Introduction
Do you want to switch lights by just shaking your hand? However, you may don't want to use a complicated and costly triple axis accelerometer. This digital shake sensor is sure to meet your needs.
The digital shake sensor is to detect hand shaking which only sensitive to unidirectional hand movements. The spring-type vibration switch is used to output a low-level pulse when the user shakes once in the specified direction and the on-board indicator flashes at the same time. Thanks to the unidirectional sensitivity of the vibration switch and the corresponding filter circuit, it has strong anti-shock interference capability to prevent false triggering. Simple and easy, switch controls are all in just a single shake.
Features
- Unidirection sensitive, strong anti-shock interference, preventing false triggering
- Compatible with 3.3V/5V controller
- Compact design, easy to install
Applications
- Shaking Light Stick
- Shake Switch
Specifications
- Input Voltage (VCC): 3.3V~5.0V
- Switch Life Span: Over 200,000 times
- Interface: Gravity 3P Digital
- Dimension: 30.0mm*22.0mm
Board Overview
Label | Name | Description |
---|---|---|
+ | VCC | Power VCC(3.3~5.5V) |
- | GND | Power GND |
D | Digital | Digital output (high-level when stationary, low-level pulse when shaken) |
PWR | Power | Power indicator (red), turned on when power up |
ON | ON | Shake triggered indicator (blue) |
How to Shake the Sensor
The vibration switch used by the sensor is unidirectional sensitivity. As shown in the above figure, the user can hold the module just like the logo on the module, and shake it in the direction of the arrow indicated on-board (from +Y to Y-). This will generate an effective low-level interrupt pulse on the “D” pin and a bright flash on the indicator ON. It is not sensitive to shaking, bumping or vibration in the X or Z direction, but can still trigger an interrupt if the shaking is severe.
When used, the detection of interrupt signals and an appropriate increase in the dithering time will make the trigger more stable.
Arduino Tutorial
This tutorial presents a basic usage of the module with Arduino UNO.
Requirements
- Hardware
- DFRduino UNO R3 (or similar) x 1
- DFRobot Gravity: Digital Shake Sensor x 1
- Gravity 3P digital wire (or Dupont wires) x 1
- Software
Connection Diagram
Example Codes
const int interruptPin = 2; // D2 pin is connected to interrupt pin
const int ledPin = 13; // D13 pin connected to LED
volatile bool interruptFlag = false;
unsigned long lastInterruptTime = 0;
const unsigned long debounceDelay = 1000; // Interrupt anti-shake delay time
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, RISING);
}
void loop() {
if (interruptFlag) {
interruptFlag = false;
if (millis() - lastInterruptTime >= debounceDelay) {
digitalWrite(ledPin, !digitalRead(ledPin));
lastInterruptTime = millis(); /
}
}
}
void handleInterrupt() {
interruptFlag = true;
}
Results
- In the direction indicated by the arrow on-board, every time the module is shaken, the ON indicator on the sensor will flash once. The indicator L on the Arduino UNO will be toggled once.
Micro:bit Tutorial
This tutorial presents a basic usage of the module with Raspberry Pi.
Requirements
- Hardware
- Micro:bit x 1
- Micro:mate x 1
- DFRobot Gravity: Digital Shake Sensor x 1
- Gravity 3P digital wire (or Dupont wires) x 1
- Software
Connection Diagram
Example Codes
FAQ
For any questions, advice or cool ideas to share, please visit the DFRobot Forum.