Gravity_Digital_Shake_Sensor_SKU_SEN0289-DFRobot

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. Shakes or vibrations in other directions like the X or Z do not produce an effective interrupt pulse.

Arduino Tutorial

This tutorial presents a basic usage of the module with Arduino UNO.

Requirements

Connection Diagram


Example Codes

#define LED_PIN                 13
#define DIGITAL_INPUT_PIN       3             //Connect the sensor to digital Pin 3 which is Interrupts 1.

unsigned char stateFlag = 0;
unsigned long timepoint = 0;
void setup()
{
  pinMode(LED_PIN, OUTPUT);

  // Set to input mode with internal pull-up. 
  // Otherwise, it will fail to generate intterupts under 3.3V power supply.
  pinMode(DIGITAL_INPUT_PIN, INPUT_PULLUP);   

  attachInterrupt(1, toggleLED, FALLING);     // Trigger LED toggle function when the falling edge is detected
  timepoint = millis();
}
void loop()
{
  // toggle onboard LED
  if (stateFlag != 0){
    digitalWrite(LED_PIN, HIGH);
  }
  else {
    digitalWrite(LED_PIN, LOW);
  }
}

//Interrupt serivce routinue
void toggleLED()
{
  // The hardware has done some filter. 
  // To further improve stability, here add a 50ms for debouncing.
  // This will not block the main function.
  if (millis() - timepoint > 50U){    
    timepoint = millis();
    stateFlag = (stateFlag + 1) % 2;
  }
}

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

DFshopping_car1.png Get SEN0289 Gravity: Digital Shake Sensor from DFRobot Store or DFRobot Distributor.

Turn to the Top