Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Vibration / Shake Switch

Available Languages
Picture
Picture

Introduction 

Picture
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:
  • Arduino uno
  • Breadboard
  • Vibration/Shake switch
  • Buzzer

The Circuit

Ardumotive Tutorial - Arduino Shake Vibration Sensor
The connections are pretty easy.
  • Connect one pin of vibration sensor to Arduino Analog pin A0 and the other to 5V pin.
  • Now connect the buzzer, one pin to Arduino pin 8 and the other to GND.
​

The code

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/* 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.
   
   Find more info and video here: http://bit.ly/1iDbc2Q
   
   Dev: Michalis Vasilakis - Date: 9/9/2015 - www.ardumotive.com       */
   
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
}
Download the code from here and open it with Arduino IDE. Open the serial monitor from tools menu of Arduino IDE to test it.
vibrationsensor_tutorial.zip
File Size: 0 kb
File Type: zip
Download File

Well done!

Picture
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!
Picture
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates