- LED Blink with Button
- Motion Detection Alarm System
- Simple RGB LED Controller
- Blinking LED with WebSocket Control
- Control LED Brightness using PWM
- Web Page with HTML and CSS on ESP32
- Control Multiple LEDs
- ESP32 with Bluetooth Serial Communication
- EEPROM with ESP32
- ESP32 Push Button Input: Reading Digital States
- Interfacing DHT11 Sensor
- Interfacing Ultrasonic Sensor
- Interfacing Flame Sensor
- Interfacing Sound Sensor
- Interfacing Potentiometer
- Interfacing IR Sensor
- Interfacing Servo Motor
- Interfacing Cam Wireless
- Interfacing DC Motor
- Interfacing Shock Sensor
- Interfacing Color Recognition Sensor
- Interfacing RFID Module
- TTGO LoRa32 SX1276 OLED
- Interfacing Keypad
- Interfacing Solenoid Lock
- Interfacing 16x2 LCD
- Interfacing Soil Moisture
- Interfacing MQ-7 Gas Sensor
- Interfacing Light Sleep Mode
- Interfacing Smart Light Control
- Interfacing (IoT) Weather Station
- Interfacing Web Server for Temperature Data Display
- Interfacing Home Automation System with Relay Control
- Interfacing IoT Smart Garden
- Face Recognition-Based Door Unlock System
- Interfacing Wi-Fi Jammer Detector
- Interfacing Health Band with Pulse
- Interfacing Sound Level Logger for Classrooms
- Night Vision Surveillance Camera
- Solar Panel Monitoring System
- Smart Farming Robot for Crop Surveillance
- Smart Water Quality Monitoring System
- Industrial IoT Gateway for Real-Time Monitoring
- Agriculture System with Automated Drone Control
Interfacing Shock Sensor with ESP32
What is a Shock Sensor?
A Shock Sensor is a vibration-detecting sensor that generates a digital signal when it detects sudden movement, shock, or vibration. It is often used in alarm systems, impact detection, and safety devices.
Working Principle of Shock Sensor
The sensor contains a spring or conductive element that closes or opens a circuit when a vibration or mechanical shock is detected, generating a high or low pulse on the output pin.
- The ESP32 sends a HIGH signal to power the sensor.
- When the sensor detects a shock or vibration, it triggers a digital HIGH/LOW pulse.
- ESP32 reads the digital signal and performs actions like triggering alarms or logging data.
Formula: Shock Detected = Digital Read (HIGH or LOW)
Components Required
- ESP32 board
- Shock Sensor Module (SW-420 or equivalent)
- Jumper wires
- Breadboard (optional)
Pin Configuration of Shock Sensor Module
- VCC: Connects to 3.3V of ESP32
- GND: Connects to ESP32 GND
- DO (Digital Out): Sends digital signal to ESP32 when vibration is detected
Make sure to use a sensor module that supports 3.3V logic or use a level shifter if necessary.
Wiring Shock Sensor to ESP32
- VCC -> 3.3V (or 5V if supported)
- GND -> GND
- DO -> GPIO 15
Arduino Code for ESP32 + Shock Sensor
1const int shockPin = 15;
2
3void setup() {
4 pinMode(shockPin, INPUT);
5 Serial.begin(115200);
6}
7
8void loop() {
9 int shockState = digitalRead(shockPin);
10 if (shockState == HIGH) {
11 Serial.println("Shock Detected!");
12 } else {
13 Serial.println("No Shock");
14 }
15 delay(500);
16}
Code Explanation (Line-by-Line)
- const int shockPin = 15;: Defines GPIO 15 as the input pin connected to the shock sensor.
- pinMode(shockPin, INPUT);: Sets the shock sensor pin as an input.
- digitalRead(shockPin);: Reads the sensor’s digital signal (HIGH or LOW).
- Serial.println("Shock Detected!");: Prints a message when a shock is detected.
Applications
- Anti-theft alarm systems
- Crash or impact detection in vehicles
- Smart door knock detection
- Robotics obstacle or collision alert
- Earthquake early-warning systems (basic)
Conclusion
The Shock Sensor is a simple yet effective module for detecting vibrations and mechanical shocks using ESP32. It finds use in security and automation applications where detecting motion or impact is crucial.