0% found this document useful (0 votes)
30 views9 pages

03 - ESP8266 Ultrasonic Range Finder

This document provides a guide for setting up an ESP8266 Wi-Fi module with an UltraSonic HY-SRF05 sensor using the Blynk app. It includes hardware requirements, circuit connections, code for the ESP8266, and steps to create a Blynk project to visualize distance measurements and control LEDs. The code initializes the Wi-Fi connection, reads distance data, and updates the Blynk app accordingly.

Uploaded by

vinlse181814
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views9 pages

03 - ESP8266 Ultrasonic Range Finder

This document provides a guide for setting up an ESP8266 Wi-Fi module with an UltraSonic HY-SRF05 sensor using the Blynk app. It includes hardware requirements, circuit connections, code for the ESP8266, and steps to create a Blynk project to visualize distance measurements and control LEDs. The code initializes the Wi-Fi connection, reads distance data, and updates the Blynk app accordingly.

Uploaded by

vinlse181814
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

ESP8266 - UltraSonic HY-SRF05 in

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

UltraSonic HY-SRF05 ESP8266


VCC VU
Trig D5
Echo D6
GND G

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

// NodeMCU Pin D1 > TRIGGER | Pin D2 > ECHO

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define BLYNK_TEMPLATE_ID "TMPL6wRKKYHWi"


#define BLYNK_TEMPLATE_NAME "IOT"
#define BLYNK_AUTH_TOKEN "T0pnitvLWWILdGgSpkXtSNWL3jVwBqb8"

// You should get Auth Token in the Blynk App.


// Go to the Project Settings (nut icon).
char auth[] = BLYNK_AUTH_TOKEN;

// Your WiFi credentials.


// Set password to "" for open networks.
char ssid[] = "FPTU_Student";
char pass[] = "12345678";
void setup() {

Serial.begin (9600);
Blynk.begin(auth, ssid, pass);
pinMode(TRIGGER, OUTPUT);
pinMode(ECHO, INPUT);
pinMode(BUILTIN_LED, OUTPUT);
}

void loop() {

long duration, distance;


digitalWrite(TRIGGER, LOW);
delayMicroseconds(2);

6
digitalWrite(TRIGGER, HIGH);
delayMicroseconds(10);

digitalWrite(TRIGGER, LOW);
duration = pulseIn(ECHO, HIGH);
distance = (duration / 2) / 29.1;

if (distance <= 50) {


Blynk.virtualWrite(V0, 255);
}
else {
Blynk.virtualWrite(V0, 0);
}

if (distance <= 40) {


Blynk.virtualWrite(V1, 255);
}
else {
Blynk.virtualWrite(V1, 0);
}

if (distance <= 30) {


Blynk.virtualWrite(V2, 255);
}
else {
Blynk.virtualWrite(V2, 0);
}

if (distance <= 20) {


Blynk.virtualWrite(V3, 255);
}
else {
Blynk.virtualWrite(V3, 0);
}

if (distance <= 10) {


Blynk.virtualWrite(V4, 255);
}
else {
Blynk.virtualWrite(V4, 0);
}

7
Serial.print(distance);
Serial.println("Centimeter:");
Blynk.virtualWrite(V5, distance);
delay(200);
Blynk.run();
}

Demonstrations

8
9

You might also like