Fun Project With HC-SRO4 Ultrasonic Sensor

by ElectronicSciTech in Circuits > Arduino

623 Views, 3 Favorites, 0 Comments

Fun Project With HC-SRO4 Ultrasonic Sensor

Setup.jpg

This is a Fun project, where you can play around with the HC-SRO4 Ultrasonic Sensor, if you are just getting started with the Ultrasonic Sensor.

At the end of this project, you will have interfaced your Arduino UNO with the HC-SRO4 Sensor. Additionally, it will also be interfaced with the LED, based on the distance.

Get Your Supplies!

uno v3.jpg
Ultrasonic Sensor.jpg
breadboard.jpg
male to female v3.jpg
male to male v3.jpg
led resistor.jpg

What you need for a working system:

  1. Arduino UNO along with USB Cable
  2. HC-SRO4 Ultrasonic Sensor
  3. Breadboard
  4. Male-to-male connecting wires
  5. Male-to-female connecting wires
  6. 3V LED
  7. 330 Ohm Resistor (4 bands Color code: Orange-Orange-Brown-Gold.)

Software used:

  1. Arduino IDE

Get Your Programming Done!

InterfacingUltrasonicSensor _ Arduino 1.8.13 18-03-2021 08_48_55.png
InterfacingUltrasonicSensor _ Arduino 1.8.13 18-03-2021 08_49_13.png
  • If you know Arduino Programming, then this step will be much easier for you and you can configure the code on your own also.
  • You can find the files for the code below and the image of the code above (Note that you have to download these files and open it on Arduino IDE. So before starting this project, you must have the Arduino IDE installed. For the installation, you can refer to youtube videos (or) to the Arduino official website (i.e. https://www.arduino.cc/) (or) if you are facing any issues, you can ask in the Comments and Questions section).
  • After this, insert the USB cable in the Arduino to your laptop/pc. You can use the image above or the file of the code below and upload your code.
  • Note that when you download the (.ino) file, you have to go to Arduino IDE and open the file. Arduino will ask you to create a folder and you can go ahead and create a folder and start using the (.ino) file.

Get Your Connections Done!

Sensor setup 2.jpg
Sensor setup.jpg
Breadboard setup.jpg
schematic.jpg
Setup.jpg
  1. Once the code is uploaded to your Arduino UNO, unplug the USB cable from your laptop/pc. Now we shall start the connections.
  2. Connect the VCC from the sensor to the 5V in the Arduino UNO in the Power section (using a male-to-female wire).
  3. Connect the GND from the sensor to any one GND in the Power section of the Arduino UNO.
  4. Connect the Echo pin from the sensor to the Digital Pin (DO) number 6.
  5. Connect the Trig pin from the sensor to the Digital Pin (DO) number 5.
  6. Connect the Digital Pin (DO) number 8 from the Arduino UNO to the +ve rail in the breadboard.
  7. Connect the other GND pin from the Arduino to the -ve rail in the breadboard.
  8. Connect the 3V LED and the 330 Ohm resistor in the breadboard as shown in the schematic and the picture.

Get Your Project Done!

Ultrasonic Sensor

Now, insert the USB cable connected to the Arduino in your laptop/pc , once the Connections are done.

Your Project is Done!

You can also configure the distance in the code.

You will see that if the distance of the object is less than 20cm, the LED lights up. Else it does not light up,

Thank you for viewing this Instructable. Please share it and feel free to post the photos of your prototype. If you have any issues pertaining to this project, let me know in the Comments and Questions Section.