How to Use Ultrasonic Sensor With Arduino Nano
by STEAM-DIY in Circuits > Arduino
144 Views, 0 Favorites, 0 Comments
How to Use Ultrasonic Sensor With Arduino Nano
Welcome back to my blog. We have described INPUT and OUTPUT in previous posts. We will create projects using this knowledge. Ok, let’s go to today’s post. Today we are going to talk about how to connect an ultrasonic sensor to an Arduino board. So it is a very useful sensor for making robots. This sensor can be easily connected to an Arduino board.
Supplies
What is the ultrasonic sensor?
The main process of this sensor is to calculate the distance to an obstacle. The sensor emits a wave and calculates the distance by the time it takes to reflect in the face of an obstacle. For example, the reader system and the bats used this method. This ultrasonic sensor includes two knobs. One knob emits a pulse and the other knob detects the pulse. This sensor cannot be used for long distances. The maximum value is 25-30 cm. I am not satisfied with the values beyond that. It is more suitable for short distances. If you need long-distance sensors, there are various sensors available in the market. Waterproof sensors are also available in the market. Below is how the ultrasonic sensor works with the Arduino board.
Step 1
let’s do this project step by step. The required components are given below.
- Arduino Nano board
- Ultrasonic sensor
- Breadboard
- Jumper Wire
Firstly, identify these components.
Arduino Nano board
The Arduino Nano board is a very low-cost board. That is why I have used this board. You can use any other Arduino board for this project.
Ultrasonic sensor
This component has been described above.
Breadboard
This is used for the easy mounting of the component.
Jumper wires
I have used four male-to-male upper wires.
USB cable
It is used to connect the Arduino board to the computer.
Secondly, connect the ultrasonic sensor and the Arduino board to the breadboard.
Thirdly, connect the ultrasonic sensor to the Arduino board using the jumper wire. For that, see the circuit diagram below.
Connect the TRIG pin of the ultrasonic sensor to the D2 pin and the ECHO pin to the D4 pin. The GND pin connects to the GND pin and the VCC pin connects to the VIN or 5v pin.
Now, copy and paste the following program to the Arduino IDE.
https://youtube.com/@steam-diy?si=XOvJ1l3gY9-QSK6G (get the code from the link )
- The complete program of this project
Let’s look at this code one by one.
This code informs the Arduino board that pin D2 is the output pin and pin D4 is the input pin. Also, the serial monitor is activated.
This code prints the values to the serial monitor.
Next, select the board and port. After, click the upload button.
Now, open the serial monitor. Then you can see the ultrasonic readings.
OK, enjoy this project. The full video guide is below. So, we hope to see you in the next project or tutorial. Have a good day.