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

77. Controlling Micro servo Robotic Arm with MPU-6050 sensor module

 Hey everyone! I am back with an interesting project. Today, you will be learning about controlling a Simple 2 axis Robotic Arm, made from Micro servo motors, with an MPU-6050 sensor module. Please feel free to visit my previous blog post to learn about the MPU-6050 sensor module. Hardware components used in this project Arduino Mega 2560 - You could use any other Arduino microcontroller, but make sure you use an external power supply. USB Type A/B cable (for Arduino Mega 2560) MPU-6050 sensor module SG-90 Tower Pro Micro Servo motor (x2) Male-to-Male Jumper wires (x6) Male-to-Female Jumper wires (x5) Setup Schematic MPU-6050 sensor module VCC - 3.3V GND - Ground SDA - D20 (Arduino Mega 2560), A4 (Arduino Uno and Nano) SCL - D21 (Arduino Mega 2560), A5 (Arduino Uno and Nano) INT - D2 Micro servo motor (Roll) S (Yellow/ Orange) - D9 + (Red) - 5V - (Black/ Brown) - GND  Micro servo motor (Pitch) S (Yellow/ Orange) - D10 + (Red) - 5V - (Black/ Brown) - GND Coding As I alread...

57. Using Blynk with Arduino Uno and ESP8266 WiFi module

Hello Everyone! Today I am going to explain you how to connect your Arduino Uno with Blynk using the ESP8266 WiFi module. I have already demonstrated you about connecting your Arduino Uno with Blynk app using the Ethernet Shield W5100 and this will be the second version of that project .  Hardware components used in this project Arduino Uno ESP-01 ESP8266 WiFi module USB to TTL converter Solderless Breadboard - Half+ Breadboard power supply module - 3.3V/ 5V RGB LEDs (x3) - Common Anode Resistors (x3) - 220 Ω Relay module - 5V single channel Male-to-Male Jumper wires Female-to-Male Jumper wires Setup Your setup must look somewhat similar to that shown in the images above. Connections ESP8266 ESP-01 wifi module GND - Ground GPIO0- Not connected GPIO2 - Not connected RXD - D2 TXD - D3 CH_PD - VCC - 3.3V RESET - Not connected VCC - 3.3V  *Note: Do not connect your ESP8266 ESP-01 wifi module with 5V. RGB LED - Common Anode Anode -...

70. Arduino Stopwatch and Timer

Hello everyone! Today I am going to explain you about making an Arduino Stopwatch and Timer, which can be used for time based projects. Read on further to learn more about this project. Hardware components used in this project Arduino Uno USB Type A/ B cable Solderless Breadboard - Full+ LCD display module with I2C interface - 16x2 Potentiometer - 10K Push-buttons (x5) Active Buzzer module (KY-012) LED - Red Resistors (x6) - 10kΩ (x5) and 220Ω (x1) Male-to-Male Jumper wires - 10cm and 20cm Jumpers - to reduce the usage of wires Hardware setup Connections 10K Potentiometer S - A0 (+) - 5V (-) - Ground (GND) Active Buzzer module S - D7 (+) - 5V (-) - Ground (GND) 16x2 LCD display module with I2C interface GND - Ground VCC - 5V SDA - A4 SCL - A5 Push-buttons (+) - 5V (-) - Ground (GND) S - D2, D3, D4, D5, D6 Coding Now, I will explain you about how this real-time project works and you can figure out the coding by this idea.  Push-buttons and their functions D2 - Set Countdown timer D3...