Circuit LED Game
Hello, my name is Jas Grewal and on this instructable, I will be presenting my final project. For this project, I have created a LED chaser game. In this game, the LEDs will be flashing in consecutive order. On the serial monitor on the Arduino, you will be given a colour. With the given, you will need to press the button at the same time the LED chaser passes over that colour. For example, if you are given red, you will need to press the pushbutton right as it passes over red. This circuit works through the usage of a Piezo, a RGB, and an Arduino. The RGB gives a colour, and the LED's will be flashing and you must align the RGB colour with the LED. Every time, you do not align the colour, the Piezo buzzes, you will be given a new colour.
Supplies
The supplies are listed in the Google Charts below.
1 Arduino Uno R3
1 Red LED
1 Yellow LED
1 Green LED
1 Orange LED
1 Blue LED
1 LED RGB
1 Pushbutton
1 Piezo
R1, R3, R4, R2, R7, R8 6 560 Ω Resistor
R6 1 10 kΩ Resistor
Downloads
Start Breadboard/connect Power Source
Since there will be multiple components that require both power and ground, the first thing to do is to connect the VCC and GND to the breadboard so that it flows throughout. The main purpose of a power supply is to convert electric current from a source to the correct voltage, current, and frequency to power the load. All Arduino boards need electric power to function. A power supply is what is used to provide electric power to the boards and typically can be a battery, USB cable, AC adapter or a regulated power source device. Check the PDF below.
Drag an Arduino Uno and breadboard from the components panel to the work plane.
Connect breadboard power (+) and ground (-) rails to Arduino 5V (Red wire) and ground (GND)(Black wires), respectively, by clicking to create wires.
Extend power and ground rails to their respective buses on the opposite edge of the breadboard by creating a red wire between both power buses and a black wire between both ground buses.
Components
Add your components, the Piezo, LED’s, RGB, resistors, and pushbuttons. Make sure the resistors go to ground (for the RGB and LED's).
Make sure the resistors connect the LED to ground. Plug the LED into two different breadboard rows so that the cathode (negative, shorter leg) connects to one leg of a resistor. The resistor (560ohms) can go in either orientation because resistors aren't polarized, unlike LEDs, which must be connected in a certain way to function. Connect other resistor leg to ground. Wire up the LED anode (positive, longer leg) to Arduino.
Drag a pushbutton from the components panel to the center of your breadboard, and place it across the center column break so that its legs are plugged into four different breadboard rows.
Click to create a wire connecting one button leg to power.
Create and position a high value resistor (10K) between that same button leg and ground on opposite side.
To better understand what's going on, it's useful to also take a look at a free-wired version of the sample circuit, pictured here.
Explore the sample circuit embedded here by starting the simulation and testing the pushbutton. Remember that the breadboard rows are connected inside, so you can plug in components and wires to make quick temporary connections. You could load up a new Tinkercad Circuits window and build your own version of this circuit along side the sample. Reference, the picture above. You may choose to do the exact same placement as my tinkercad or schematic.
Wiring
In this step start wiring all your components. Make sure to use the proper colour for the RGB wires. Connect your Piezo to ground, pushbutton to power, all the LED's to each output. Check PDF below.
Add your components, the Piezo, LED’s, RGB, resistors, and pushbuttons.
560Ω resistors go to ground
10kΩ resistor go to ground
RGB go to ground
LED go to ground
Piezo go to ground
Pushbutton go to ground
LEDred to pin 8
LEDorange to pin 9
LEDyellow to pin10
LEDgreen to pin 11
LEDblue to pin 12
Push to pin 2
Buzz to pin 7
Code
When the code editor is open, you can click the dropdown menu on the left and select "Blocks + Text" to reveal the Arduino code generated by the code blocks. Follow along as we explore the code in more detail. Anything after a set of slashes // is a comment, just for us humans to read, and is not included in the program when the Arduino runs it.
Downloads
Int Code
’s called int because it’s an integer, or any whole number.
//Code //Variables int red = 8; int orange =9; int yellow = 10; int green = 11; int blue = 12; int push = 2; int buzz = 7; int redRGB = 6; int blueRGB = 5; int greenRGB = 3; int colNumber = 0; int ledNumber =0; int score =0;
These are the int codes
You may switch the pins around.
PinMode() Code
Inside the setup, pins are configured using the pinMode() function. It is configured as an input, so we can "listen" to the electrical state of the pushbutton.
//Setup void setup() { Serial.begin(9600); pinMode(red, OUTPUT); pinMode(orange, OUTPUT); pinMode(yellow,OUTPUT); pinMode(green,OUTPUT); pinMode(blue,OUTPUT); pinMode(buzz,OUTPUT); pinMode(push,INPUT); pinMode(redRGB, OUTPUT); pinMode(greenRGB,OUTPUT); pinMode(blueRGB,OUTPUT); rgbColour(); }The pinMode() function is used to configure a specific pin to behave either as an input or an output.
Pin: the Arduino pin number to set the mode of.
Mode: INPUT, OUTPUT, or INPUT_PULLUP.The analog input pins can be used as digital pins, referred to as A0, A1, etc.