10% Off For Your First Order, Code:Elephant10



Arduino Project: Vibration Switch

Posted by Fiona Su on

thumb

Introduction:
Vibration switch, also called vibration sensor. It is a electronic switch sensing the intensity of a vibration and transfer the result to the circuit device, and activate the circuit to start working.
Hardware Required:

  • Arduino Board *1
  • USB Cable *1
  • Vibration Sensor*1
  • 10KΩ Resistor *1
  • Breadboard*1
  • Breadboard Jumper Wire*3

Connection for REV4:

thumb

Connection for Arduino Mega 2560 R3:

thumb

Sample Code:

#define SensorLED     13
#define SensorINPUT   2  
unsigned char state = 0; 
void setup() 
{ 
  pinMode(SensorLED, OUTPUT); 
  pinMode(SensorINPUT, INPUT);
attachInterrupt(0, blink, FALLING);//D2 as external interruption 0, when there is falling trigger and call blink function
 
}
void loop()
{
      if(state!=0)
      {
        digitalWrite(SensorLED,HIGH);
        delay(3000);
        state = 0;
      }   
      else 
        digitalWrite(SensorLED,LOW);
}  
 
void blink()// digital input of the sensor falling, triggering interruption function
{
  state++;
}

Result:
Touch the sensor with your hand, the D13 indicator light on Arduino will be on for 3 seconds and then be out.

0 comments

Leave a comment

Please note, comments must be approved before they are published