Interactive Electronics Quiz Game With Arduino

by Boateng in Circuits > Arduino

602 Views, 0 Favorites, 0 Comments

Interactive Electronics Quiz Game With Arduino

ARDUINO ELECTRONICS GAME
IMG_20230830_205816.jpg

In this instructable, I will guide you through the creation of an interactive and educational Electronics Quiz game using Arduino. This project serves as a unique blend of entertainment and knowledge, providing an engaging platform to delve into essential electronics principles.

Supplies

Materials and Components:

  • Arduino board
  • 16x4 LCD display
  • Push buttons (True and False)
  • Buzzer
  • 6 LEDs
  • Jumper wires
  • Breadboard
  • 3.7v lithium battery(you can use 5v to power the arduino)
  • Glue gun and glue sticks

Software:

  • Arduino IDE
  • Tinkercad

Overview

The project's logic revolves around two sets of questions: Set 1 and Set 2. The questions are stored as structures containing the question text and the correct answer. The Arduino code displays questions one by one on the LCD and waits for the participant's response through the True and False buttons.

As participants answer questions, the code checks whether their answers are correct and increments the scores accordingly. When Set 1 is completed, the score is displayed, and the quiz proceeds to Set 2. After completing both sets, the final score is displayed. If the combined score exceeds 24 points, the LEDs light up in a celebratory pattern, accompanied by the message "Congratulations!"

Furthermore, the project has been designed with flexibility in mind. Educators or users can easily modify and upload new sets of questions to the Arduino, allowing for the expansion of the quiz to include questions from other subjects like physics, mathematics, or any desired domain. This adaptability makes the project a versatile educational tool with the potential to engage learners across diverse topics.

In summary, the project involves connecting an LCD, buttons, a buzzer, and LEDs to an Arduino board to create an interactive quiz game. The Arduino code manages the quiz flow, tracks scores, and controls LEDs and audio feedback. The project's flexibility allows for the integration of questions from various subjects, making it an adaptable and engaging educational tool.

Connecting the Components

TME EDU-GAME.png

To build the game, you'll need to connect the components properly.

Start by connecting the Arduino to your components based on this diagram. You can use a breadboard for a neat setup. Make sure to secure all the connections.

LCD Display

  • Connect the SDA (Serial Data) pin of the LCD display to the SDA pin on the Arduino.
  • Connect the SCL (Serial Clock) pin of the LCD display to the SCL pin on the Arduino.
  • Connect the VCC (Power) pin of the LCD display to 5V on the Arduino.
  • Connect the GND (Ground) pin of the LCD display to GND on the Arduino.

Pushbuttons (True/False)

  • Connect one terminal of the True button to digital pin 2 on the Arduino.
  • Connect the other terminal of the True button to GND on the Arduino.
  • Connect one terminal of the False button to digital pin 3 on the Arduino.
  • Connect the other terminal of the False button to GND on the Arduino.
  • Connect a 10k-ohm resistor from each button's free terminal to 5V on the Arduino. This pull-up resistor will ensure proper button functionality.

Buzzer

  • Connect the positive (red) wire of the buzzer to digital pin 4 on the Arduino.
  • Connect the negative (black) wire of the buzzer to GND on the Arduino.

LEDs (x6)

  • Connect the first LED's anode (longer leg) to digital pin 7 on the Arduino.
  • Connect the cathode (shorter leg) of the first LED to GND on the Arduino.
  • Repeat this process for the remaining five LEDs, connecting them to digital pins 8 to 12 for a sequential LED display.

Uploading the Code

Here's the Arduino code for the quiz game. You can copy and paste this code into your Arduino IDE:

// AUTHOR: ISAAC BOATENG

// DESCRIPTION: A quiz game to test knowledge on electronics concepts.

// The game displays questions on an LCD screen and uses buttons for user input.

// The user's score is displayed and LEDs blink in celebration if the score is high.

 

#include <Wire.h>

#include <hd44780.h>

#include <hd44780ioClass/hd44780_I2Cexp.h>

hd44780_I2Cexp lcd;

 

