Introduction of the Project
In this project guide, we will explain how to create a number game with Arduino. Arduino is a popular open-source hardware and software platform that enables people to create interactive electronic projects. With its versatile microcontroller and various sensors, an Arduino board can be used to create a wide range of games, including number games. A number game is a fun and challenging game that involves guessing a number within a specific series.
We will walk you through the process of setting up the hardware, coding the game, and testing it. We will also provide tips and tricks to help you customize and improve your game. Whether you are a beginner or an experienced Arduino user, this guide will give you the skills and knowledge you need to create a fun and engaging number game that you can enjoy with your friends and family. So, let’s get started!
Supplies
To create a number game with Arduino, we will use pushbuttons and an LCD screen to play a time-based number game. To build this Arduino project, we will require the following components:
Components
- Arduino Uno R3
- 4 Pushbuttons
- LCD 16×2
- 1 Small Breadboard
- 5 Resistors
- Connecting Wires
You can get all these components online or from any nearby electronics shop. We have created this project online with the TinkerCad website.
Circuit Diagram
Steps To Create A Number Game With Arduino
Step 1: Gather all the components on the Digital Board or Physical Table.
Step 2: Plug all the PushButtons on the BreadBoard.
PushButton:
Step 3: Connect the 1st terminal of each to the 5V pin of the Arduino.
Step 4: Connect the 2nd terminal of each to the GND (Ground) pin of the Arduino.
Step 5: Connect the 3rd pin of it to the 8, 9, 10, & 11 number pins of the Arduino, respectively.
LCD:
Step 6: Connect the Power & the LED anode terminal of it to the 5V pin of the Arduino.
Step 7: Connect the Ground, Contrast, and Read/Write & LED cathode terminals of it to the GND pin of the Arduino, as shown in the circuit.
Step 8: Connect the Register Select, Enable, & DB4 to DB7 pins of it to the 2 to 7 number pins of the Arduino, respectively, as shown in the figure.
Source Code
#include <LiquidCrystal.h> LiquidCrystal lcd(2, 3, 4, 5, 6, 7); int a = 8, b = 9, c = 10, d = 11; int A; int score = 0; void setup() { lcd.begin(16,2); pinMode(a, INPUT); pinMode(b, INPUT); pinMode(c, INPUT); pinMode(d, INPUT); } void loop() { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Select next no. "); lcd.setCursor(0, 1); lcd.print("in the series "); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 2, 4, 8, 16 , ?"); lcd.setCursor(0, 1); lcd.print("32 | 6 | 20 | 40"); delay(5000); A = digitalRead(a); if(A == 1) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 1, 3, 5, 7, ?"); lcd.setCursor(0, 1); lcd.print("10 | 11 | 9 | 8"); delay(5000); A = digitalRead(c); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 2, 3, 5, 7, ?"); lcd.setCursor(0, 1); lcd.print("10 | 11 | 9 | 8"); delay(5000); A = digitalRead(b); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 3, 9, 27, 81, ?"); lcd.setCursor(0, 1); lcd.print("243 | 1 | 9 | 10"); delay(5000); A = digitalRead(a); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 1, 1, 2, 3, ?"); lcd.setCursor(0, 1); lcd.print("8 | 5 | 9 | 8"); delay(5000); A = digitalRead(b); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 1, 2, 4, 7, ?"); lcd.setCursor(0, 1); lcd.print("10 | 11 | 9 | 8"); delay(5000); A = digitalRead(b); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Score :"); lcd.setCursor(0, 1); lcd.print(score); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print(" 10, 7, 5, 4, ?"); lcd.setCursor(0, 1); lcd.print("1 | 3 | 4 | 8"); delay(5000); A = digitalRead(c); if(A == HIGH) { score = score + 5; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Final Score = "); lcd.setCursor(15, 0); lcd.print(score); delay(5000); }
Explanation of the Code
1. First thing was to include a header file, “LiquidCrystal” for LCD.
2. After that, we initialized arrays and variables that will be required in the function.
3. In the setup function, we have declared the LCD as having 2 rows and 16 columns. Also, we have configured the pin mode for input purposes.
4. In the loop function, we display the options, along with the question, and give 5 seconds of time to the player to give the answer to that question using the push button. If the answer is right, the player will get 5 points, and at last, the final score will be displayed.
5. Following are the functions with their use case that we have used in our source code:
- lcd.clear() function will help to clear the screen of the LCD.
- lcd.print() function prints the text in the LCD.
- lcd.setCursor() function helps to set the cursor in the LCD.
- The delay function takes time in milliseconds, using which players will be given 5 seconds of time to answer each question.
Output
On starting the simulation, we will be able to see the display in LCD and see our final score at the end of the game.
Recommendation
- Define the rules: Before starting to code, define the rules of your number game. Determine the range of numbers that the player can guess, the number of guesses they have, and the winning conditions.
- Choose the hardware: Select the appropriate hardware for your game, such as an Arduino board, LEDs, buttons, and a display. Ensure that the hardware is compatible with each other and with the game you want to create.
- Write the code: Use the Arduino Integrated Development Environment (IDE) to write the code for your game. Create functions for generating random numbers, checking the player’s guesses, and displaying the game’s outcome.
- Test the game: Test your game by running it on your Arduino board and checking that it works as expected. Make any necessary adjustments to the code or hardware to improve the game’s functionality and user experience.
- Customize the game: Add features and personal touches to your game, such as sound effects, difficulty levels, or a high score table. Experiment with different hardware components to enhance the game’s interactivity and engagement.
- Share the game: Once your game is complete, share it with others by uploading the code to the Arduino community or posting it on social media. Get feedback and suggestions from others to improve your game even further.

Meerali’s expertise lies in building Arduino projects from scratch. She has a vast knowledge of the various sensors, actuators, and other electronic components that can be used with Arduino boards. Meerali is also skilled in programming languages like C++, Python, and Java, which are commonly used to program Arduino boards.
0 Comments