Spin the Wheel Arduino
Hi. My name Is Sahil. I will be showing you my final project. This game is about spinning the wheel. This game aims to spin the wheel with an IR remote. When you press on the remote again the wheel stops and you get to watch the countdown on the seven segments and will have a chance to win a prize!
Supplies
- Arduino Uno x1
- Seven Segment display x1
- Servo Motot
- Push button x1
- LED's (Green and Red)
- 5 Resistors ( Three 330 and one 1k)
- IR Receiver And Remote X1
- Wires
- Breadboard
Wiring
First, How I created this project was I looked at this photo and would make the same connections into my breadboard. I first connected the Seven Segment Display, IR sensors and the push button. Then I added the Resistors to the proper spot and then I would connect everything using jumper wires. Afterward, I would use my Arduino and connect my seven segments to my digital pins alongside the pushbutton, connecting them to my digital pin. Lastly, I would connect my LED and Servo motor into the analog pins.
Downloads
CODE
In this step, I would put my code into my project. Here is my code Below.
#include <Servo.h>
#include <IRremote.h>
int a = 13;
int b = 12;
int c = 7;
int d = 8;
int e = 9;
int g = 11;
int f = 10;
int greenLed = A4;
int redLed = A5;
int completeBtn = 2;
Servo myServo;
int RECV_PIN = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
#define code1 490// code recived from negative button
void setup()
{
myServo.attach(3);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(greenLed,OUTPUT);
pinMode(redLed,OUTPUT);
pinMode (completeBtn, INPUT);
Serial.begin(9600);
irrecv.enableIRIn();
}
void nine()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
}
void eight()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(e, LOW);
digitalWrite(d, LOW);
}
void seven()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, HIGH);
digitalWrite(f, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
}
void six()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(e, LOW);
digitalWrite(d, LOW);
}
void five()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(e, HIGH);
digitalWrite(d, LOW);
}
void four()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, LOW);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
}
void three()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, LOW);
}
void two()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(g, LOW);
digitalWrite(f, HIGH);
digitalWrite(e, LOW);
digitalWrite(d, LOW);
}
void one()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, HIGH);
digitalWrite(f, HIGH);
digitalWrite(e, HIGH);
digitalWrite(d, HIGH);
}
void zero()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(g, HIGH);
digitalWrite(f, LOW);
digitalWrite(e, LOW);
digitalWrite(d, LOW);
}
void countdown()
{
nine();
delay(1000);
eight();
delay(1000);
seven();
delay(1000);
six();
delay(1000);
five();
delay(1000);
four();
delay(1000);
three();
delay(1000);
two();
delay(1000);
one();
delay(1000);
zero();
delay(1000);
}
void servoMotor ()
{
// stop rotation
delay(2000);
myServo.write(90);
}
void loop ()
{
myServo.write(0);
//delay(3000);
//myServo.write(90);
//delay(5000);
//countdown();
//delay (5000);
if (digitalRead(completeBtn) == HIGH){
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
}
else {
digitalWrite(greenLed, LOW);
digitalWrite(redLed, HIGH);
}
if (irrecv.decode(&results)){
Serial.println(results.value,HEX);
if (results.value == 0x490) //reciver recives 490 hex
{
myServo.write (90);
countdown();
}
else myServo.write (180);
irrecv.resume(); // Receive the next value
}
}
DEMO VIDEO
Here is a demo video of my project in action!
Thank you for reading this. Have a great day and try this out!