MyRoboPathOpen Robotics Lab
Arduino Uno #32 of 35
Est. 0.5 Hours
Budget: $2 - $3
Beginner

KY-002 Spring Vibration & Impact Shock Sensor

Capture mechanical impacts, table knocks, and tamper vibrations using hardware interrupts on a spring-contact switch.

Detect knocks, earthquakes, machine vibrations, and package impacts with the KY-002 vibration switch module! Because spring-contact closures last less than 1 millisecond, simple polling loops miss hits—so you will wire KY-002 to Arduino Uno hardware interrupt pin D2 (INT0) for 100% impact capture.

Arduino Uno R3KY-002 Vibration SwitchHardware Interrupt INT0Impact DetectionTamper Alert
KY-002 Spring Vibration & Impact Shock Sensor Blueprint
KY-002 Spring Vibration & Impact Shock SensorCAD Blueprint

Key Learning Objectives & Robotics Concepts

By building and programming this project, you will master the following core engineering skills:

1Understand why ultra-brief (<1ms) mechanical spring closures require hardware interrupts instead of delay() polling.
2Write a clean, minimal Arduino ISR updating volatile counters safely.
3Distinguish a single light table bump from sustained tampering by counting shock pulses inside a 1-second window.
4Build vibration-triggered theft alarms and machine health monitors.

Power Architecture & Voltage Staging

5V / 3.3V Regulated Power

The KY-002 contains a microscopic conductive spring around a center pin plus an onboard 10kΩ pull-up resistor, consuming <0.5mA on Arduino Uno 5V. Interrupt-driven edge capture guarantees sub-millisecond shock pulses are never lost while Serial logs are printing.

KY-002 Spring Vibration & Impact Shock Sensor Power Architecture Schematic
Figure: Regulated Arduino Uno supply rails, current budget, and component protection.Power Schematic

Bill of Materials (BOM) & Hardware Components

Bill of Materials for KY-002 Spring Vibration & Impact Shock Sensor
ComponentSpecifications & AlternativeQtyApprox Cost
Arduino Uno R3ATmega328P with INT0 on D21$8.00
KY-002 Vibration Switch ModuleSW-18015P conductive spring cylinder + 10kΩ pull-up1$1.00
5mm LED + 220Ω Resistor + BuzzerVisual & audible shock alert stage1$0.95
Breadboard & Jumper Wires6× breadboard jumpers1$2.00

Electrical & System Architecture

Connect KY-002 Middle (+) to 5V, (-) to GND, and Signal (S) to Arduino interrupt pin D2 (INT0). Wire Shock Alert LED (+220Ω) to D8 and optional Buzzer to D9.

Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-002 Spring Vibration & Impact Shock Sensor.
Figure: Complete Arduino Uno R3 pin-to-pin wiring schematic for KY-002 Spring Vibration & Impact Shock Sensor.Wiring Schematic

Autonomous Behavior & Finite State Machine (FSM)

Deterministic Arduino loop handling KY-002 SW-18015P Spring Vibration Module acquisition, filtering, and real-time output updates.

Figure: Firmware execution flow and state transitions for KY-002 Spring Vibration & Impact Shock Sensor.
Figure: Firmware execution flow and state transitions for KY-002 Spring Vibration & Impact Shock Sensor.Control Algorithm

Step-by-Step Physical Assembly & Wiring Tutorial

Follow each of the 5 sequential milestone stages with technical photos, wiring checks, and pre-flight tests.

1

Inspect KY-002 Spring Capsule & Pinout

Duration: 5 Mins

Verify the 3-pin layout on KY-002: S (Signal), center (+5V), and - (GND).

KY-002 Spring Vibration & Impact Shock Sensor hardware layout diagram
Stage 1: KY-002 SW-18015P Spring Vibration Module hardware inspection & pinout overview.Stage 1 Diagram
Step Action Checklist:
  • Seat the KY-002 rigidly onto the breadboard so tabletop knocks transmit cleanly into the metallic cylinder.
  • Verify silkscreen labels: S, middle (+), and (-).
  • Note that the spring switch is normally OPEN (HIGH via pull-up) and shorts to LOW briefly during vibration.
