Hey friends, I’m here with another interesting article on IoT. In this blog, we are discussing the making of the Blynk water level indicator which we made using esp8266 nodemcu. For finding the level of the water in a container we are using an ultrasonic sensor. Also, we are going to display and alert also control the pump using Blynk App. For more details regarding the project please visit our website.
Working of the projectThe ultrasonic sensor works on the principle of reflection of ultrasonic sound. Place the sensor on the top of the container so that it can sense correctly and completely. The messages are going to display on a 16x2 LCD display that is connected with the nodemcu via theI2C module. The code and circuit both are given below.
Material Required:- NodeMCU (ESP8266 MOD)
- 16×2 LCD with I2C module
- Relay module
- DC pump
- Ultrasonic sensor (HC-SR04)
- 12v power supply
NOTE: Please upload this code to the nodemcu.
//TECHATRONIC.COM
// ESP8266 LIBRARY
// https://github.com/ekstrand/ESP8266wifi
#include <LiquidCrystal_T2C.h>
#include <Wire.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
char auth[] = "your-auth-code";//Enter your Auth token
char ssid[] = "your-wifi-ssid";//Enter your WIFI name
char pass[] = "your-wifi-password";//Enter your WIFI password
BlynkTimer timer;
bool pinValue = 0;
#define trig D3
#define echo D4
#define relay D5
void setup() {
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
pinMode(relay, OUTPUT);
Wire.begin(D2, D1);
lcd.init();
lcd.backlight();
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(10L, Wlevel);
digitalWrite(relay, HIGH);
}
BLYNK_WRITE(V0) {
pinValue = param.asInt();
}
void loop() {
Blynk.run();
timer.run();
}
void Wlevel() {
if (pinValue == 1) {
digitalWrite(relay, LOW);
lcd.setCursor(0, 1);
lcd.print("Motor is ON ");
} else if (pinValue == 0) {
digitalWrite(relay, HIGH);
lcd.setCursor(0, 1);
lcd.print("Motor is OFF");
}
digitalWrite(trig, LOW);
delayMicroseconds(4);
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);
long t = pulseIn(echo, HIGH);
long cm = t / 29 / 2;
Blynk.virtualWrite(V1, cm);
Serial.println(cm);
lcd.setCursor(0, 0);
lcd.print("Water Level: ");
lcd.print(cm);
lcd.print(" ");
}
Setup the Blynk App:Install Blynk App from your preferred App Store and login into app using your social accounts. After login, you’ll reach the main screen.
Create a new project using any preferred name. Here I have used ‘Water Level Indicator’.
Auth token will be sent to the registered email-id used at the time of login. Put that auth code into the code mentioned above.
This is how the main project screen looks like. Now you are good to import widgets on the screen.
Import widgets as reference from above images and then the main screen will look like this.
Change setting of each widget as shown above and try to make it like the image below after all things done
Now plug in power-supply to NodeMCU and wait for the display to update information in both LCD and Blynk App.
We hope that you like this project and if so then also check out our tutorials on Arduino.
HAPPY LEARNING!
Comments
Please log in or sign up to comment.