// Pin Definitions

int trueButtonPin = 2;     // Button to answer "True"

int falseButtonPin = 3;    // Button to answer "False"

int buzzerPin = 4;         // Buzzer for feedback

const int ledStartPin = 7; // Pin where the first LED is connected

 

// Variables to track scores and questions

int scoreSet1 = 0;

int scoreSet2 = 0;

int currentQuestionIndex = 0;

bool set1Completed = false;

 

// Define the Question structure

struct Question {

  const char *text;

  bool answer;

};

 

// Set 1 Questions

Question questionsSet1[] = {

   {"Electrons flow +ve  to -ve?", false},

  {"Diode allows one-way current?", true},

  {"Resistor limits     current?", true},

  {"AC stands for       alternating current?", true},

  {"Analog signals are   continuous?", true},

  {"A rectifier converts DC to AC?", false},

  {"Transistor amplifies signals?", true},

  {"LED emits light?", true},

  {"Zener diode regulates voltage?", true},

  {"Microcontroller has CPU?", true},

  {"nucleus contains    electrons ?", false},

  {"Op-amp amplifies    signals?", true},

  {"NAND gate is        universal?", false},

  {"v=IR?", true},

  {"protons move around electrons", false}

};

 

// Set 2 Questions

Question questionsSet2[] = {

  {"Electrons flow +ve  to -ve?", false},

  {"Diode allows one-way current?", true},

  {"Resistor limits     current?", true},

  {"AC stands for       alternating current?", true},

  {"Analog signals are   continuous?", true},

  {"A rectifier converts DC to AC?", false},

  {"Transistor amplifies signals?", true},

  {"LED emits light?", true},

  {"Zener diode regulates voltage?", true},

  {"Microcontroller has CPU?", true},

  {"nucleus contains    electrons ?", false},

  {"Op-amp amplifies    signals?", true},

  {"NAND gate is        universal?", false},

  {"v=IR?", true},

  {"protons move around electrons", false}

};

 

// Calculate the number of questions in each set

const int numQuestionsSet1 = sizeof(questionsSet1) / sizeof(questionsSet1[0]);

const int numQuestionsSet2 = sizeof(questionsSet2) / sizeof(questionsSet2[0]);

 

// Function prototypes

void setup();

void loop();

void askQuestion(Question *questionSet, int numQuestions);

void checkAnswer(bool correctAnswer, bool userAnswer);

void showSet1Score();

void showSet2Score();

void showFinalScore();

 

// Setup function, runs once at startup

void setup() {

  lcd.begin(20, 4); // Initialize the LCD display

  lcd.backlight();  // Turn on the backlight

 

  // Set button pins and LED pins as inputs/outputs

  pinMode(trueButtonPin, INPUT);

  pinMode(falseButtonPin, INPUT);

  pinMode(buzzerPin, OUTPUT);

  for (int i = ledStartPin; i <= ledStartPin + 5; i++) {

    pinMode(i, OUTPUT);

  }

 

  // Display introductory message on LCD

  lcd.clear();

  lcd.print("TME EDU-GAME        ELECTRONICS QUIZ");

  delay(3000);

}

 

// Main loop function, runs repeatedly

void loop() {

  // Check if Set 1 questions are completed

  if (!set1Completed) {

    if (currentQuestionIndex < numQuestionsSet1) {

      askQuestion(questionsSet1, numQuestionsSet1);

    } else {

      showSet1Score(); // Show Set 1 score

      set1Completed = true;

      currentQuestionIndex = 0;

    }

  } else { // Set 2 questions

    if (currentQuestionIndex < numQuestionsSet2) {

      askQuestion(questionsSet2, numQuestionsSet2);

    } else {

      showSet2Score();   // Show Set 2 score

      showFinalScore();  // Display final score and celebrate if high

    }

  }

}

 

// Function to ask a question and get user input

