Skip to main content

64. Colour Sorting Game with Talking Arduino

Hey everyone!
Today I am going to explain you about making a fun game with Arduino and you can also make your Arduino talk. In this game, a total of 10 random questions will be asked and you have to place the coloured sheet when the respective colour is displayed on the LCD screen, or called. You will be given 5 attempts and if you use all of them, the game will be over and you should start it again.

Hardware components used in this project

  • Arduino Uno
  • USB Type A/ B cable
  • Ethernet Shield W5100/ SD card module
  • SD card
  • Solderless Breadboard Power rail - Half+
  • TCS230/ TCS3200 colour sensor
  • 16 x 2 LCD display module with I2C interface
  • Audio Jack/ Speaker/ Amplifier

Hardware setup

Connections


TCS230/ TCS3200 Colour sensor

  • GND - Ground
  • OE - Ground
  • S0 - D3
  • S1 - D5
  • S2 - D6
  • S3 - D7
  • Out - D8
  • VCC - 5V

16 x 2 LCD display module with I2C interface

  • GND - Ground
  • VCC - 5V
  • SDA - A4
  • SCL - A5

Coding

The audio files will be stored in your SD card and you will be needing the TMRpcm library to access these files.
Libraries needed for this project:
If you do not have these libraries, please feel free to follow the hyperlinks and download the libraries as ZIP folders. You can then add these ZIP folders to your Arduino IDE software by going to:
Sketch--->Include Library--->Add .ZIP Library...
If you are unsure about using TMRpcm, this documentation will help you:
Before moving on to the coding, you have to record your voice and convert those files from .mp3 to .wav format. You can use this online converter to convert the files before storing them in your SD card.
  • Welcome - A message that plays when you start the game
  • Red - Played when 'Red' is displayed in the LCD display module
  • Red_c - Played when the correct Red sheet is placed
  • Red_w - Played when the wrong colour sheet is placed 
  • Blue - Played when 'Blue' is displayed in the LCD display module
  • Blue_c - Played when the correct Blue sheet is placed
  • Blue_w - Played when the wrong colour sheet is placed 
  • Green - Played when 'Green' is displayed in the LCD display module
  • Green_c - Played when the correct Green sheet is placed
  • Green_w - Played when the wrong colour sheet is placed 
  • LBlue - Played when 'Light Blue' is displayed in the LCD display module
  • LBlue_c - Played when the correct Light Blue sheet is placed
  • LBlue_w - Played when the wrong colour sheet is placed 
  • Yellow - Played when 'Yellow' is displayed in the LCD display module
  • Yellow_c - Played when the correct Yellow sheet is placed
  • Yellow_w - Played when the wrong colour sheet is placed 
  • End - Played when the value stored in count variable (number of questions answered) reaches 10
  • Gameover - Played when the value stored in tries variable reaches 5
Now let's move on to the coding. First of all, you will need to include the libraries, mentioned above, in your Arduino IDE sketch. Create TMRpcm instance. Define the colour sensor pins.Create global variables named chipSelect, Red, Green, Blue, Count, Score, Final score and Tries. Set the LCD address for a 16 chars and 2 line display. The chipSelect variable must be assigned to D4 if you are using Ethernet shield.
  • Arduino Ethernet shield - D4
  • Adafruit SD shields and modules - D10
  • Sparkfun SD shield - D8
  • MKRZero SD - SDCARD_SS_PIN
Create a new function named colour. You have to use void data type for this. This function will be used to measure the frequencies of Red, Green and Blue respectively. 

void colour( ){
  digitalWrite(S2, LOW);
  digitalWrite(S3, LOW);
  Red=pulseIn(sensorOut, LOW);
  digitalWrite(S2, HIGH);
  digitalWrite(S3, HIGH);
  Green=pulseIn(sensorOut, LOW);
  digitalWrite(S2, LOW);
  digitalWrite(S3, HIGH);
  Blue=pulseIn(sensorOut, LOW);
}
Within void setup( ), initial the lcd and call the pinMode( ) function to configure the S0, S1, S2, and S3 pins as OUTPUT. The sensor output pin must be configured as INPUT. Set the data rate in 9600 baud for serial data transmission. Assign speakerPin to D9 if you are using Arduino Uno.
  • Arduino Uno, Nano, etc. - D9
  • Arduino Mega - D5, D6, D11 or D46
if(!SD.begin(SD_ChipSelectPin)){
    Serial.println("SD fail");
    return;
  }
