Spinning Wheel
My name is Darsh and I made a wheel that uses a spinning arrow to land on any choice for a game idea. When the arrow lands on a choice, the person will have 9 seconds to do the task on the wheel, when the timer runs out, the red LED will flash, when the timer is running and you push the pushbutton, the green LED will flash.
Supplies
For this project, you will need
- Arduino Board
- BreadBoard
- Seven Segment Display
- 5 resistors ( 4 330s and 1 10k)
- IR Receiver
- IR Remote
- Pushbutton
- Green and Red LED
- Servo Motor
And last some wires to keep the circuit nice and tidy!
Start the Wiring
This step would be a little difficult, especially for the seven segment display, but the wiring is simple, as according to the tinker cad diagram
1. Connecting Power
Since by project and components require ground and power the first step in to apply the VCC and the Ground from the Arduino to the breadboard (best one is probably 5V). Don't forget to add a jumper wire at the end of the breadboard so that the whole breadboard can be connected.
2. Building Seven Segment display
The next step in to build the seven segment display that will show case the numbers from 9 to 0. First we add wires connected to the correct pins on the seven segment:
int a = 11;
int b = 10;
int c = 9;
int d = 8;
int e = 7;
int g = 13;
int f = 12;
Than you will connect to resistors (330 ohms) on each side for power (+). The seven segment display will show numbers from led segments.
3. Servo Motor
The next component you will attach is the servo motor; and its quite simple. There are 3 colors on the servo motor orange representing 'pin' red representing 'power' and black representing 'ground'. You will connect all of these to the sated above. Check the photos for better guidance. When turned on the servo motors arm will move in a continuously in one direction like a clock.
4. IR receiver
Next is adding the IR receiver. For the IR receiver you need ground power and a pin. In my Tinkercad you can see where each one goes. When a HEX signal is given to IR receiver (infrared signals) then it shall function; you can check if your IR receiver is working by using the serial monitor.
int RECV_PIN = 5;
5. LED's
This one is straightforward you will need a connection to ground from both through resistors (330) and on the other side you need to connect it with a pin.
int greenLed = A4;
int redLed = A5;
The Code (Integers)
The code is also pretty simple
this would be the integers of all of the seven segment pins, LEDs, pushbutton, IR Receiver, and the Servo:
#include <Servo.h>
#include <IRremote.hpp>
int a = 11;
int b = 10;
int c = 9;
int d = 8;
int e = 7;
int f = 12;
int g = 13;
int greenLed = A4;
int redLed = A5;
int completeBtn = 2;
Servo myServo;
int RECV_PIN = 5;
#define VOL_UP 0xFE01BF00 // Volume Up (your remote)
bool stopTimer = false;
The Code (Void Setup)
This is the code where all the components are declared as either a input or output device:
void setup()
{
myServo.attach(3);
myServo.write(90); // stop position
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_PULLUP);
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
Serial.begin(9600);
IrReceiver.begin(RECV_PIN);
randomSeed(analogRead(A0));
}
The Code (The Voids 9-0)
This is the code for powering the Seven Segment display to work to form each of the numbers:
void zero()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, HIGH);
}
void one()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void two()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, HIGH);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void three()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, LOW);
}
void four()
{
digitalWrite(a, HIGH);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void five()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void six()
{
digitalWrite(a, LOW);
digitalWrite(b, HIGH);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void seven()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, HIGH);
digitalWrite(g, HIGH);
}
void eight()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, LOW);
digitalWrite(e, LOW);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
void nine()
{
digitalWrite(a, LOW);
digitalWrite(b, LOW);
digitalWrite(c, LOW);
digitalWrite(d, HIGH);
digitalWrite(e, HIGH);
digitalWrite(f, LOW);
digitalWrite(g, LOW);
}
It is kind of long, but is is really simple to do, just takes a lot of time. It is better to just do one of it and copy the rest 8 times and just change according to how each the numbers would show.
The Code (Seven Seg Countdown)
This code is for the countdown on the Seven Seg to work counting down from 9 to 0:
void countdown()
{
stopTimer = false;
// wait until button is released
while (digitalRead(completeBtn) == HIGH)
{
delay(10);
}
for (int i = 9; i >= 0; i--)
{
if (digitalRead(completeBtn) == HIGH) // button pressed
{
stopTimer = true;
break;
}
if (i == 9) nine();
if (i == 8) eight();
if (i == 7) seven();
if (i == 6) six();
if (i == 5) five();
if (i == 4) four();
if (i == 3) three();
if (i == 2) two();
if (i == 1) one();
if (i == 0) zero();
delay(1000);
}
if (stopTimer)
{
digitalWrite(greenLed, HIGH);
digitalWrite(redLed, LOW);
}
else
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
}
}
The Code (The Servo Spinning)
This is for the servo motor to spin randomly every time the volume+ button on the remote is pressed:
void spinWheel()
{
int spins = random(3, 6);
for (int i = 0; i < spins; i++)
{
myServo.write(20);
delay(180);
myServo.write(160);
delay(180);
}
myServo.write(90); // stop
}
This part is easy, just with the rotations and the delay of each rotation.
The Code (For the Whole Code Above to Work)
This is the void loop code, where method created above is being called down here and is constantly being repeated for the circuit to work:
void loop()
{
Serial.println(digitalRead(2));
delay(200);
if (IrReceiver.decode())
{
unsigned long code = IrReceiver.decodedIRData.decodedRawData;
Serial.println(code, HEX);
if (code == VOL_UP) // ignore repeat (0)
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, LOW);
spinWheel();
countdown();
}
IrReceiver.resume();
}
}
Final Project
This is the final outcome of the project, all the components wired in and the code working for the servo motor and the rest of the components.