We will learn about HC-SR04, widely known as an ultrasonic sensor, how it works, and how to interface with a NodeMCU. We will also learn how to measure the distance using HC-SR04.
Before building the circuit, let me explain what an HC-SR04 sensor is.
As the name indicates, ultrasonic sensors measure distance by using ultrasonic waves. But how?
The sensor head emits an ultrasonic wave and receives the wave reflected back from the target. Ultrasonic sensors measure the distance to the target by measuring the time between the emission and reception. So there ends the technical definition, I don't know how many of you understood.
Simply stated, an ultrasonic sensor is a device that can measure the distance of an object by using sound waves. It measures distance by sending out a sound wave at a specific frequency and waits for that sound wave to bounce back. By recording the time taken between the sound wave being generated and the sound wave bouncing back, it is possible to calculate the distance between the sensor and the object.
How It WorksHmm, well actually we have to figure out the distance because the sensor itself simply holds it's "ECHO" pin HIGH for a duration of time corresponding to the time it took to receive the reflection (echo) from a wave it sent.
- The module sends out a burst of sound waves, at the same time it applies voltage to the echo pin.
- The module receives the reflection back from the sound waves and removes voltage from the echo pin.
On the base of the distance a pulse is generated in the ultrasonic sensor to send the data to NodeMCU or any other micro-controller.
The starting pulse is about 10us and the PWM signal will be 150 us-25us on the base of the distance. If no obstacle is there, then a 38us pulse is generated for NodeMCU to confirm that there are not objects detected.
Before getting the reading of the HC-SR04 know about the calculation.
FormulaD = 1/2 × T × Cwhere D is the distance, T is the time between the Emission and Reception, and C is the sonic speed.(The value is multiplied by 1/2 because T is the time for go-and-return distance.)
Now connect the circuit as show in schematic.
Sending Data to the CloudWhen logging to the serial monitor, our data isn't that useful. Once in thingsai.io, we can graph and react to the data.
To set up thingsai.io account:
1. Visit https://thingsai.io.
2. Register using your Google account or email ID.
Login page:
3. After logging in, click on 'create new project' and give any name of your choice. In my case, it is 'Water Level Monitor.'
4. Now give the device a name. In my case, it's NodeMCU. You can select any name.
5. Now add the parameters. For example, since we are monitoring the humidity and temperature of our room, our parameters will be level (in decimal).
6. Now click on 'update device.'
For mode details or if you're facing the problem during creation of project, please watch demo video.
WiFi Setup1. Start the Phone WiFi and scan for AP name abcd.
2. Connect with this AP.
3. Now a web page opened, click on WiFi Configuration and type your hotspot SSID and password.
4. Now your node is connected to the network.
Note: If no any web page opened in browser then type 192.168.4.1 in your phone browser it will show the wifi configuration page.










Comments