Project tutorial
Basketball Hoop with Buzzer using an Arduino

Basketball Hoop with Buzzer using an Arduino © GPL3+

Create a child-friendly basketball hoop using either an Arduino Uno or an Arduino Nano.

  • 88 views
  • 1 comment
  • 1 respect

Components and supplies

51gzz5eu9pl. sx425
Ultrasonic Sensor - HC-SR04 (Generic)
The sensor component
×1
A000066 iso both
Arduino UNO & Genuino UNO
You can also use the Arduino Nano
×1
Adafruit industries ada1536 image
Buzzer
The sound component
×1
12002 04
Breadboard (generic)
Necessary for construction
×1
11026 02
Jumper wires (generic)
Necessary for construction
×1

Necessary tools and machines

5165950
Tape, Foam
Any type of tape will work
Basketball Hoop
Any bucket is fine
Circular Stuffed Animal/Ball
Any light ball that you know will not damage your HC-SRO4 sensor will work

Apps and online services

About this project

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.

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.

Step 2: Completing and Understanding the Hardware Schematics

Part1-Understanding the basic Breadboard design

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.

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

Part3:Sensor

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

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.

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.

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!!!

Code

CodeC/C++
Basketball Buzzer with Sensor
const int trig_pin = 12;
const int echo_pin = 11;
const int buzzer_pin = 6;
int distance_cm;
long duration;

void setup()
{
//Setting up the sensor
pinMode(trig_pin, OUTPUT);
pinMode(echo_pin, INPUT);
pinMode(buzzer_pin, OUTPUT);
}
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);
  }
}

Schematics

Schematics
Remember to use an Active Buzzer
Screenshot 2020 05 14 at 5 09 35 pm eye6hrmurw

Comments

Similar projects you might like

Buzzer Alarm System With Help Of Arduino

by ONYX

  • 70,702 views
  • 10 comments
  • 42 respects

Sigfox-Connected Basketball Hoop

Project tutorial by Sylvain Demortier

  • 4,426 views
  • 1 comment
  • 7 respects

Ultrasonic Security System

Project tutorial by Ivan

  • 52,856 views
  • 40 comments
  • 129 respects

Arduino Tutorial : Mini Piano

Project tutorial by the lonely programmer

  • 26,358 views
  • 7 comments
  • 37 respects

Arduino LCD Video Game

Project tutorial by xXarduino_11Xx

  • 6,406 views
  • 4 comments
  • 21 respects

Arduino Bluetooth Robot for Android Device

Project showcase by aip06

  • 5,278 views
  • 2 comments
  • 19 respects
Add projectSign up / Login