Get Help
Accelerometer
Sparki has a 3-Axis accelerometer. It is used to detect the acceleration Sparki is experiencing. Usually, this mostly means the force of gravity. It can do this in all 3 XYZ axis, or directions, which are left/right (X), forward/backwards (Y), and up/down (Z). This is the same part that smartphones use to tell how you’re tilting them.What is Acceleration?
Acceleration is how fast something speeds up. If we took a super turbo-charged Sparki and had it going 10 meters per second (36kph, 22 mph), the velocity is 10 meters per second, written as 10 m/s. If the car is reaching 10 meters per second in 10 seconds, you can say the acceleration is 1 meters per second per second, or 1 meters per second squared, written as 1 m/s2. Gravity is also a force that causes acceleration. Objects that are falling will fall faster and faster with acceleration. The only thing that keeps most things from falling is that they are being pushed up by the ground. Gravity is the acceleration that Sparki measures when it is sitting flat on a surface.How It Works
The accelerometer is what’s called a microelectromechanical, or MEMs device. MEMs are made of very tiny mechanical parts and wires too small to see, made in the same way microchips are made. Inside of the part, too tiny to see, are tiny springs. When the part is accelerated, these springs compress or relax. By measuring the amount these springs compress or relax, the part is able to measure the acceleration it is experiencing. The part has 3 different axis, or directions, of these spring-masses. They are left/right (X), forward/backwards (Y), and up/down (Z): The direction of the arrows shows the positive direction of the reading. If the acceleration is in the opposite direction, the reading will be negative. For example, if Sparki is sitting flat on a level table, the Z axis reading should be -9.8 m/s2. If Sparki is then flipped upside-down, the reading would be positive 9.8 m/s2.Using the Part
With the basic Sparki code in place, you can measure the acceleration in each axis using these commands:
1 2 3 |
sparki.accelX(); sparki.accelY(); sparki.accelZ(); |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/******************************************* Basic Accelerometer Sensor test Sparki has a 3-Axis accelerometer. It is used to detect the acceleration Sparki is experiencing. Usually, this mostly means the force of gravity. It can do this in all 3 XYZ axis, which are left/right (X), forward/backwards (Y), and up/down (Z). This is the same part that smartphones use to tell how you’re tilting them. This program shows how to read the sensor and display the information on the LCD. ********************************************/ #include <Sparki.h> // include the sparki library void setup() { } void loop() { sparki.clearLCD(); // wipe the screen float x = sparki.accelX(); // measure the accelerometer x-axis float y = sparki.accelY(); // measure the accelerometer y-axis float z = sparki.accelZ(); // measure the accelerometer z-axis // write the measurements to the screen sparki.print("Accel X: "); sparki.println(x); sparki.print("Accel Y: "); sparki.println(y); sparki.print("Accel Z: "); sparki.println(z); sparki.updateLCD(); // display all of the information written to the screen delay(100); } |