Use this code snippet to check if your SD card is connected to the Arduino microcontroller board.
Set the volume level of the speaker. The volume can be set from 0 to 7. Play 'welcome' file as the LCD display module shows 'Ready'. Set a delay period depending on the duration of the 'welcome' file.
Now, create a local variable named 'number' and assign it to the random number generator. You will have to generate a random number between 0 - 4 (inclusive) because we will be using five colours in this game: Blue, Green, Light Blue, Red and Yellow.
You must use the colour sensor and the colour function which you created, to measure the frequencies of Red, Green and Blue for each coloured sheet. Using these frequencies, you can call the 'if' function to help the Arduino detect the colours. If you are unsure about this, please visit my previous project: https://arduinoprojectsbyr.blogspot.com/2019/12/45-arduino-based-colour-detection.html.
Use 'switch...case' function to assign each colour to the numbers.
  • 0 - Red
  • 1 - Blue
  • 2 - Green
  • 3 - Light Blue
  • 4 - Yellow
The top left corner of the LCD display must display the name of the colour, while the top right corner must display the number of tries. The number of tries will increase by one every time the wrong coloured sheet is placed within the gap. Once the number of tries reaches 5, the game will be over and the lcd display must show ' Game Over ' in the first row and ' Try again ' in the second row. The lcd display must be cleared before it shows the final score. The count, tries, and score variable must be reset to zero.
The bottom left corner of the LCD display must display the number of questions completed out of 10, and the bottom right corner must display the score. The score must increase by 10 every time the correct coloured sheet is placed in the gap. Once the number of questions completed reaches 10, your LCD display must show the final score. The count, tries, and score variable must be reset to zero.
If anyone has any questions with the coding, please feel free to send me an email at arduinoprojectsbyr@gmail.com.

Final Look

This is the final look of this project. Hope you enjoy this game! 
If anyone has any questions, or suggestions, about this project, please feel free to comment below or send me an email at arduinoprojectsbyr@gmail.com.

Comments

Popular posts from this blog

51. Buzz wire game using Arduino

Hello everyone! This is my first Arduino project in 2020 and it is going to be a fun and simple project. You would have heard of the Buzz Wire, a steady hand game, and today you will be learning to make one using Arduino. Hardware components used in this project Arduino Nano USB Type A to mini B cable (for Arduino Nano) Solderless Breadboard - Mini and Full-size LEDs (x2) - Green and Red Resistors (x2) - 220 Ω  Active Buzzer module (KY-012) LCD display module with I2C interface - 16x2 Male-to-Male Jumper wires (x4) - 10cm Female-to-Male Jumper wires (x5) - 20 cm Jumpers (x5) - to reduce the usage of wires Copper wire  Tape (or any form of insulation)  Setup Your hardware setup must look somewhat similar to the ones in the images above. The beginning and end of the copper wire maze must be taped to prevent conductivity between the wire loop and maze. Connections LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5

71. Buzz Wire Game ( Version 2.0 ) using Arduino

Hey Everyone! I hope that everyone's safe during this pandemic. Today I am going to explain you about the second version of my Buzz wire game. People who are bored of staying indoors can find this game pretty interesting and fun to play.  If you are a beginner, you can start off with my first version of this project :  51. Buzz wire game using Arduino   Hardware components used in this project Arduino Uno Solderless Breadboard (x2) - Full/ Full+ LCD display module with I2C module - 16x2 Potentiometer - B20K Push-buttons (x3) Resistor - 220 Ω Active Buzzer module (KY-012) LED - Red Copper Wire - 19/ 20 gauge thick Male-to-Male Jumper wires - 10cm and 20cm Wire - Long enough to connect the loop of copper wire to ground Other tools required for this project Cutting pliers - To cut the right amount of copper wire Round-nose pliers - To bend the copper wire and make a maze and loop Hardware setup Connections Wire Maze - D2 Wire loop - Ground (GND) B20K Potentiometer S - A0 (+) - 5V (-)

86. RFID Health tag (Arduino and Python)

 Hey everyone, Sorry I have not uploaded in a while. Today, I will be sharing an interesting project with all of you. This RFID Health tag project is useful when it comes to keeping track of vaccinated individuals, their biodata and their health conditions and medications. For this project, you will be needing Arduino and Python. Read on further to see how I did this project. Hardware components used in this project Arduino Uno Solderless Breadboard - Half+ MRFC522 RFID reader RFID key tags (x5) Push-buttons (x2) Male-to-Male Jumper wires (x12) USB Type A/ B cable (for Arduino Uno) Software required Arduino IDE - latest version recommended Python 3.8 Schematic MFRC522 RFID reader SDA/ SS - D10 SCK - D13 MOSI - D11 MISO - D12 IRQ - Not connected GND - Ground RST/ RESET - D9 3.3V - 3.3V Push-buttons Submit button - D4 Retrieve button - D5 Coding Arduino For this project, you will be using the following libraries: MFRC522 by miguelbalboa -  https://github.com/miguelbalboa/rfid SPI - In-bu