Hi, folks.
I need build water level monitor for a well in my holiday home in the village. I have ESP8266-NodeMcu V3 with CH340 and four long wires for sensor where they are adjusted for water level in a well. I need the water level status show on the web by ip address given by router in the house. Can anybody help me for code please ? Thanks.
What code? You have not posted your latest attempt.
You can combine the code from the following tutorials:
- ESP8266 NodeMCU - Ultrasonic Sensor to measure the distance from the ultrasonic sensor to the water surfaces, then infer the water level
- ESP8266 NodeMCU - Web Server to print out the measured value to the web.
Please note that if you want to access the web page outside of your home network, you need to configure the port forwarding on your router.
Choose a Sensor for your Project .As IoT_hobbyist mentioned you can use Ultrasonic sensor. if the atmosphere you are using has high humidity or cause damage to sensor by water then go Water proof ultra sonic sensor. Always be aware of the surroundings that you wish to install the device and choose sensor which is suitable for your need.
What sensor (LINK)
Have you tried googling for similar projects?
I found this exactly as I need " https://youtu.be/Bd-fMyAdYAw " but this code is based on "HTTPClent", I need code for "WebServer" or some combination with code from the link and Web Server code.
Hi, that kind of ultrasonic sensor is expensive, I need code for (4-wires + 1-wire for common) where show levels (0%-25%-50%-75%-100%) via WebServer.
Do you have working code of the water levels
Hi, I found this code " https://www.hobbyprojects.com/projects/jsingh-projects/source-file/nodemcu_water_level_Monitor.ino " but I need for WebServer not for HTTPClient !
Do you have any code that only shows the water level not about any webserver type on displays the water levels in serial monitor
no I haven't
Have your ever checked the sensor. Does that give the output you desire
I will re check the sensor module later
So what you want is webserver .How would you like to display the webpage
Simple, 0% 25% 50% 75% 100%, nothing spectacular.
This is just bar displays the water levels as you wanted just assign the value to level
when each sensor is activated
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
ESP8266WebServer server(80);
String level="50";
const char *ssid = " SSID ";
const char *password = " PASSWORD ";
void setup() {
delay(1000);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
}
Serial.println("");
Serial.println(WiFi.localIP());
server.on("/", waterLevelMonitor);
server.begin();
}
void loop() {
server.handleClient();
}
void waterLevelMonitor() {
String html = "<!DOCTYPE html>";
html += "<html>";
html += "<head>";
html += "<style>";
html += ".water-level-bar {";
html += " width: 100%;";
html += " height: 50px;";
html += " background-color: #ddd;";
html += " position: relative;";
html += "}";
html += ".water-level {";
html += " height: 50px;";
html += " width: 100%;";
html += " position: absolute;";
html += " left: 0;";
html += " top: 0;";
html += "}";
html += ".level-0 {";
html += " background-color: red;";
html += " width: 0%;";
html += "}";
html += ".level-25 {";
html += " background-color: orange;";
html += " width: 25%;";
html += "}";
html += ".level-50 {";
html += " background-color: yellow;";
html += " width: 50%;";
html += " height: 100%;";
html += "}";
html += ".level-75 {";
html += " background-color: lightgreen;";
html += " width: 75%;";
html += "}";
html += ".level-100 {";
html += " background-color: green;";
html += " width: 100%;";
html += " height: 100%;";
html += "}";
html += "</style>";
html += "</head>";
html += "<body>";
html += "<h1>Water Level Monitor</h1>";
html += "<div class=\"water-level-bar\">";
html += " <div class=\"water-level level-0\"></div>";
html += "</div>";
html += "<script>";
html +="var waterLevel ="+level+";";
html += "var waterLevelBar = document.querySelector('.water-level');";
html += "waterLevelBar.classList.remove('level-0', 'level-25', 'level-50', 'level-75', 'level-100');";
html += "if (waterLevel == 0) {";
html += " waterLevelBar.classList.add('level-0');";
html += "} else if (waterLevel == 25) {";
html += " waterLevelBar.classList.add('level-25');";
html += "} else if (waterLevel == 50) {";
html += " waterLevelBar.classList.add('level-50');";
html += "} else if (waterLevel == 75) {";
html += " waterLevelBar.classList.add('level-75');";
html += "} else if (waterLevel == 100) {";
html += " waterLevelBar.classList.add('level-100');";
html += "}";
html += "</script>";
html += "</body>";
html += "</html>";
server.send(200, "text/html", html);
}
Its the code you provided it will provide output on serial monitor according to the water level/sensor activated
int sensor1 = D1;
int sensor2 = D2;
int sensor3 = D5;
int sensor4 = D6;
void setup() {
Serial.begin(9600);
// Serial.setDebugOutput(true);
pinMode(sensor1,INPUT_PULLUP);
pinMode(sensor2,INPUT_PULLUP);
pinMode(sensor3,INPUT_PULLUP);
pinMode(sensor4,INPUT_PULLUP);
}
void loop() {
// wait for WiFi connection
if (digitalRead(sensor4) == LOW)
{
// Level = "100";
Serial.println(" Level = 100");
}
else
if (digitalRead(sensor3) == LOW)
{
// Level = "75";
Serial.println(" Level = 75");
}
else
if (digitalRead(sensor2) == LOW)
{
// Level = "50";
Serial.println(" Level = 50");
}
else
if (digitalRead(sensor1) == LOW)
{
// Level = "25";
Serial.println(" Level = 25");
}
else
{
// Level = "00";
Serial.println(" Level = 00");
}
}