Interface the Collision sensor with Arduino
What is a collision sensor?
The collision sensor is used for the detection of the collision of an object with the surrounding objects. It consists of a mechanical switch which when pressed outputs a signal, by measuring the signal voltage using a microcontroller a user can easily detect whether the object collides with the surrounding object or not. It is basically a digital sensor that is when pressed will give 5v and when not pressed will give 0v or vice versa depending on whether your switch is connected with a pull-up resistor or pull-down resistor.
Pin configuration of the collision sensor
Features of the collision sensor
- The operating voltage of the sensor is between 3-12V DC.
- It can handle a high current (2A).
- It is a vibration-type sensor.
Components needed
- Arduino UNO
- One collision sensor
- Breadboard
- Jumper wires
Pin connections of the collision sensor with Arduino UNO
- Connect the VCC pin of the sensor to the 5v pin of the Arduino UNO.
- Connect the GND pin of the sensor to the GND pin of the sensor.
- Connect the OUT pin of the sensor to the D2 pin of the Arduino.
Circuit diagram of the collision sensor with Arduino UNO
Arduino code for the collision sensor
const int collision=2;//Define pin for the OUT pin of the sensor
void setup() {
Serial.begin(9600);//Set baud rate for serial communication
pinMode(collision,INPUT);//Set the sensor pin as INPUT
}
void loop()
{
int collisionData=digitalRead(collision);//Read data from the sensor using digitalread function
if(collisionData==0)//If switch is not pressed
{
Serial.println("No Collision");//print no collision
}
else if(collisionData==1)//If switch is pressed
{
Serial.println("Collision");//print collision
}
else
Serial.println("No Data");
}