Example Code for Arduino-Crash Sensor Switch Detection
Last revision 2025/12/20
This article offers detailed instructions and example code for detecting a crash sensor switch with Arduino, including a wiring diagram to assist DIY enthusiasts in implementing the sensor effectively.
Wiring Diagram

Sample Code
// #
// # Editor : Lauren from DFRobot
// # Date : 26.09.2012
// # E-Mail : [email protected]
// # Product name: Crash sensor
// # Product SKU : SEN0138
// # Version : 0.1
int ledPin = 13; // choose the pin for the LED
int inputPin = 3; // Connect sensor to input pin 3
void setup() {
Serial.begin(9600); // Init the serial port
pinMode(ledPin, OUTPUT); // declare LED as output
pinMode(inputPin, INPUT); // declare Micro switch as input
}
void loop(){
int val = digitalRead(inputPin); // read input value
if (val == HIGH) { // check if the input is HIGH
digitalWrite(ledPin, LOW); // turn LED OFF
} else {
digitalWrite(ledPin, HIGH); // turn LED ON
Serial.println("Switch Pressed!");
}
delay(50);
}
Was this article helpful?
