Introduction: How to Monitor Ultrasonic Distance With ESP8266 and AskSensors IoT Cloud

About: IoT Maker, co-founder of asksensors.com

This instructable presents how to monitor the distance from an object using ultrasonic HC-SR04 sensor and ESP8266 node MCU connected to the AskSensors IoT cloud.

Step 1: Material We Need

We will need the following Hardware:

  • ESP8266 Node MCU
  • Ultrasonic HC-SR04 Sensor
  • Bread Board
  • Jumper wires
  • Micro USB cable

Step 2: Build Your Hardware

Connect the ultrasonic sensor to the ESP8266 node MCU:

  • HC-SR01 TRIG pin to ESP8266 D1 pin
  • HC-SR01 ECHO pin to ESP8266 D2 pin
  • HC-SR01 VCC pin to 5V (you can also try with 3.3V)
  • Ground to ground

Note:The ESP8266 GPIOs require 3V3 signals (not 5V tolerent). For quick hack, if you are using the HC-SR (5V version), we highly recommend to add a serial resistor between the HC-SR TRIG and ECHO pins and the ESP8266 pins. However, for production, a 3V3/5V level shifter is needed (check this page).

Otherwise, The ESP8266 is compatible with HC-SR 3V3 version and no level shifter is needed in this case.

Step 3: AskSensors Setup

Step 4: Download the Code

Download the code from the AskSensors github Page.

Decompress it and fill the following informations:

const char* wifi_ssid = "....................";             // SSID
const char* wifi_password = "....................";         // WIFI 
const char* apiKeyIn = "..................";      // API KEY IN

Step 5: Run the Code

Connect the ESP8266 to your computer and upload the code.

Now, Go to your AskSensors dashboard.

Open your sensor page and add a new graph to visualize your data stream in real time as shown in the enclosed figure.