How to Use an Ultrasonic Sensor With Arduino

by baileyvp in Circuits > Arduino

136 Views, 0 Favorites, 0 Comments

How to Use an Ultrasonic Sensor With Arduino

cover image.jpg

This tutorial is to show you how to code for an ultrasonic sensor and arduino.

Supplies

Arduino

4 jumper wires

breadboard

ultrasonic sensor

Screen Shot 2021-11-09 at 2.20.10 PM.png

in arduino, this is the coding you are going to use.

Now, on to hooking up the arduino.

First, let's start with the ultrasonic sensor. I hooked mine up on the breadboard at j 1, 2, 3, and 4.

Next, we are going to hook up the breadboard to the arduino.

The red jumper goes from 5V on the arduino to VCC on the sensor. This puts it at F4 on the breadboard.

The black jumper goes from gnd to gnd on the arduino and the sensor, which is F1 on the breadboard.

1.jpg
2.jpg
3.jpg
4.jpg

Next are the rest of the jumpers.

I put the green jumper going from 8 to the trig pin on the sensor, so F3.

The yellow jumper goes from 7 to the echo pin on the sensor, so F2.

These two wires correspond with the input and output in your coding:

"const int trigPin = 8;

const int echoPin = 7;"

Finally, you are all set to upload your coding and connect your arduino.

Once you have uploaded in arduino, go to "Tools" and then "Serial Monitor" to play around with the ultrasonic sensor's distance readings.