How to use a Vibration Sensor
- Get link
 - X
 - Other Apps
 
Vibration / Shake Switch
Introduction
In this tutorial we will use one vibration sensor or shake switch to make a beep sound from a buzzer while we shake our breadboard.
What you will need - Hardware
For this tutorial you will need: 
  | 
The Circuit
The connections are pretty easy. 
 The code :
Here's the code 
********************************************************************* 
/* Vibration Sensor (Shake Switch) - Testing with buzzer 
   In this tutorial we will use one vibration sensor (or shake switch)  
   to make a beep sound from a buzzer while we shake our breadboard. 
     */ 
const int buzzer = 8; //Buzzer connected to pin 8 of Arduino uno / mega 
int sensor;           //Variable to store analog value (0-1023) 
void setup() 
{ 
	Serial.begin(9600);      //Only for debugging 
	pinMode(buzzer, OUTPUT); 
} 
void loop() 
{ 
	sensor = analogRead(A0); 
	//While sensor is not moving, analog pin receive 1023~1024 value 
	if (sensor<1022){ 
		tone(buzzer, 500); 
		Serial.print("Sensor Value: "); 
		Serial.println(sensor); 
	}else{  
		noTone(buzzer); 
		Serial.print("Sensor Value: "); 
		Serial.println(sensor); 
	} 
	delay(100); //Small delay 
} 
********************************************************************* 
Well done!
You have successfully completed one more "How to" tutorial and you learned how to use a vibration (or shake) sensor with Arduino. 
I hope you liked this, let me know in the comments!  | 
- Get link
 - X
 - Other Apps
 

Comments
Post a Comment