Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino UNO-Based Interactive Basketball Arcade Game with LCD Display

Image of Arduino UNO-Based Interactive Basketball Arcade Game with LCD Display

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

  • 5V connected to Resistor (1k Ohms)
  • A0 connected to Photocell (LDR) and Resistor (10k Ohms)
  • A1 connected to Photocell (LDR) and Resistor (1k Ohms)
  • GND connected to various components including Resistor (10k Ohms) and 16X2 LCD
  • D7 connected to Pushbutton
  • D13 connected to 16X2 LCD (V0)
  • D12 connected to 16X2 LCD (RS)
  • D11 connected to 16X2 LCD (E)
  • D5 connected to 16X2 LCD (D4)
  • D4 connected to 16X2 LCD (D5)
  • D3 connected to 16X2 LCD (D6)
  • D2 connected to 16X2 LCD (D7)

Resistor (1k Ohms)

  • One pin connected to 5V of Arduino UNO
  • Other pin connected to Pushbutton and Photocell (LDR)

Resistor (10k Ohms)

  • One pin connected to Photocell (LDR)
  • Other pin connected to GND of Arduino UNO

Pushbutton

  • One pin connected to D7 of Arduino UNO
  • Other pin connected to Resistor (1k Ohms)

Photocell (LDR)

  • One pin connected to Resistor (1k Ohms) and A1 of Arduino UNO
  • Other pin connected to Resistor (10k Ohms) and A0 of Arduino UNO

16X2 LCD

  • VSS connected to GND of Arduino UNO
  • VDD connected to Resistor (1k Ohms)
  • V0 connected to D13 of Arduino UNO
  • RS connected to D12 of Arduino UNO
  • RW connected to GND of Arduino UNO
  • E connected to D11 of Arduino UNO
  • D4 connected to D5 of Arduino UNO
  • D5 connected to D4 of Arduino UNO
  • D6 connected to D3 of Arduino UNO
  • D7 connected to D2 of Arduino UNO
  • A connected to Resistor (1k Ohms)
  • K connected to GND of 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.