Accelerometer sensor arduino schematics

Last Updated on March 16, 2024

The accelerometer is a MEMS sensor, it measures acceleration in two different units including meters per second square, or the acceleration felt like weight, G-forces. Accelerometer widely used for orientation detection.




 
Arduino Hookup

Accelerometer-sensor-arduino

Circuit diagram

Accelerometer-sensor-circuit

Arduino Accelerometer sensor sketch code

[code]

/*www.theorycircuit.com*/
int myState=0;
int greenLedPin=11;
int redLedPin=7;
int blueLedPin=3;
int buttonPin=2;
int potPin=3;
int accZPin=0;
int accYPin=1;
int accXPin=2;

int startAccZ;
int startAccY;
int startAccX;

void setup(){
pinMode(greenLedPin,OUTPUT);
pinMode(redLedPin,OUTPUT);
pinMode(blueLedPin,OUTPUT);
pinMode(buttonPin,INPUT);
startAccZ=analogRead(accZPin);
startAccY=analogRead(accYPin);
startAccX=analogRead(accXPin);
}

void alertBlinking(){
digitalWrite(redLedPin,HIGH);
delay(50);
digitalWrite(redLedPin,LOW);
delay(100);
digitalWrite(blueLedPin,HIGH);
delay(50);
digitalWrite(blueLedPin,LOW);
delay(100);
}

boolean senseAcceleration(int myPotVal){
boolean myReturn=false;
myPotVal=map(myPotVal,0,1023,0,10);
if (analogRead(accXPin)>startAccX+myPotVal) myReturn=true;
if (analogRead(accYPin)>startAccY+myPotVal) myReturn=true;
if (analogRead(accZPin)>startAccZ+myPotVal) myReturn=true;
return myReturn;
}

void loop(){
//alertBlinking();
switch (myState){
case 0: //idle
if (senseAcceleration(analogRead(potPin))==true) {
digitalWrite(greenLedPin,LOW);
myState=1;
} else {
digitalWrite(greenLedPin,HIGH);
};
break;
case 1: // alert
alertBlinking();
if (digitalRead(buttonPin)==HIGH){
myState=0;
}
break;
}
delay(10);
}

[/code]
 



Components List

S.No Name Quantity
1. Arduino uno 1
2. Accelerometer sensor 1
3. LED Green 1
Red 1
Blue 1
4. Resistor 220 Ω
1.2 KΩ
Variable Resistor
3
1
1
5. Push button switch 1
6. Connecting wires as required

2 thoughts on “Accelerometer sensor arduino schematics

Leave a Reply

Your email address will not be published. Required fields are marked *