Alarme de detecção de queda/colisão baseado em Arduino usando sensor de detonação KY-031

Arduino based drop/collision detection alarm using KY-031 knock sensor

Detecting the physical conditions of a robot is always useful in robotic applications. Especially if the robot is a rover and is designed to explore different terrains. In these applications, there are cases where the state of the robot needs to be detected. It may involve detecting a collision or fall, changing the orientation of the robot's body, detecting the navigation direction, or detecting the state of the robot relative to the surrounding terrain, etc. important state changes. If a robot is designed to explore outdoors, it is important to know whether a robot has collided sideways or fallen on its side. This can be used to take intuitive actions in response to such events.

Fall or collision detection by the robot's body can be especially crucial in the design of battle robots. Battle bots are designed to beat other bots in a robotic battle. By detecting impact or collision in specific parts of the robotic body, a battle robot can be designed to perform autonomous actions of rescue, stabilization or act against the load.

In this project, we designed a collision/fall detection circuit using Arduino and Knock sensor. The knock sensor can be useful in detecting impacts such as a collision or fall. A knock sensor is sensitive to vibrations and can provide early warning before complete destabilization or damage if properly installed in a rover's mechanical assembly. Let's test a knock detection circuit with a popular KY-031 knock sensor.

Required components

  1. Arduino UNO x1
  2. Knock sensor KY-031 x1
  3. LEDx1
  4. Resistance 330Ω x1
  5. Connecting wires/jumper wires
  6. Test board
  7. Power supply for Arduino

Circuit Connections

In this project, Arduino interfaces with a knock sensor to detect any impact such as collision or fall. The knock sensor used in the circuit is KY-031. The sensor has three terminals – Signal, VCC and GND. The signal terminal is indicated by the 'S' label, the middle one is VCC and GND is indicated by the '-' label on the sensor.

KY-031 Knock Sensor Pin Diagram

For interfacing, the KY-031 knock sensor with Arduino connects pin S to any GPIO on the Arduino, pin 7 in this case, and connects the VCC and GND pins to the 5V output and one of the GND pins on the Arduino, respectively. For an indication of the impact, an LED is connected to pin 6 of the Arduino UNO. The LED has an interface that supplies current from the Arduino pin. A current limiting resistor is connected in series to the LED for its protection.

Circuit Diagram

Arduino based fall/collision/shock detector circuit diagram

Arduino Sketch

How it works

A knock sensor is a vibration sensor that detects vibrations or shocks when knocked or knocked. One of the popular knock sensors is KY-031. This simple and inexpensive knock sensor can be easily connected to any microcontroller or single-board computer. It has a digital output that, when the sensor is turned on, remains at a HIGH level by default. Whenever there is a shock or impact, the digital output of the sensor is currently LOW.

The KY-031 knock sensor actually has a conductive vibrating spring. This spring acts as a switch inside the sensor and remains open circuit by default. When there is a shock or impact, the spring vibrates for a moment and touches a contact, forming a closed connection. By default, the sensor output is pulled HIGH via a 10K resistor. When the vibrating spring touches the contact, the output is driven DOWN. A simplified representation of the knock sensor is shown below.

KY-031 Knock Sensor Internal Block Diagram

The knock sensor is not a very sensitive device. It can only detect strong vibrations or shocks. Therefore, it can be useful in detecting collisions or falls. It can also be used as a door knock sensor.

In the circuit, the output of the knock sensor is connected to pin 7 of the Arduino. Since the sensor is pulled high by default and only outputs a LOW level in case of shock or vibration, the Arduino is programmed to group a logical LOW level on the respective pin. Whenever there is a LOW signal on pin 7 of the Arduino, it turns pin 6 to HIGH, turning on an LED. This provides a visual indication of the impact detected on the sensor.

In a robotic application, the knock sensor can be strapped to the robot's body so that any shock or vibration to the body is transferred to it. In a robotic application, instead of turning on an LED, a counter action, such as activating some actuators to stabilize the robot's body or counterattack (as in the case of battle robots), can be initiated.

The code

The sketch is very simple. It starts by declaring the pins connected to the knock sensor and the LED. Variables – 'knockDetect', 'impactAlarm' and 'lastKnockTime' are declared to detect knock/knock signal logic, signal impact status and record elapsed time since last impact in milliseconds respectively.

In the setup function, the baud rate for serial messages is set to 9600 using the Serial begin method, the LED pin is set as output while the Knock pin is set as input.

In the loop (functions 0, the Arduino groups a logic LOW signal on the knock pin. If there is a logic low level, a message indicating knock detection is passed to the serial port, the LED is lit by passing a logic HIGH on pin 6, and the impactAlarm flag is set to True If no LOW signal is detected in a loop iteration since 500 milliseconds since the last impact, a message indicating no impact is passed to the serial port, the LED is turned off by passing a logic LOW on the pin 6, and the impactAlarm flag is set to False.

Result

The following demonstration shows how the circuit works when the knock sensor falls onto a surface.

Related Content

Back to blog

Leave a comment

Please note, comments need to be approved before they are published.