Created
January 6, 2020 05:44
-
-
Save futureshocked/5b47a9279068e42828626b130d158354 to your computer and use it in GitHub Desktop.
With this sketch your Arduino can detect acceleration using an analog accelerometer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x, y, z; | |
void setup() | |
{ | |
Serial.begin(9600); // sets the serial port to 9600 | |
} | |
void loop() | |
{ | |
x = analogRead(0); // read analog input pin 0 | |
y = analogRead(1); // read analog input pin 1 | |
z = analogRead(2); // read analog input pin 1 | |
Serial.print("accelerations are x, y, z: "); | |
Serial.print(x, DEC); // print acceleration in the X axis | |
Serial.print(" "); // prints a space between the numbers | |
Serial.print(y, DEC); // print acceleration in the Y axis | |
Serial.print(" "); // prints a space between the numbers | |
Serial.println(z, DEC); // print acceleration in the Z axis | |
delay(100); // wait 100ms for next reading | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment