Arduino Crash Sensor

crash sensor

This sensor is simply a micro switch. When the small lever is pushed in an on board LED lights and the output goes LOW. The following sketch lights the LED on the Arduino when the lever is pressed.

// Crash sensor
int ledPin = 13;
int inPin = 8;
int earthPin = 6;
int vccPin = 7;
int valueCrash = 1;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(inPin, INPUT_PULLUP);
pinMode(earthPin, OUTPUT);
pinMode(vccPin, OUTPUT);
digitalWrite(earthPin, LOW); // provide 0 volts for Gnd
digitalWrite(vccPin, HIGH); // provide +5 volts for Vcc

}

void loop() {
valueCrash = digitalRead(inPin); // read the state of the crash sensor
digitalWrite(ledPin, !valueCrash); // light LED if switch closed
}

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s