Match the Color Game Using 555, 4017 and RGB LED
772 Views, 1 Favorites, 0 Comments
Match the Color Game Using 555, 4017 and RGB LED
I created a circuit in which random colors are picked and where the user must attempt to match the colors as many times as possible for a high score as they blink on and off from left to right at a certain speed. The score and the info are displayed on the serial monitor. The buzzer also makes three unique sounds one for matching, mismatching, and a tune for a new high score. The project is quite simple and not too complex to understand. I've created a diagram on TinkerCAD as well as a working circuit in real life.
Supplies
1x Arduino UNO
1x Breadboard
1x Buzzer
LEDs (4x yellow, 3x green, 2x red)
RBG LED
Resistors (12x 10kΩ, 6x 330Ω)
1x 100 μF Polarized Capacitor
Wires
1x Pushbutton
1x 555 Timer
1x 4017 Decade Counter
1x Potentiometer (Optional)
If you none of these components I recommend that you get a kit with all these components plus more.
Full Schematics
I've made three different schematics 2 on TinkerCAD and 1 on Frizing. The only difference is the capability to control the blinking rate for one with the potentiometer. The one I made is the one without it since it's at the pace that I wanted. The Frizing schematic is also based on the one I actually made.
The circuit is made up of the 555 timer and the 4017 decade counter that is connected to the LEDs that work completely independent of the Arduino. The Arduino just checks to see what LED is on when the user presses the button and determines whether or not the user was able to successfully able to match the LED color to that of the RGB led. The 555 timer pulses at a constant pace and sends that electric current signal to the 4017 decade counter, whenever a clock pulse is received at the clock input of the 4017 decade counter, it increments the count and activates the corresponding output PIN, and turns on each LED one after the other in a loop.
Coding
//Declaring the pins
int button = 13; int LED1 = 9; int LED2 = A4; int LED3 = A3; int LED4 = A0; int LED5 = 8; int LED6 = A5; int LED7 = A2; int LED8 = A1; int LED9 = 7;
int red_light_pin= 2; int green_light_pin = 3; int blue_light_pin = 4;
const int buzzer = 6; int sound = 500;
int iRand = 0;
int LEDS = 0; int points = 0; int point = -1; int Highscore = 0;
void setup() { pinMode(13, INPUT); pinMode(7, INPUT); pinMode(8, INPUT); pinMode(9, INPUT); pinMode(red_light_pin, OUTPUT); pinMode(green_light_pin, OUTPUT); pinMode(blue_light_pin, OUTPUT); Serial.begin(9600); } void setTone(int pin, int note, int duration) { //Setting up tone for the simpler alarm sounds tone(pin, note, duration); delay(duration); noTone(pin); }
void buttonpush() { if (digitalRead(button) == LOW) //detects the button push { if (LEDS == iRand)//If the colors matched { tone(buzzer, 600); delay(130); tone(buzzer, 750);; delay(70); noTone(buzzer); points++; Serial.print("You're current score is "); Serial.println(points); } else // The colors are mismatched { tone(buzzer, 400); delay(200); tone(buzzer, 300); delay(130); tone(buzzer, 100); delay(100); noTone(buzzer); if (Highscore < points){ Highscore = points; Serial.print("You landed on wrong LED... You got a new highscore of "); Serial.println(Highscore); points = -1; tone(buzzer, 400); delay(200); tone(buzzer, 500); delay(130); tone(buzzer, 700); delay(100); noTone(buzzer); } else{ Serial.print("You landed on wrong LED... This time you scored "); Serial.println(points); Serial.print("Your Highest score was "); Serial.println(Highscore); points = 0; } } delay(2000); } }
void LEDcolors()//Here is where each color is assigned the correct number; 3 = yellow, 2 = green and 1 = red. This is also where {// it is checked to see what LED is on, so when the button is pushed buttonpush();// it will know if the correct colors are matched if (digitalRead(LED9) == 1) { LEDS = 3; } else if (digitalRead(LED8) == 1) { LEDS = 2; } else if (digitalRead(LED7) == 1) { LEDS = 3; } else if (digitalRead(LED6) == 1) { LEDS = 1; } else if (digitalRead(LED5) == 1) { LEDS = 2; } else if (digitalRead(LED4) == 1) { LEDS = 3; } else if (digitalRead(LED3) == 1) { LEDS = 1; } else if (digitalRead(LED2) == 1) { LEDS = 2; } else if (digitalRead(LED1) == 1) { LEDS = 3; } buttonpush(); } void RGB_color(int red_light_value, int green_light_value, int blue_light_value) { //Serial.println(red_light_value); //Serial.println(green_light_value); //Serial.println(blue_light_value); analogWrite(red_light_pin, red_light_value); analogWrite(green_light_pin, green_light_value); analogWrite(blue_light_pin, blue_light_value); }
void loop() //Main loop where the game will continue to run forever { if (points != point){ RGB_color(0, 0, 0); iRand = random(1,4);//Random number between 1 and 3 is choosen which is what determines what color the user must match //Serial.println("TEST"); //Serial.println(iRand); if (iRand == 1){ RGB_color(0, 255, 255); // Red //Serial.println("red"); } else if (iRand == 2){ RGB_color(255, 0, 255); // Green //Serial.println("green"); } else if (iRand == 3){ RGB_color(0, 0, 255); // Yellow //Serial.println("yellow"); } point=points; } LEDcolors(); }
Downloads
Wiring
Follow diagrams of the circuit and make sure each wire is in the correct spot and isn't lose. Overall the wiring is very simple but can be very condensed so try to make it as neat as possible. Also, feel free to edit the code to your liking and maybe add other features.
End
You made it to the end. I've attached a video of the project working. I hope this project inspired you to either make this project or gave you an idea of a project that you might want to make next. Thank you for taking the time to read this and I hope you liked the project.