Engineering & Tuning Tip: Tape or clamp the breadboard lightly to the desk to test knock detection through the table!
2

Wire Signal to Hardware Interrupt Pin D2

Duration: 5 Mins

Connect KY-002 to D2 (INT0), plus Alert LED to D8 and optional Buzzer to D9.

KY-002 Spring Vibration & Impact Shock Sensor breadboard wiring check diagram
Stage 2: Breadboard layout & Arduino Uno pin-to-pin wiring audit.Stage 2 Diagram
Step Action Checklist:
  • Connect KY-002 center (+) → 5V, (-) → GND, and S → D2.
  • Wire Red LED (+220Ω) to D8 and Piezo Buzzer to D9.
  • Plug in USB power.
Engineering & Tuning Tip: On Arduino Uno, only D2 (INT0) and D3 (INT1) support external attachInterrupt()—always use D2 for fast shock switches!
3

Verify Microsecond Contact Capture

Duration: 5 Mins

Flick the breadboard edge lightly with a fingernail and confirm every shock fires INT0.

KY-002 Spring Vibration & Impact Shock Sensor power rail protection diagram
Stage 3: Supply rail check (USB 5.0V Regulated Rail (<1mA)) and circuit protection verification.Stage 3 Diagram
Step Action Checklist:
  • Upload the diagnostic snippet and open Serial Monitor.
  • Tap the desk firmly beside the breadboard—confirm instant interrupt counts print.
  • Notice how reliable INT0 capture is compared to polling loops!
Engineering & Tuning Tip: Adding a 15ms ISR debounce prevents one spring bounce from looking like 10 separate knocks.
4

Upload Tamper & Impact Classifier Firmware

Duration: 10 Mins

Flash the smart shock analyzer that differentiates gentle bumps from sustained tampering.

KY-002 Spring Vibration & Impact Shock Sensor serial telemetry verification diagram
Stage 4: Firmware upload & 115200 baud Serial Monitor verification.Stage 4 Diagram
Step Action Checklist:
  • Upload the production sketch below.
  • Give a single light tap → Serial logs "Minor Bump" and flashes D8 briefly.
  • Shake the breadboard briskly → Serial logs "TAMPER ALARM!" and sounds D9 buzzer.
Engineering & Tuning Tip: Windowed pulse counting dramatically reduces false theft alarms from passing trucks or doors closing!
5

Test Orientation & Sensitivity

Duration: 5 Mins

Observe how horizontal vs. vertical orientation affects radial spring sensitivity.

KY-002 Spring Vibration & Impact Shock Sensor live operational logic diagram
Stage 5: Live operational logic flow & calibration verification.Stage 5 Diagram
Step Action Checklist:
  • Tap vertically vs horizontally along the cylinder axis.
  • Notice the spring flexes most easily perpendicular to the cylinder barrel.
  • Tune TAMPER_HITS (default 3 hits/sec) for your application.
Engineering & Tuning Tip: Mount two KY-002 modules at 90° to each other for omnidirectional 3D shock protection.

Subsystem Benchtop Verification Scripts

Test each hardware subsystem independently before deploying the full autonomous firmware.

1Bench Diagnostic: KY-002 SW-18015P Spring Vibration Module Hardware Check

Subsystem Diagnostic

Minimal standalone sketch to verify pin wiring and signal response for KY-002 SW-18015P Spring Vibration Module before running the full project firmware.

Arduino IDE Diagnostic ScriptC++ / Arduino
// Diagnostic: Interrupt-Driven KY-002 Shock Counter
volatile unsigned long hits = 0;
void isrShock() { hits++; }
void setup() { pinMode(2, INPUT_PULLUP); attachInterrupt(digitalPinToInterrupt(2), isrShock, FALLING); Serial.begin(115200); }
void loop() { static unsigned long last=0; if (hits != last) { last = hits; Serial.print("Shock Pulse #"); Serial.println(last); } }
Expected Output: Prints incrementing Shock Pulse numbers instantaneously on every desk knock.

Complete Production Firmware

Full working C++ source code with pin mappings, non-blocking timers, and FSM avoidance routines.

