Skip to main content

Basketball enthusiasts and makers, have you ever wished for a way to automatically keep track of your hoops right in your backyard? Whether you’re honing your skills or enjoying a friendly match, our guide to creating a basketball counter using a laser sensor and an Arduino is here to elevate your game. This project combines the thrill of basketball with the satisfaction of DIY electronics, making it a perfect weekend endeavor for sports fans and tech enthusiasts alike.

What You’ll Need

Before we bounce into the building process, let’s ensure we have all the necessary components:

  • Arduino Uno (or any other compatible Arduino board)
  • Laser diode
  • Photodiode or a light-dependent resistor (LDR)
  • Buzzer or LED (for scoring indication)
  • Resistors (220 ohms for the LED and 10K ohms for the LDR)
  • Breadboard and jumper wires
  • USB cable to connect Arduino to your computer
  • Basketball hoop (of course!)
  • Computer with Arduino IDE installed

Setting the Stage

Our setup involves positioning the laser diode on one side of the basketball rim and the photodiode or LDR on the opposite side. When the basketball passes through the hoop, it interrupts the laser beam, triggering a count on the Arduino.

Step 1: Circuit Assembly

  1. Connect the laser diode to one of the digital pins on the Arduino (for example, pin 2) for control. Remember to use a resistor if your laser diode requires current limiting.
  2. Place the LDR or photodiode across the hoop, aligning it with the laser diode. Connect one end to another digital pin (say, pin 3) and the other end to the ground. Place a 10K ohm resistor between pin 3 and 5V to create a voltage divider, which helps in detecting the laser’s interruption accurately.
  3. Add a buzzer or LED to signal a successful score. Connect the buzzer or LED’s positive end to pin 4 and the negative end to the ground through a 220-ohm resistor.

Step 2: Programming the Arduino

Now, let’s dive into the code that will bring our basketball counter to life.

// Define pin numbers
const int laserPin = 2;
const int sensorPin = 3;
const int buzzerPin = 4;

// Variables to keep the score
int score = 0;
bool beamBroken = false;

void setup() {
  pinMode(laserPin, OUTPUT);
  pinMode(sensorPin, INPUT);
  pinMode(buzzerPin, OUTPUT);

  // Start the serial communication
  Serial.begin(9600);

  // Turn on the laser
  digitalWrite(laserPin, HIGH);
}

void loop() {
  // Check if the beam is broken
  if (digitalRead(sensorPin) == LOW) {
    if (!beamBroken) {
      score++;
      Serial.print("Score: ");
      Serial.println(score);
      // Signal a score
      digitalWrite(buzzerPin, HIGH);
      delay(100); // Adjust for buzzer or LED duration
      digitalWrite(buzzerPin, LOW);
      beamBroken = true;
    }
  } else {
    beamBroken = false;
  }
}

This code continuously checks for interruptions in the laser beam. When the beam is broken, it increments the score, outputs the score to the Serial Monitor, and activates the buzzer or LED to signal a score.

Step 3: Testing and Calibration

After uploading the code to your Arduino, it’s time for the fun part—testing! Position the laser and sensor carefully to ensure the basketball will reliably interrupt the beam when passing through the hoop. You may need to adjust the positioning for optimal performance.

Leave a Reply