Accellerometer
Processes an analog Accellerometer (ADXL 335 series) sensor and prints the information to the computer monitor
Accellometer Code
---------- Copy Code Below
/*
ADXL335
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
analog 4: ground
analog 5: vcc
*/
// these constants describe the pins. They won't change:
//const int groundpin = 18; // analog input pin 4 -- ground
//const int powerpin = 19; // analog input pin 5 -- voltage
const int xpin = A3; // x-axis of the accelerometer
const int ypin = A2; // y-axis
const int zpin = A1; // z-axis (only on 3-axis models)
int yValue;
int xValue;
int zValue;
void setup() {
Serial.begin(9600);
}
//Explain that acceleration exists even without motion due to gravity (1g acceleration)
//In this program if you tap the sensor in the X,Y or Z direction it will sense it
----------------------------------- Copy Code Below
void loop() {
yValue = analogRead(ypin);
xValue = analogRead(xpin);
zValue = analogRead(zpin);
Serial.print(analogRead(xpin));
Serial.print("\t");
Serial.print(analogRead(ypin));
Serial.print("\t");
Serial.print(analogRead(zpin));
Serial.println();
// delay before next reading:
delay(1000);
}
----------------------------------- Copy Code Above
Things to do:
1) Build a tilt meter to display X tilt using LEDs
2) Build a tilt meter to display X and Y tilt using LEDs.
3) Use the output of the accelerometer to control a servo motors rotation
4) Use the output of the accelerometer to control a small remote-controlled vehicle
No comments:
Post a Comment