Circuit Documentation
Summary
This circuit is a quiz game system built using an Arduino UNO, an I2C LCD 16x2 screen, three pushbuttons, and a resistor. The Arduino UNO controls the LCD screen to display questions and receives input from the pushbuttons to determine the user's answers. The system keeps track of the score and allows the user to restart the quiz.
Component List
I2C LCD 16x2 Screen
- Description: A 16x2 character LCD screen with I2C interface.
- Pins: SCL, SDA, VCC (5V), GND, VDD, VO, RS, RW, E, D0, D1, D2, D3, D4, D5, D6, D7, BLA, BLK
Arduino UNO
- Description: A microcontroller board based on the ATmega328P.
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
Pushbutton (3 units)
- Description: A simple pushbutton switch.
- Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
Resistor
- Description: A resistor with a resistance of 10k Ohms.
- Pins: pin1, pin2
- Properties: Resistance: 10k Ohms
Comment (3 units)
- Description: Placeholder for comments in the circuit.
- Pins: None
Wiring Details
I2C LCD 16x2 Screen
- SCL connected to Arduino UNO A5
- SDA connected to Arduino UNO A4
- VCC (5V) connected to Arduino UNO 5V
- GND connected to Arduino UNO GND
Arduino UNO
- A5 connected to I2C LCD 16x2 Screen SCL
- A4 connected to I2C LCD 16x2 Screen SDA
- 5V connected to I2C LCD 16x2 Screen VCC (5V)
- GND connected to I2C LCD 16x2 Screen GND
- GND connected to Resistor pin2
- D9 connected to Pushbutton Pin 3 (out)
- D8 connected to Pushbutton Pin 3 (out)
- D7 connected to Pushbutton Pin 3 (out)
Pushbutton 1
- Pin 3 (out) connected to Arduino UNO D9
- Pin 2 (in) connected to Resistor pin1
Pushbutton 2
- Pin 3 (out) connected to Arduino UNO D8
- Pin 2 (in) connected to Resistor pin1
Pushbutton 3
- Pin 3 (out) connected to Arduino UNO D7
- Pin 2 (in) connected to Resistor pin1
Resistor
- pin1 connected to Pushbutton Pin 2 (in)
- pin2 connected to Arduino UNO GND
Code Documentation
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
// Initialize LCD: 0x27 is the I2C address, adjust if necessary
LiquidCrystal_I2C lcd(0x27, 16, 2);
// Pin definitions
const int trueButton = 7;
const int falseButton = 8;
const int restartButton = 9;
// Quiz data: 6 questions with answers (true or false)
String questions[] = {
"Kean Handsome?", // True
"Pi equals 3.14?", // True
"1+1=3?", // False
"2+2=Lapu-Lapu?", // True
"Mlue is a color?", // False
"Tomato is Fruit?" // True
};
bool answers[] = {true, true, false, true, false, true};
int totalQuestions = 6; // Number of questions
// Variables
int currentQuestion = 0;
int score = 0;
void setup() {
lcd.init(); // Initialize the LCD
lcd.backlight(); // Turn on backlight
pinMode(trueButton, INPUT_PULLUP);
pinMode(falseButton, INPUT_PULLUP);
pinMode(restartButton, INPUT_PULLUP);
displayQuestion();
}
void loop() {
if (digitalRead(trueButton) == LOW) {
checkAnswer(true);
}
else if (digitalRead(falseButton) == LOW) {
checkAnswer(false);
}
else if (digitalRead(restartButton) == LOW) {
restartQuiz();
}
}
void displayQuestion() {
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Q" + String(currentQuestion + 1) + ":");
lcd.setCursor(0, 1);
lcd.print(questions[currentQuestion]);
}
void checkAnswer(bool userAnswer) {
lcd.clear();
if (userAnswer == answers[currentQuestion]) {
lcd.print("Correct!");
score++;
} else {
lcd.print("Incorrect!");
}
delay(2000); // Display result for 2 seconds
currentQuestion++;
if (currentQuestion < totalQuestions) {
displayQuestion();
} else {
displayScore();
}
}
void displayScore() {
lcd.clear();
lcd.print("Score: ");
lcd.print(score);
lcd.setCursor(0, 1);
lcd.print("Try Again?");
}
void restartQuiz() {
currentQuestion = 0;
score = 0;
displayQuestion();
}
This code initializes the LCD screen and sets up the pins for the pushbuttons. It then enters a loop where it waits for the user to press one of the buttons to answer the quiz questions or restart the quiz. The LCD displays the current question, and the user's answer is checked against the correct answer. The score is displayed at the end of the quiz, and the user can restart the quiz by pressing the restart button.
