03 - ESP8266 Ultrasonic Range Finder
03 - ESP8266 Ultrasonic Range Finder
Blynk App
Hardware Required
ESP8266 Wi-Fi module
UltraSonic HY-SRF05
Breadboard
Jumper wires
Contents
Connect the ESP8266 by following the circuit diagram provided in the resource.
Install the necessary libraries for the project, including the Blynk library.
Code the project using the ESP8266, including initializing the WiFi module. This
code should also include setting up the Blynk app to receive data from the
temperature sensor and send commands to the LEDs.
Upload the code to the ESP8266 board using a Micro USB cable.
Download the Blynk app on your mobile and create a new project.
Add 5 LEDs, each LED will display when the distance is within the given limit
and a gauge to display the distance parameter.
Link items to the ESP8266 onboard pins connected to the UltraSonic HY-SRF05
Connect the mobile phone to the same WiFi network as the ESP8266 module and
launch the Blynk application.
The temperature reading will now be displayed on the mobile phone and the LED
will be lit at the pre-set distance, along with the distance parameter displayed on
the Gauge.
1
Circuit
2
3
4
Blynk setup
Create blynk IoT account new version
- Create template
- Set leds
+ V0: integer, 0/1, id = 1
+ V1: integer, 0/1, id = 2
+ V2: integer, 0/1, id = 3
5
+ V3: integer, 0/1, id = 4
+ V4: integer, 0/1, id = 5
- Set Gauge: V5, integer, 0/500, id = 6
- Template settings: id, name and token
Code
#define TRIGGER D5
#define ECHO D6
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Serial.begin (9600);
Blynk.begin(auth, ssid, pass);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BUILTIN_LED, OUTPUT);
}
void loop() {
6
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);
digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration / 2) / 29.1;
7
Serial.print(distance);
Serial.println("Centimeter:");
Blynk.virtualWrite(V5, distance);
delay(200);
Blynk.run();
}
Demonstrations
8
9