INTERFACING SHOCK SENSOR (KY-002) WITH BHARAT -PI

by madhankarthick in Circuits > Sensors

466 Views, 0 Favorites, 0 Comments

INTERFACING SHOCK SENSOR (KY-002) WITH BHARAT -PI

wer (1).jpg
Screenshot 2023-09-15 155318.png
WhatsApp Image 2023-09-06 at 14.26.59.jpg

The KY-002 Vibration Switch Module detects shaking and knocking. When the module is moved, a spring mechanism will close the circuit sending a short high signal.It can be used with a variety of microcontrollers like Arduino, ESP32, Raspberry Pi and others.

How Shock Sensor Work?

cs.png
dv.png

The shock sensor consists of SW-18015p which looks like a cylindrical shape on the module.

The shock sensor consists of a metallic wire and a metallic terminal. The metallic terminal is connected to 5v, this metallic terminal is surrounded by a spring formed by a metal wire. When there is a vibration or when we shake the sensor the metal terminal hits the metal wire and current from the metallic terminal now flows to the metal wire. So the output of the sensor will be 5v to the Bharat pi board.\



REQUIREMENTS

Artboard-1-e1686767346235.jpg
wires.jpg
res.jpeg
OIP.jpeg
  1. KY-002 (shock sensor module)
  2. Bharat-pi
  3. Jumper wires
  4. Resistor(220 ohm)


Interfacing Shock Sensor WITH BHARAT -PI

xa.png
sc.png

Connect the ground pin of the shock sensor to the ground pin of the bharat-pi, the VCC pin to 5v, and the analog signal pin (4)to . Also, connect the positive lead of LED to pin 23.

CODE

OIP (1).jpeg

int ledpin=23;         // Set led pin at Arduino pin 11

int shocksensor=4;       // Set sensor pin at Arduino pin 8

int sensorvalue;        // initialize variable to store sensor data

void setup()

{

 pinMode(ledpin,OUTPUT);   // LED pin set to output

 pinMode(shocksensor,INPUT); //shock sensor pin set to input

 Serial.begin(115200);    // set baud rate for Serial communication

}

void loop()

{

 sensorvalue = digitalRead(shocksensor); // read values from sensor pin and store in variable

 if (sensorvalue==HIGH)   // if shake detected

 // if (sensorvalue==LOW) // for pull-up configuration

 {

 digitalWrite(ledpin,HIGH); // turn LED on

 Serial.println("vibration detected system awake"); // Print message

 }

 else{

 digitalWrite(ledpin,LOW); // turn LED off

 Serial.println("Sleep mode"); // Print message

 }

 delay(30);         // delay

}

 

 code avilabe at git-hub : https://github.com/Madhankarthick/SHOCK-SENSOR-CODE-BHARAT-PI.git

Downloads

Working

First, initialize pins of shock sensor & LED. We have declared a variable name sensor value to read values from the shock sensor. In the void setup, we configure pins as INPUT or OUTPUT. We want to read values from the sensor pin so we will declare it as INPUT and LED as OUTPUT. We also configure the baud rate to 115200.

In a void loop, we continuously read values from the shock sensor and store values in the variable name sensor value and we check here condition if it is HIGH or not. HIGH means vibration or shake has been detected, the sensor sends a HIGH signal to our Arduino which we printed as "vibration detected system awake" Here we have written code to turn ON led when vibration is detected. Whereas when the sensor is in pull-up configuration then the sensor will send a Low signal in the presence of vibration or shake.

When the sensor doesn’t sense a shake or vibration then the sensor sends a LOW signal to Arduino which is printed as “Sleep mode “ and the LED connected to pin 23 will turn OFF. Whereas when the sensor is in pull-up configuration, the sensor will send a HIGH signal. We have introduced a delay of 20 milliseconds.

APPLICATIONS

OIP (1).jpeg
OIP.jpeg
ZIP-WAVE-5.jpg

Tap detection - Shock accelerometers are frequently employed in tap interfaces, which are integral components of advanced user interfaces. Shock sensors are used to detect the direction of a finger tap and distinguish between a single and double tap.

Micro-drive protection - Shock sensors are becoming increasingly prevalent in laptops and other portable devices employing disk drives. Many laptops are fitted with a three-axis shock sensor which detects sudden movements, including free falls and sudden impacts. When the sensor detects vibration or shock which exceeds a predetermined level, it causes the hard disk drive's read/write head to retract from the disk itself, preventing the head from scratching the disk upon impact. Some sensors also cause the drive to shut down completely upon impact.

Shipping and handling - Shock sensors can be attached to shipping cases in order to detect and record rough handling. By coupling the sensor with a visual label alerting the handler to the presence of the sensor, companies are able to reduce damage to their shipments and pinpoint exactly when damage does occur.

Automotive security systems - Shock sensors are employed in security systems to detect shock related to tampering. If the sensor detects severe vibrations due to tampering, it triggers the vehicle's alarm to deter theft. The video below shows the effects of tampering with a vehicle fitted with a shock sensor.

VIDEO

INTERFACING SHOCK SENSOR