Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

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

By Nikhil Agnihotri April 8, 2021

Detecting the physical conditions of a robot is always useful in robotic applications. Particularly if the robot is a rover and is designed to explore different terrains. In such applications, there are instances when the state of the robot has to be detected. It may involve detection of collision or fall, change in orientation of the robot’s body, detection of direction of the navigation, or detection of the state of the robot with respect to the surrounding terrain, etc. Detection of fall or collision is one of such important state changes. If a robot is designed to explore outdoors, it gets important to know if a robot has collided from a side or fallen on a side. This can be used to take intuitive actions in response to such events.

Detection of fall or collision on the part of the robot body can be especially crucial in the design of battle bots. Battle bots are designed to win against other bots in a robotic battle. By detecting impact or collision on specific parts of the robotic body, a battle bot can be designed to take autonomous actions for rescue, stabilization, or actuate against the charge.

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

Components required

  1. Arduino UNO x1
  2. KY-031 Knock Sensor x1
  3. LED x1
  4. Resistor 330Ω x1
  5. Connecting wires/jumper wires
  6. Breadboard
  7. Power supply for Arduino

Circuit connections

In this project, Arduino is interfaced with a knock sensor to detect any impact like 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 the GND is indicated by ‘-‘ label on the sensor.

Pin diagram of KY-031 Knock sensor

For interfacing, the KY-031 knock sensor with Arduino connects the S pin to any of the Arduino’s GPIO, pin 7 in this case, and connects the VCC and GND pins to 5V out and one of the GND pins of Arduino, respectively. For an indication of the impact, a LED is interfaced at pin 6 of the Arduino UNO. The LED is interfaced such that it sources current from the Arduino pin. A current limiting resistor is connected in series to the LED for its protection.

Circuit diagram

Circuit diagram of Arduino based Fall/Collision/Shock detector

Arduino Sketch

How it works

A knock sensor is a vibration sensor that detects vibrations or shocks when tapped or knocked. One of the popular knock sensors is KY-031. This simple and cheap knock sensor can be easily interfaced with any microcontroller or single-board computer. It has a digital output that, on powering up the sensor, remains HIGH by default. Whenever there is a shock or impact, the sensor’s digital output goes LOW for the moment.

The KY-031 knock sensor actually has a conductive vibrating spring. This spring acts as a switch within the sensor and remains open-circuit by default. When there is a shock or impact, the spring is vibrated for a moment and touches a contact-making 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 to LOW. A simplified representation of the knock sensor is shown below.

Internal block diagram of KY-031 Knock sensor

The knock sensor is not much sensitive device. It can only detect hard 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 Arduino’s pin 7. As the sensor is pulled high by default and only outputs a LOW on shock or vibration, Arduino is programmed to pool for a logical LOW at the respective pin. Whenever there is LOW signal at the Arduino’s pin 7, it sets the pin 6 HIGH, lighting up a LED. This gives a visual indication of the detected impact to the sensor.

In a robotic application, the knock sensor can be tied to the robot’s body, so any shock or vibration to the body is transferred to it. In a robotic application, instead of glowing a LED, a counter action like activating some actuators to stabilize the robot’s body or counter attack (like in the case of battle robots) can be initiated.

The code

The sketch is pretty simple. It begins by declaring pins connected to the knock sensor and the LED. Variables – ‘knockDetect’, ‘impactAlarm’, and ‘lastKnockTime’ are declared to detect knock/tapping signal logic, flag status of impact, and record time elapsed from the last impact in milliseconds, respectively.

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

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

Result

The following demonstration shows the working of the circuit when the knock sensor is dropped over a surface.


Filed Under: Electronic Projects, Sensors, Tutorials, Video

 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Powering a USB hub: safely distributing current from a shared power supply
  • RF-DC rectifier impedance matching
  • How can I get the frequency please help!
  • Elektronik devre
  • 12VAC to 12VDC 5A on 250ft 12AWG

RSS Electro-Tech-Online.com Discussions

  • 100uF bypass Caps?
  • Fuel Auto Shutoff
  • Actin group needed for effective PCB software tutorials
  • how to work on pcbs that are thick
  • compatible eth ports for laptop

Featured – Designing of Audio Amplifiers part 9 series

  • Basics of Audio Amplifier – 1/9
  • Designing 250 Milli Watt Audio Power Amplifier – 2/9
  • Designing 1 Watt Audio Power Amplifier – 3/9
  • Designing a Bass Boost Amplifier – 4/9
  • Designing a 6 Watt Car Audio Amplifier – 5/9
  • Design a low power amplifier for headphones- 6/9

Recent Articles

  • ITG Electronics releases gate drive transformers with 200 – 450 V DC capability
  • Stackpole introduces HCJ jumpers with 70.7 amp continuous current capability
  • Infineon releases MCU with 128K flash and multi-sense capabilities
  • ST introduces 600V GaN gate drivers with 300 ns start-up time
  • ABLIC releases S-19116 automotive voltage detector with 6.8μs response time

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronics Projects and Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe