Devices & Components
Arduino Uno Rev3
Mini Breadboard
Red LEDs
Resistor 330 ohm
Green LEDs
Active Buzzer
Vibration Sensor
Software & Tools
Arduino IDE
Project description
Code
Don't Move Me! : Game's Code
cpp
Arduino game based on a vibration sensor.
1const int greenLED = 2; 2const int redLED = 3; 3const int buzzer = 12; 4const int vibrationSensor = A0; 5 6void setup() { 7 pinMode(greenLED, OUTPUT); 8 pinMode(redLED, OUTPUT); 9 pinMode(buzzer, OUTPUT); 10 pinMode(vibrationSensor, INPUT); 11 12 startGame(); 13} 14 15void loop() { 16 int sensorValue = digitalRead(vibrationSensor); 17 18 if (sensorValue == HIGH) { // Vibration detected 19 digitalWrite(greenLED, LOW); 20 digitalWrite(redLED, HIGH); 21 digitalWrite(buzzer, HIGH); 22 //wait for 3 seconds 23 delay(3000); 24 //turn off the buzzer 25 //we turn off the buzzer and wait for 5 seconds before restarting the game. 26 //We wait because the buzzer itself create vibration which is detected by the vibration sensor. 27 digitalWrite(buzzer, LOW); 28 //wait for five seconds before restarting the game 29 delay(5000); 30 startGame(); // Restart the game 31 } 32} 33 34void startGame() { 35 digitalWrite(greenLED, HIGH); // Turn on green LED to indicate game start 36 digitalWrite(redLED, LOW); 37}
Downloadable files
Don't Move Me! : Game's Circuit
Arduino game based on a vibration sensor.
Untitled Sketch 2_bb.png

Documentation
Don't Move Me! : Game's Circuit
Arduino game based on a vibration sensor.
Untitled Sketch 2_bb.png

Comments
Only logged in users can leave comments