Step 5: Accelerometer

This sensor is used to find the orientation of the phone. Widely used in gaming and other interactive applications.

It measures the acceleration along 3 axis x, y and z. Units considered are SI units that is ms^-2. Range of the values is -9.8 to +9.8.

xAccel: 0 when the phone is at rest on a flat surface, positive when the phone is tilted to the right (i.e., its left side is raised), and negative when the phone is tilted to the left (i.e., its right size is raised).

yAccel: 0 when the phone is at rest on a flat surface, positive when its bottom is raised, and negative when its top is raised.

zAccel: Equal to -9.8 (earth’s gravity in meters per second per second when the device is at rest parallel to the ground with the display facing up, 0 when perpendicular to the ground, and +9.8 when facing down. The value can also be affected by accelerating it with or against gravity.

The events which we are interested is acceleration.Changed which triggers when ever the sensor measures different values from previous measures.

To pass the values to Arduino we wont use this but will use a timer event which is a element which triggers after every specified time is passed.

The sampling rate of accelerometer is pretty high so if we send the data when different values are measured than previous what will happen is the application will try to send new data irrespective of previous data is received or not by Arduino, hence we the timer to send the data.

So we will include a timer which ticks every specified time in msec and when it ticks we will send the data through the serial.

Application

• Include connect, disconnect buttons and checkbox to initialize serial communication.
• Also include a slider switch to enable and disable accelerometer as well as timer.
• Then place 6 labels with 2 adjacent to each other using horizontal arrangement available in layout tabs.
• Also include a slider using which we will set timers ticking period.
• Do keep the min and max value of slider 1 and 1000 respectively so that we don’t need to map them as time for timer will be from 1 to 1000msec.
• In block coding add events for connect and disconnect.
• For slide switch it is same as light sensor, a functions returns true when slide switch is in on position and enables accelerometer and timer.
• Accelerometer automatically updates itself so need of special event.
• The slider change event sets timer interval to the position of the thumb.
• And when timer ticks it send acceleration along x, y, z through serial to Arduino and updates the labels according if serial is open.