Distance Measurement Using Nodemcu and HC-SR04
Hi Creative people are you looking for Distance Measurement Using Nodemcu and HC-SR04 then you are at the right place.
In this project, we are making a scale or short-range sensing device using Nodemcu and an ultrasonic sensor.
HC-SR04 or in other words distance sensor is the component that plays main role in our project.
To begin with, let us go through some of the pre-requits of this project.
What is Distance measurement?
This is a very basic question that most of us hear or few already know about this.
It’s nothing but the distance between 2 objects.
It’s very useful when we have a need to find out the distance to do some calculations.
For example, if you want to buy a table for your bedroom you should be aware of space availability.
By measuring the distance in advance you can plan for the size of the table that fits best.
Why Use Nodemcu to measure the distance?
With the improving technology everybody like to stay ahead of others.
Nobody likes the very old way of distance measuring, like the most widely used using scale!
How cool is it to measure the distance and not have the need to read the values manually?
Sounds interesting right? Yes, it is! we will make a project as we spoke about above.
How to measure distance using Nodemcu
Nodemcu is one of the popular microcontrollers that has great features.
Pocket-friendly board that has built-in wifi to build cool projects.
We are not using Wi-Fi here at the moment.
But in the future, we can convert this project into an IoT project, More on this later.
The logic behind the Range Sensor or Ultrasonic Sensor
Nodemcu is combined with the ultrasonic sensor in our project.
As we know HC-SR04 boards can measure range as they emit ultrasonic waves.
To begin with we need some of the electrical components that are available in most hobby electronics shops.
If not there is always online shopping that comes in handy
Note: I have added working video of this project, Dont miss to check it out at the end.
Materials Necessary to Build this Project
- Nodemcu or ESP8266
- Ultrasonic sensor or HC-SR04 module
- OLED display
- Breadboard mini or normal size
- Jumper wires
- Arduino IDE and Programming Cable
Distance Measurement Using Nodemcu and HC-SR04 Circuit Diagram
Below is the circuitry that we use to build this project.
If you are familiar with electronics then this circuit is very easy to understand.
If you are still a newbie i have given a written explanation below.
Just you can make this circuit by reading that explaination.
Circuit Diagram Explanation
To make it easier we will divide the circuit connection into 3 parts.
1)Ultrasonic Sensor
Vcc to Breadboard positive power rail
Gnd to Negative rail of the breadboard
Trig to D6 pin on Nodemcu Board
Echo to D5 Pin on Nodemcu Board
2)OLED Display
Scl to D2
Sda to D1
Vcc To positive breadboard rail
Gnd to Breadboard negative rail
3)Nodemcu connections
Vcc from board to the positive rail
Gnd to Negative power rail
After completing the circuit, the project will look something like this.
This directly says that our project is almost complete.
The only thing that is left is to upload the Arduino Code.
Ultrasonic Sensor Distance Measurement Arduino Code
You can check Arduino Codes for this Project
Just open this code and paste it into Arduino IDE.
If this is your first time connecting an OLED display to your Arduino IDE then you need to add 2 additional libraries.
You can get Adafruit GFX and Adafruit SSD1306 libraries by hitting the respective words.
Once you have these libraries add to your Arduino Library
You can do this by clicking on Sketch->Include Library->Add.zip library option.
Click on the file that you just bought in and click ok.
Do the same for another library too.
Now select the type of board by clicking on Tools->Board and ESP8266.
Now click on Upload and wait for upload completion.
After you upload the code your OLED display will show numbers like this.
These numbers are the values or ranges.
In other words distance between the ultrasonic sensor and the object that comes in front of it
How to use Nodemcu Powered Distance Measuring Meter
- This is a plug-and-play type of device.
- Just plug in to any USB-powered source.
- OLED will start to show numbers.
- Now bring the sensor in front of the object where the distance needs to be measured.
- Hold it still until the numbers are stable on OLED.
- These are the values in cms.
- You can also cross-check these values using a normal scale/ruler.
Working video of Distance Measurement Using Nodemcu and HC-SR04
You can check the video on how to use this distance-measuring device here
Don’t miss to check our previous post on making a Wi-Fi Rover Controlled by Smartphone
Amazing PCBWAY Circuit Boards You should try
PCB WAY is well known for offering high-quality Printed circuit boards at a very budget friendly price to build many interesting electronics projects.
PCBWay is offering FR-4 & Aluminum boards in addition to advanced PCBs like Flexible & Rigid-Flex boards, HDI, and Rogers at a very reasonable price.
More info is given below.
They are running the 5th Creators Competition.
Want to win a Raspberry Pi pico? Click here
We are pleased to inform that we have a Technical cooperation with kicad and FreeCAD.
Check the details for freecad and Kicad.
Thank you for reading this article about Distance Measurement Using Nodemcu and HC-SR04 check our other amazing project too.