Let op: De plus aan 3,3V niet de 5V
Hierboven het aansluitschema voor de ADXL 335 accelerometer. Er zijn een paar goede websites waar je meer informatie en programmavoorbeelden kan vinden:
https://www.arduino.cc/en/Tutorial/ADXL3xx
https://learn.adafruit.com/adafruit-analog-accelerometer-breakouts
http://bildr.org/2011/04/sensing-orientation-with-the-adxl335-arduino/
Hieronder een op basis van het Arduino voorbeeld programma aangepaste sketch met een led.
/* ADXL3xx Aangepaste versie met led.
Van examples > sensors > ADXL3xx.
Reads an Analog Devices ADXL3xx accelerometer and communicates the
acceleration to the computer.
http://www.arduino.cc/en/Tutorial/ADXL3xx
The circuit:
analog 0: accelerometer self test
analog 1: z-axis
analog 2: y-axis
analog 3: x-axis
created 2 Jul 2008 by David A. Mellis modified 4 Sep 2010 by Tom Igoe
This example code is in the public domain.
*/
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 ledPin = 7; //led op pin 7
int x = 0;
void setup() {
Serial.begin(9600); // initialize the serial communications:
pinMode (ledPin, OUTPUT);
}
void loop() {
Serial.print("\tx="); // print a tab between values:
Serial.print(analogRead(xpin)); // print the sensor values:
Serial.print("\ty=");
Serial.print(analogRead(ypin));
Serial.print("\tz=");
Serial.print(analogRead(zpin));
Serial.println();
x = analogRead (xpin);
if (x < 325){ // dit getal kan je veranderen
digitalWrite(ledPin, HIGH);
}
else {
digitalWrite(ledPin, LOW);
}
delay(100); // delay before next reading:
}