void askQuestion(Question *questionSet, int numQuestions) {

  lcd.clear();

  Question currentQuestion = questionSet[currentQuestionIndex];

  lcd.print(currentQuestion.text);

  lcd.setCursor(0, 1);

 

  // Wait for user input (True/False button press)

  while (true) {

    if (digitalRead(trueButtonPin) == HIGH) {

      checkAnswer(currentQuestion.answer, true);

      break;

    } else if (digitalRead(falseButtonPin) == HIGH) {

      checkAnswer(currentQuestion.answer, false);

      break;

    }

  }

 

  currentQuestionIndex++;

}

 

// Function to check the user's answer and provide feedback

void checkAnswer(bool correctAnswer, bool userAnswer) {

  lcd.clear();

  if (correctAnswer == userAnswer) {

    lcd.print("Correct!");

    if (!set1Completed) {

      scoreSet1++;

    } else {

      scoreSet2++;

    }

    digitalWrite(buzzerPin, HIGH);

    delay(1000);

    digitalWrite(buzzerPin, LOW);

  } else {

    lcd.print("Incorrect!");

    digitalWrite(buzzerPin, HIGH);

    delay(1000);

    digitalWrite(buzzerPin, LOW);

  }

 

  delay(1000);

  lcd.clear();

}

 

// Function to display Set 1 score

void showSet1Score() {

  lcd.clear();

  lcd.print("Set 1 Score: ");

  lcd.print(scoreSet1);

  delay(3000);

}

 

// Function to display Set 2 score

void showSet2Score() {

  lcd.clear();

  lcd.print("Set 2 Score: ");

  lcd.print(scoreSet2);

  delay(3000);

}

 

// Function to display final score and celebration

void showFinalScore() {

  lcd.clear();

  lcd.print("Quiz Over!");

  lcd.setCursor(0, 1);

  lcd.print("Total Score: ");

  lcd.print(scoreSet1 + scoreSet2);

 

  // If the total score is high, display congratulations and blink LEDs

  if (scoreSet1 + scoreSet2 > 24) {

    lcd.setCursor(0, 2);

    lcd.print("Congratulations!");

 

    // Blink LEDs in celebration

    while (true) {

      for (int i = ledStartPin; i <= ledStartPin + 5; i++) {

        digitalWrite(i, HIGH);

      }

      delay(100);

      for (int i = ledStartPin; i <= ledStartPin + 5; i++) {

        digitalWrite(i, LOW);

      }

      delay(100);

    }

  }

 

  delay(3000);

}

Customizing the Game

if you Want to create your own set of questions or expand the game into other subjects? You can do that by modifying the questions in the code. Just follow the same format to add more questions and enhance your learning experience.


Question questionsSet1[] = {

   {"Electrons flow +ve  to -ve?", false},

  {"Diode allows one-way current?", true},

  {"Resistor limits     current?", true},

  {"AC stands for       alternating current?", true},

  {"Analog signals are   continuous?", true},

  {"A rectifier converts DC to AC?", false},

  {"Transistor amplifies signals?", true},

  {"LED emits light?", true},

  {"Zener diode regulates voltage?", true},

  {"Microcontroller has CPU?", true},

  {"nucleus contains    electrons ?", false},

  {"Op-amp amplifies    signals?", true},

  {"NAND gate is        universal?", false},

  {"v=IR?", true},

  {"protons move around electrons", false}

};

 

// Set 2 Questions

Question questionsSet2[] = {

  {"Electrons flow +ve  to -ve?", false},

  {"Diode allows one-way current?", true},

  {"Resistor limits     current?", true},

  {"AC stands for       alternating current?", true},

  {"Analog signals are   continuous?", true},

  {"A rectifier converts DC to AC?", false},

  {"Transistor amplifies signals?", true},

  {"LED emits light?", true},

  {"Zener diode regulates voltage?", true},

  {"Microcontroller has CPU?", true},

  {"nucleus contains    electrons ?", false},

  {"Op-amp amplifies    signals?", true},

  {"NAND gate is        universal?", false},

  {"v=IR?", true},

  {"protons move around electrons", false}

you can change the questions and state weather it is true or false in the code and the number of questions you can stored depend on the arduino board you are using,if you want to store more questions then consider using arduino mega with enough storage capacity.