working code without the accelerometer