กลับไปหน้ารวมไฟล์
basketball-hoop-with-buzzer-using-an-arduino-61f30a-en.md

Summary

Stuck at home with a little sports fanatic? This easy to build, Arduino-powered basketball hoop buzzer creates a fun, indoor basketball game. This project is also for beginners, so it is a nice first, second, or third project that you can build with kids.

Step 1: Gather the Materials

Here are the Arduino-related materials needed for this project -

  • Arduino Uno (You can also use an Arduino Nano or any other clone board of the Uno - I use an Elegoo Uno R3 for these tutorials)
  • HC-SRO4 Sensor (A common sensor that can be used for a variety of projects)
  • ACTIVE Buzzer (The output buzzer noise for this project. Make sure it is an ACTIVE Buzzer. Passive Buzzers make the 8 piano notes. Active Buzzers make the Buzzer noise.)
  • Any Breadboard
  • Some jumper wires (A lot of male-female and male-male, but maybe only 1-2 female-female)
  • Lastly, the Arduino IDE software on Mac, Linux or a Windows device.
Here are all of the Arduino-related things that are needed for this project.

And here is everything else that you need -

  • Some tape (Any type of tape is fine, but Duct tape, Flex tape, and any Heavy Duty tape will be way too big)
  • A bucket for a basketball hoop (Get creative! - just remember that there should be no hole in the bottom - it needs to be covered since that is where the HC-SRO4 Sensor goes.
  • A stuffed animal or a squishy ball that you know will not damage the sensor.
The rest of the stuff you need for the project

Step 2: Completing and Understanding the Hardware Schematics

Part1-Understanding the basic Breadboard design

The basic Breadboard design that is the beginning of almost any Arduino Project

How it looks like on my Elegoo Arduino (Note - Colors of wires don't matter)

The Breadboard contains regular pins and positive and negative currents on the sides. Due to the fact that the Arduino only has 1 5V pin, and since most medium to decently large-scale projects involve multiple devices that run on 5V, you can connect that 5V pin to the top of the positively charged row. This will make any pin attached to the positively charged row receive 5V of power. Do the same with GRND and the negatively charged row. Although we only have one device that runs on 5V in this experiment, it is good practice now while you are practicing beginner projects, so the transition will not be as hard.

Part2:BuzzerSetup

The next step is to add a buzzer. One side goes to the Digital pin 6 (or anywhere else- just remember to change the code as well), and the other has a jumper wire going through to the negatively charged row (GRND). Pretty self-explanatory, right? The next step is where it gets tricky.

Buzzer Schematic

As you can see, assembling the buzzer part of this project is simple.

Part3:Sensor

Final product

Here's how it looks like

If the images are not clear, here is the breakdown.

VCC --> 5V power (positively charged row)

Trig pin --> Digital Pin 12

Echo pin --> Digital Pin 11

GRND --> GRND (Negatively charged row)

Sounds easy, right - but wait! There's one catch -- The wires for the sensor need to be composed of at least three smaller wires connected since the sensor has to be reached and taped at the bottom of the basketball hoop.

Good job! You have officially finished the hardware portion of this project. Now on to the code portion.

Step 3: The Code

I will have a step-by-step guide and instructions about the code below. But first, copy and paste the code into Arduino IDE.

const int trig_pin = 12;
const int echo_pin = 11;
const int buzzer_pin = 6;
int distance_cm;
long duration;

Here, we are defining the variables. Remember the digital pins? Here we are saying that the trig pin is on 12, the echo pin is on 11, and the buzzer pin is on 6. We are measuring the distance with the sensor in centimeters, and its duration is labeled as "long".

void setup()
{
//Setting up the sensor
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
}

Here we are setting up the sensor. To be more descriptive, we are setting the trigger pin (the pin that outputs the signal that something is detected) as output and the echo pin (the detecting pin) as input. This is necessary for almost any project with the sensor.

void loop()
{
//Sensor detecting movement
digitalWrite(trig_pin, LOW);
delayMicroseconds(2);
digitalWrite(trig_pin, HIGH);
delayMicroseconds(10);
digitalWrite(trig_pin, LOW);
duration = pulseIn(echo_pin, HIGH);
distance_cm = (duration*0.034)/2.0;
//If the movement is far away, do not turn the buzzer on
if (distance_cm >= 10 || distance_cm <= 0)
{
digitalWrite(buzzer_pin, LOW);
}
//Otherwise, turn the buzzer on
else
{
digitalWrite(buzzer_pin, HIGH);
}
}

The first few lines, labeled, "Sensor detecting movement" are setting up how the sensor detects motion.

The if statement says that if the movement is far away, do not turn the buzzer on (As mentioned). However, the "else" part means that if it is close by, the buzzer should be on.

And that's the code! Now on to installation! :)

Step 4: Installation

Things required for installation - Project, tape, some sort of scoring hoop or box, and an energy supply

OK, now lets physically install it. The project may not look like much, but with a bit of creativity and maybe some crafts, you can create an amazing creation to enjoy.

Tape the Sensor Down

The only real step in this process is to tape the Sensor down onto the bottom of the bin. Make sure the wires are straight, and tape those down as well.

Ta-da!!!

Plug it into your power supply, and then get shooting. Remember to use a very soft squishy ball or some sort of balloon, because if you use anything too heavy, your sensor could be damaged.

Here is the video of the project (Note - Arduino Nano shown in the video, but the project is easiest with an Arduino Uno)

Here is the video. DO NOT use a real basketball. Use a balloon or a soft ball if you don't want to crush the sensor.

Interested in this project? Here are my other projects - https://create.arduino.cc/projecthub/ShreyanR/lego-gun-shooter-with-an-arduino-uno-d9028a?ref=user&ref_id=1536504&offset=0

https://create.arduino.cc/projecthub/ShreyanR/soundbox-826a56

More projects coming soon!!!

EXPANDED TECHNICAL DETAILS

Scoring Mechanism

This project turns a standard basketball hoop into an interactive training tool.

  • Detection Sensor: Typically uses an Infrared (IR) Break Beam sensor or an Ultrasonic sensor mounted at the rim. When the ball passes through, the beam is broken or the distance measurement drops significantly, triggering a score.
  • Hardware Integration: The Arduino monitors the sensor state in high-speed loops. Upon a successful "basket," it triggers a sequence of light and sound.

Audio-Visual Feedback

  • Buzzer Alerts: A Piezo Buzzer is used to play a "win" melody or a celebratory beep. Different sound patterns can be programmed for various scoring streaks.
  • Visuals: A simple 4-digit 7-segment display or an LCD keeps track of the score. To prevent multiple counts for a single basket, the code implements a "lockout" timer (e.g., 500ms) after a score is detected before it can count again.

ข้อมูล Frontmatter ดั้งเดิม

title: "Basketball Hoop with Buzzer using an Arduino"
description: "Create a child-friendly basketball hoop using either an Arduino Uno or an Arduino Nano."
author: "adityan76"
category: ""
tags:
  - "audio"
  - "entertainment system"
  - "kids"
views: 7699
likes: 3
price: 870
difficulty: "Easy"
components:
  - "1x Tape, Foam"
  - "1x Buzzer"
  - "1x Arduino UNO"
  - "1x Jumper wires (generic)"
  - "1x Circular Stuffed Animal/Ball"
  - "1x Basketball Hoop"
  - "1x Ultrasonic Sensor - HC-SR04 (Generic)"
  - "1x Breadboard (generic)"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "d6ce4d491ce2a0dc44194a771867cd51482908decf0cf77418039495d266fad5"
encryptedPayload: "U2FsdGVkX1/drPF7OGIe1pIg9NNp0y08Y/64cqj8zgLsVsoRQd/T3xaK9Ay+/MnuuGm9ZOgnxY+tpTmHMWaAFSfXb0ddZ2dyYm374WjO8QE="
seoDescription: "Build a DIY child-friendly Basketball Hoop with a Buzzer using Arduino Uno or Arduino Nano. Perfect for beginner makers and kids."
videoLinks:
  - "https://www.youtube.com/embed/2Ue55uNW_zY"
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/basketball-hoop-with-buzzer-using-an-arduino-61f30a_cover.jpg"
lang: "en"