Arduino UNO-Based Interactive Basketball Arcade Game with LCD Display
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
The circuit in question appears to be designed for an interactive game, possibly a basketball arcade game, as suggested by the embedded code. It includes an Arduino UNO microcontroller as the central processing unit, interfaced with a 16x2 LCD for display purposes. The circuit also features input components such as a pushbutton and photocells (LDRs) for sensing light levels, which may be used to detect scoring events or player interactions. Resistors are used for various purposes, including pull-up/down configurations and voltage division.
Component List
Arduino UNO
- Microcontroller board based on the ATmega328P
- It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
Resistor (1k Ohms)
- Passive two-terminal electrical component
- Implements electrical resistance as a circuit element
Resistor (10k Ohms)
- Passive two-terminal electrical component
- Implements electrical resistance as a circuit element
Pushbutton
- A simple switch mechanism for controlling some aspect of a machine or a process
Photocell (LDR)
- A light-controlled variable resistor
- The resistance of a photoresistor decreases with increasing incident light intensity
16X2 LCD
- A simple display with 2 lines of 16 characters each
- Used for displaying information
Wiring Details
Arduino UNO
5Vconnected to Resistor (1k Ohms)A0connected to Photocell (LDR) and Resistor (10k Ohms)A1connected to Photocell (LDR) and Resistor (1k Ohms)GNDconnected to various components including Resistor (10k Ohms) and 16X2 LCDD7connected to PushbuttonD13connected to 16X2 LCD (V0)D12connected to 16X2 LCD (RS)D11connected to 16X2 LCD (E)D5connected to 16X2 LCD (D4)D4connected to 16X2 LCD (D5)D3connected to 16X2 LCD (D6)D2connected to 16X2 LCD (D7)
Resistor (1k Ohms)
- One pin connected to
5Vof Arduino UNO - Other pin connected to Pushbutton and Photocell (LDR)
Resistor (10k Ohms)
- One pin connected to Photocell (LDR)
- Other pin connected to
GNDof Arduino UNO
Pushbutton
- One pin connected to
D7of Arduino UNO - Other pin connected to Resistor (1k Ohms)
Photocell (LDR)
- One pin connected to Resistor (1k Ohms) and
A1of Arduino UNO - Other pin connected to Resistor (10k Ohms) and
A0of Arduino UNO
16X2 LCD
VSSconnected toGNDof Arduino UNOVDDconnected to Resistor (1k Ohms)V0connected toD13of Arduino UNORSconnected toD12of Arduino UNORWconnected toGNDof Arduino UNOEconnected toD11of Arduino UNOD4connected toD5of Arduino UNOD5connected toD4of Arduino UNOD6connected toD3of Arduino UNOD7connected toD2of Arduino UNOAconnected to Resistor (1k Ohms)Kconnected toGNDof Arduino UNO
Documented Code
#include <LiquidCrystal.h>
int oldVal1 = 0;
int oldVal2 = 0;
int blockedPercentage = 90;
int player1Score = 0;
int player2Score = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int buttonPin = 7;
long maxTime = 60000; // in ms
long currentTime = 0;
int mainDelay = 250;
int displayTime = 0;
int winner = 0;
const int contrast = 13;
// Function prototypes
void intro();
void initialScreen();
void initialScreenWithClock();
void renderDisplayTime();
void readyScreen();
void resetScreen();
void resetGame();
void renderWinner();
void setup() {
Serial.begin(9600);
analogWrite(contrast, 10);
pinMode(buttonPin, INPUT);
oldVal1 = analogRead(A0);
oldVal2 = analogRead(A1);
resetGame();
lcd.begin(16, 2);
intro();
readyScreen();
initialScreen();
}
void loop() {
int buttonState = digitalRead(buttonPin);
int updatePlayersScore = 0;
if (buttonState == HIGH) {
Serial.println("reset");
resetGame();
updatePlayersScore = 1;
resetScreen();
readyScreen();
initialScreen();
}
if (currentTime < 0) {
renderWinner();
return;
}
int value = analogRead(A0);
float value1Percentage = ((float) value / (float) oldVal1) * 100;
oldVal1 = value;
if (value1Percentage <= blockedPercentage) {
player1Score++;
updatePlayersScore = 1;
}
int value2 = analogRead(A1);
float value2Percentage = ((float) value2 / (float) oldVal2) * 100;
oldVal2 = value2;
if (value2Percentage <= blockedPercentage) {
player2Score++;
updatePlayersScore = 1;
}
if (updatePlayersScore) {
lcd.setCursor(0, 2);
lcd.print(" ");
Serial.println("Player 1 score: ");
Serial.println(player1Score);
lcd.setCursor(0, 2);
lcd.print(player1Score);
Serial.println("Player 2 score: ");
Serial.println(player2Score);
lcd.setCursor(6, 2);
lcd.print(player2Score);
updatePlayersScore = 0;
}
if (currentTime % 1000 == 0) {
displayTime = currentTime / 1000;
}
renderDisplayTime();
currentTime -= mainDelay;
delay(mainDelay);
}
// Additional functions are defined below
The code provided is for an Arduino UNO microcontroller and is responsible for controlling the game logic, including scorekeeping, display updates, and handling button presses to reset the game. The LiquidCrystal library is used to interface with the 16x2 LCD display. The code includes functions for displaying an introduction, ready screen, and winner screen, as well as for managing the game's state and scores.