🏀 Arduino Mini Basketball Game – Goal Counter with IR Sensor, 7-Segment Display & I2C LCD

 



📌 Project Overview

This project is a Mini Basketball Game made with an Arduino board, IR sensor, 7-segment display, buzzer, and an I2C LCD.

  • The IR sensor detects when the ball goes through the hoop.

  • The 7-segment display shows the score (0–9 for 1 digit).

  • The I2C LCD shows the game title and flashes “GOAL!” when a score is made.

  • The buzzer plays a short beep sound whenever a goal is scored.

  • The Arduino RESET button resets the game.

This is a fun project for kids, students, and hobbyists who want to learn Arduino in a playful way.



🎯 Components Required

  • Arduino UNO (or compatible board)

  • 1 × IR Sensor Module

  • 1 × 7-Segment Display (Common Cathode, 1-digit)

  • 1 × 16×2 LCD with I2C module

  • 1 × Buzzer (active)

  • Jumper wires

  • Breadboard or PCB

🔌 Circuit Connections

IR Sensor

IR Sensor PinArduino Pin
VCC5V
GNDGND
OUTD2

Buzzer

Buzzer PinArduino Pin
+D8
GND

7-Segment Display (1-digit, common cathode)

7SegmentArduino Pin
aD4
bD5
cD6
dD7
eD8
fD9
gD10
DPNot used
Common CathodeGND

I2C LCD (16×2)

LCD PinArduino Pin
SDAA4
SCLA5
VCC5V
GNDGND

📜 Arduino Code

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <SevSeg.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); 
SevSeg sevseg;

const int irPin = 2;         
const int buzzerPin = 8;

int score = 0;
bool goalDetected = false;

void setup() {
  pinMode(irPin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  
  lcd.backlight();
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Seema HIZBULLAH");
  lcd.setCursor(0,1);
  lcd.print(".CC BASKET BALL");

  
  byte numDigits = 1;
  byte digitPins[] = {}; 
  byte segmentPins[] = {4,5,6,7,8,9,10}; 
  bool resistorsOnSegments = true;
  sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
}

void loop() {
  // Detect goal with IR sensor
  if(digitalRead(irPin) == LOW){ // LOW when ball blocks IR
    if(!goalDetected){
      score++;
      if(score > 9) score = 9; // limit to 1-digit
      digitalWrite(buzzerPin, HIGH);
      lcd.setCursor(0,1);
      lcd.print("GOAL!          "); 
      delay(200);
      digitalWrite(buzzerPin, LOW);
      goalDetected = true; // prevent double count
    }
  } else {
    goalDetected = false;
    lcd.setCursor(0,1);
    lcd.print("                "); // clear line
  }

  // Show score on 7-segment
  sevseg.setNumber(score);
  sevseg.refreshDisplay();
  delay(50);
}

⚡ How It Works

  1. The IR sensor detects the basketball when it passes through the hoop.

  2. Each goal increases the score counter.

  3. The 7-segment display shows the current score.

  4. The LCD screen shows the game title and flashes “GOAL!” when a basket is made.

  5. The buzzer plays a beep sound each time a score is made.

  6. The Arduino reset button restarts the game and sets the score back to 0.





Comments

Popular Posts