arduino_uno_ky002_vibration_shock_switch.ino
arduino_uno_ky002_vibration_shock_switch.inoArduino C++
/**
 * Project 32: KY-002 Interrupt-Driven Vibration & Tamper Detector
 * Board: Arduino Uno R3 | Pins: D2 (KY-002 INT0), D8 (LED), D9 (Buzzer)
 */
const uint8_t VIB_PIN    = 2;
const uint8_t ALERT_LED  = 8;
const uint8_t BUZZER_PIN = 9;
const uint8_t TAMPER_HITS = 3; // >=3 shocks within 1s = Tamper Alert

volatile uint16_t windowHits = 0;
volatile unsigned long lastIsrMs = 0;

void onVibration() {
  unsigned long now = millis();
  if (now - lastIsrMs >= 15) { // 15ms spring bounce filter
    lastIsrMs = now;
    windowHits++;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(VIB_PIN, INPUT_PULLUP);
  pinMode(ALERT_LED, OUTPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(VIB_PIN), onVibration, FALLING);
  Serial.println(F("KY-002 Vibration & Tamper Monitor Armed"));
}

void loop() {
  delay(800);
  noInterrupts();
  uint16_t count = windowHits;
  windowHits = 0;
  interrupts();

  if (count >= TAMPER_HITS) {
    Serial.print(F("[TAMPER ALARM!] Heavy Vibration (")); Serial.print(count); Serial.println(F(" hits)"));
    digitalWrite(ALERT_LED, HIGH);
    tone(BUZZER_PIN, 2000, 300);
    delay(350);
    digitalWrite(ALERT_LED, LOW);
  } else if (count > 0) {
    Serial.print(F("[BUMP] Minor shock detected (")); Serial.print(count); Serial.println(F(" hit)"));
    digitalWrite(ALERT_LED, HIGH); delay(120); digitalWrite(ALERT_LED, LOW);
  }
}

Firmware Architecture Explanation:

  • Captures sub-millisecond spring closures asynchronously via INT0 even while loop() sleeps.
  • Atomically snapshots and resets windowHits inside noInterrupts()/interrupts() critical section.
  • Separates benign single bumps from multi-hit tampering to eliminate false alarms.

Operational Verification & Pin State Matrix

1Double-check all 5 Arduino Uno pin connections against the wiring schematic before plugging in USB.
2Upload the Bench Diagnostic sketch first and confirm Serial Monitor at 115200 baud matches: Prints incrementing Shock Pulse numbers instantaneously on every desk knock.
3Upload the complete production sketch and verify every condition in the operational truth table below.

Input Signal vs. System Output Truth Table:

Operational truth table for KY-002 Spring Vibration & Impact Shock Sensor
Input / StatePin / SignalDetected ConditionExpected Output
0 Hits / 0.8sD2 Idle HIGHStationaryArmed Standby
1–2 Hits / 0.8sBrief INT0Light Knock / BumpShort D8 LED Flash
≥ 3 Hits / 0.8sRapid INT0Tamper / ShakeD8 LED + 2kHz Alarm

Engineering Troubleshooting Matrix

Engineering troubleshooting matrix for KY-002 Spring Vibration & Impact Shock Sensor
ProblemLikely CauseDiagnostic CheckEngineering Solution
No response even when shaking vigorouslyWired to non-interrupt pin or loose S wireVerify S connects strictly to D2Connect KY-002 S → D2 and confirm INPUT_PULLUP.
Triggers nonstop without touchingDefective shorted spring inside cylinderMeasure continuity across cylinder leads at restTap gently to unstick spring or replace KY-002.
Only very hard impacts registerSW-18015P mounted on soft foam absorbing energyCheck mechanical coupling to test surfaceMount PCB rigidly to surface being monitored.

Engineering Challenges & Upgrades

Take your build to the next level with these progressive engineering upgrades:

Level 1Secret Knock Door Unlocker

Record time gaps between 3 knocks and unlock Project 8 Servo only when your secret rhythm matches!

Level 2Appliance Wash-Cycle Done Notifier

Monitor washing machine vibration and chime when vibration stops for 2 continuous minutes.

Level 3Earthquake / Shock Logger

Combine with DS3231 RTC (Project 18) to timestamp peak shock counts.