Math Game Using Arduino | Arduino Project

by | Nov 25, 2022 | Arduino, Basic Coding, Coding

Home » Coding » Basic Coding » Arduino » Math Game Using Arduino | Arduino Project

Introduction

Do you want to make learning mathematics more interesting? Then you will find this Arduino project really helpful. Today we are going to create a Math Game Using Arduino. It will be a time-based game with components like Pushbuttons and LCD to display scores.

 

Supplies

To get started with making this project let’s have a look at the requirements first. We are doing this project online on Tinkercad, but you can also make it physically by purchasing the components online or from any electronics center

Components

Circuit Diagram

Math Game Using Arduino | Arduino Project

Steps To Create A Math Game Using Arduino

Step 1: Gather all the components onto the Digital Board or Physical Table.

Step 2: Plug the PushButtons on the BreadBoard.

PushButton:

Step 3: Now, Connect the First terminal of each to 5V pin of the Arduino.

Step 4: Connect the Second terminal of each to GND pin of the Arduino.

Step 5: Connect the 3rd pin of Pushbutton to the 10 and 11 number pin of the Arduino, respectively.

LCD:

Step 6: Connect Power and LED anode terminal of LCD to the 5V pin of the Arduino.

Step 7: Connect the Ground, Contrast, and Read/Write and LED cathode terminals of LCD to the GND pin of Arduino, as shown in the circuit diagram.

Step 8: Connect the Register Select, Enable, and DB4 to DB7 pins of LCD to the 2nd to 7th number pins of the Arduino, as shown in the figure.

Source Code

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
int a = 10, b = 11;
int A;
int score = 0;
void setup()
{
Serial.begin(9600);
lcd.begin(16,2);
pinMode(a, INPUT);
pinMode(b, INPUT);
}


void loop()
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Choose the ");
lcd.setCursor(0, 1);
lcd.print("correct answer ");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 12 x 12 = 144");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);


A = digitalRead(a);
Serial.print(A);
if(A == 1)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TRUE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 15 + 32 = 47 ");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);
A = digitalRead(a);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TRUE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 32 x 5 = 150");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);
A = digitalRead(b);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FALSE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 99 * 99 = 9891");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);


A = digitalRead(b);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("FALSE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 54 - 45 = 9");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);


A = digitalRead(a);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TRUE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 68 / 4 = 17");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);


A = digitalRead(a);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TRUE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print(" 67 % 2 = 1");
lcd.setCursor(0, 1);
lcd.print("a)True b)False");
delay(5000);


A = digitalRead(a);
Serial.print(A);
if(A == HIGH)
{
score = score + 5;
}


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("TRUE");
delay(2000);


lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Final Score = ");
lcd.setCursor(14, 0);
lcd.print(score);
delay(5000);
}

Explanation of the Code

1. Initially, we included a header file for LCD.

2. After that, we initialized arrays and variables that will be required in the function.

3. Now, for 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 and began the serial connection with 9600 bits per second.

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.

Purpose of Functions:

  • lcd.clear(): will help to clear the screen of the LCD
  • lcd.print(): prints the text in the LCD
  • lcd.setCursor(): helps to set the cursor in the LCD
  • Delay function: takes time in milliseconds, using which players will get 5 seconds of time to answer each question.

Output

Now let us have a look at the final output of this Arduino project once we have successfully established all the connections.

Math Game Using Arduino

When you start the simulation, you will be able to see the display on the LCD, and your final score after playing this math game will be displayed.

 

More Arduino Projects>>>

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *