DFROBOT SEN0289 Digital Sway Sensor Product Information Tutorial

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

Applications

Specifications

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

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

Micro:bit Tutorial

This tutorial presents a basic usage of the module with Raspberry Pi.

Requirements

Connection Diagram


Example Codes


FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum.

More Documents