Lesson 21 Vibration Switch

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp

Introduction

A vibration switch is a device that recognizes the amplitude of the vibration to which it is exposed and provides some sort of response when this amplitude exceeds a predetermined threshold value. The switch response is typically an electrical contact closure or contact opening. The electrical contact may be either an electromechanical relay or solid-state triac.

Components

– 1*SunFounder Uno board

– 1*USB data cable

– 1* vibration switch module

– Jumper wires

Experimental Principle

The main principle of vibration switch is that, conductive vibration spring and trigger pin are precisely placed in switch ontology and bond to curing position through adhesive. Normally, the spring and the trigger pin do not contact. Once shook, the spring will shake and contact with trigger pin to conduct and generate trigger signals.

With the LED attached to pin 13, connect the vibration switch to digital pin D8. When the vibration switch inducts vibration signals, pin SIG will output low level, and the LED on the module and the LED attached to pin 13 will light up. The schematic diagram of the vibration switch module is shown as follows.

Experimental Procedures

Step 1: Build the circuit

Step 2: Program (Please refer to the example code in LEARN -> Get Tutorial on our website)

Step 3: Compile the code

Step 4: Upload the sketch to the SunFounder Uno board

Now, shake the switch module, and you should see the LED attached to pin 13 on the SunFounder Uno board and the LED on the module light up.

Code

/************************************************
* name:Vibration Switch
* function: shake the switch module, and you should see the LED attached to pin 13 on the SunFounder Uno board and the LED on the module light up.
**************************************************/
//Email:support@sunfounder.com
//Website:www.sunfounder.comconst int vibswPin = 8; //the Vibration Switch attach to
const int ledPin = 13; //the led attach to
int val = 0; //initialize the variable val as 0
/******************************************/
void setup()
{
pinMode(vibswPin,INPUT); //initialize vibration switch as an input
pinMode(ledPin,OUTPUT); //initialize ledPin switch as an output
//Serial.begin(9600);
}
/*******************************************/
void loop()
{
val = digitalRead(vibswPin); //read the value from vibration switch
//Serial.println(val);
if(val == LOW) //without vibration signal
{
digitalWrite(ledPin,HIGH); //turn off the led
delay(500);//delay 500ms,The LED will be on for 500ms
}
else
{
digitalWrite(ledPin,LOW); //turn on the led
}
}
/*********************************************/