Blynk with HC-SR04 | NodeMCU IoT

Hey Folks, we’re back with another interesting article, Blynk with HC-SR04 based on IoT. HC-SR04 is one of the basic sensors, it can be interfaced very easily with almost every development board out there. We have demonstrated its interfacing with many development boards, links to which are provided below. Today we’ll demonstrate its interfacing with NodeMCU and try to display its value on the Blynk App just in the case of Ir Sensor. For an introductory article and more description about the HC-SR04 and NodeMCU head over to their respective articles. So, without wasting any time, let’s start today’s discussion.

HC- SR04 and NodeMCU in brief

HC-SR04

HC-SR04 is one of the best sensors for measuring distance, however, it comes with certain limitations. Besides this, it is cheap and easily affordable, and programmable with different boards. Moreover, if you want to read about HC-SR04 in detail, then here is the link to the article, you can read about its building in detail there. HC-SR04 is quite popular as it can measure distance up to some accuracy despite its flaws. This sensor has 4 pins, two power pins, and two communication pins. There is also another model that comes with 3 pins, two power pins, and a ping pin, in this only a single pin is used for communication.

This sensor is built out of two MAX232 driver ICs for driving the ultrasonic transducers. Paired with an LM324 Op-Amp for amplifying the incoming signal. All these processes are controlled by an 8-bit Microprocessor, EM78P153. The circuit is quite hard to replicate in the same compact size. However, if you like to replicate it, the schematic and other details are mentioned in the article on HC-SR04. On the other hand, if the sensor gets damaged, there is negligible scope for repair. As the components are mostly SMD and are hard to repair for beginners.

NodeMCU

NodeMCU is one of the most popular development boards among beginners. Due to its compact size and support, for easy to program interface like Arduino IDE. Besides, this comes with some rather powerful specs and features that can make a huge difference from other development boards at the same price. This board is manufactured by Espressif Systems, and along with this they also manufactured many other boards. ESP8266 aka NodeMCU packs with a Tensilica Xtensa LX106 32-bit RISC Microprocessor that is capable of running RTOS. Moreover, it can operate on a variable frequency of about 80MHz-160MHz. Regardless of these high-performance specs, it comes in a rather small size that is comparable to the size of your thumb.

In addition to this, it comes with 128 KB of SRAM that is capable of running some nice powerful lines of code. Moreover, it is paired with 4 MB of SPI FLASH ROM Storage, this is quite a handful for most of the projects. In addition to this, it also comes with an 802.11b/g/n Wi-Fi Transceiver. However, it doesn’t support Bluetooth like its other version, which does. Now comes the main thing, the pins. NodeMCU has enough pins for normal use, but for tasks like using analog sensors in a bunch, it creates a problem as there are not enough analog pins on it. Overall, if we see this board is most suitable for beginner use, due to its low cost and better features it is highly recommended.

Material Required

Listed are some of the materials that are required for the demonstration of the interfacing Blynk with the HC-SR04 sensor. All the components are easily available either in the local or online market.

  • NodeMCU
  • HC-SR04
  • Jumper Wires
  • Breadboard
  • Object for detection
  • Blynk Interface for display of status.

Fritzing Schematic

Wiring

HC-SR04 PinNodeMCU
VccVIN
TRIGD1/GPIO5
ECHOD2/GPIO4
GNDGND

Designing Blynk Interface

For designing the blynk interface for Blynk with HC-SR04, we’ll be using the same template and device as that of the IR Sensor with Blynk. I have explained all the steps in detail in the that article. Make sure to read that to understand it well. Moreover, I have marked the section specifically for designing templates and devices. Also for web dashboard and mobile dashboard. Do remember that you’ll be needed an account on the blynk server to do this. So make sure either you make one or if you have one then you must be logged in.

Web Dashboard

For designing a Web Dashboard, make sure to follow the steps mentioned below. To make it easy, I have made them in bullet points.

  1. First login to your account and wait until the home page opens. The home page will be your dashboard home window, from there open the template section to modify it.
  2. Next, head over to the Datastreams tab to either modify it from the previous demonstration or create a new one like this one. Once you have modified the datastream you can now move to the web dashboard to modify it.
  3. Click on the Web Dashboard tab and then click on edit, if you have previously made something on it. Otherwise, create a new widget according to the steps mentioned in IR Sensor with Blynk.
  4. Select the widget and click on the gear icon to modify it. Below is the reference image of the settings of the widget. Change all the settings that are not crucial according to your choice.
  5. However, keep in mind that the device and template both are same also same for the data stream. With this done, we are good to proceed to the next part.