Water level detector using esp8266

Hello everyone I am working on project using Arduino Uno , lcd 16*2, buzzer , water level sensor (not ultrasonic sensor ) . But I don't know how to connect esp8266 with the existing project to send an alert message .can anyone help me .
Thank you in advance
Here is the code
/ include the library code:
#include <LiquidCrystal.h>
//initialise the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int resval = 0; // holds the value
int respin = A5; // sensor pin used
int buzzer = 8;

void setup() {
pinMode(buzzer,OUTPUT);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);

// Print a message to the LCD.
lcd.print("WATER LEVEL: ");
}

void loop() {
// set the cursor to column 0, line 1
lcd.setCursor(0, 1);

resval = analogRead(respin); //Read data from analog pin and store it to resval variable

if (resval<=100){
lcd.println("Empty ");
digitalWrite(buzzer,LOW);
}
else if (resval>100 && resval<=300)
{
lcd.println("Low ");
digitalWrite(buzzer,LOW);

}

else if (resval>300 && resval<=330)
{
lcd.println("Medium ");
}
else if (resval>330){
lcd.println("High ");
digitalWrite(buzzer,HIGH);

}
delay(1000);
}

How about removing the UNO altogether from the project and just use the ESP8266 for all the tasks you mention. It's way more powerful than the UNO and it'll save you the hassle of having to setup a link between the ESP and the UNO, which is something many people seem to struggle with.
Follow one of the gazillion tutorials on how to connect an ESP over WiFi to a website or database. How do you want the alert to be sent?

Thankyou ... But I am using esp8266 esp01 wifi module not nodemcu. I want Alert message to be sent either on Gmail or as a simple sms to phone please guide .

I want to use this

I would suggest just using the ESP01 MCU in combination with the 16/2 LCD (equipped with an I2C Interface) and an external ADC (which also uses the I2C Protocol). Like that, you could get rid of the large and mostly unnecessary Arduino Uno and the external ADCs often have a much better resolution than the built-in ones. You might also use the ADC of the ESP01 but it only seems to have a limited working range.


LCD with I2C Interface


ADC 16Bit resolution

If you don't want to wait some more weeks for the new hardware to arrive, you can try to set up a serial communication between the Arduino and the ESP01 and program the ESP to send the received (and processed) data to an API / Server or directly to your Phone to show an alert etc.

True, but it's not really an issue in this case. Just use a resistor voltage divider to keep the voltage below 1.0V on the ADC pin. A 10k and 22k resistor would be close enough already.

SMS requires either an online SMS service which I'm not familiar with (but they exist, that's all I know), email requires setting up your ESP to send mail e.g. through SMTP. Assuming Google works where you live as well, you could find pages like this one: ESP32 Send Emails using SMTP Server: HTML, Text, Attachments (Arduino IDE) | Random Nerd Tutorials
What have you tried/found already and where did you get stuck & why?

Edit: about SMS, seems like e.g. IFTTT.com offers an sms service; see here: https://www.hackster.io/pawan-kumar3/send-text-messages-using-esp8266-01-with-dht11-sensor-data-2dc286
Again, just regurgitating the first seemingly relevant hit from Google...

Actually I am new to this field can you guide me how to set up serial communication between arduino and esp . It will be of great help

Again:

You'll never learn if somebody shows you the solution. Besides, I can only speak for myself, but I've got things to do; this is your project.

I am not able to connect my Arduino Uno with esp it's saying packet header not found

Yeah, so that's why I suggested to remove the Uno altogether. You're running into an unnecessary problem, like many have before you.

Btw, if you want help on particular errors, please post the full code used (in this case on both the Uno and the ESP) and the full error message you get.

Is my code logic correct?? Arduino code

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int resval = 0;
int respin = A0;
int buzzer = 8;

void setup() {
pinMode(buzzer,OUTPUT);

lcd.begin(16, 2);

lcd.print("WATER LEVEL: ");
}

void loop() {

resval = analogRead(respin);

if (resval<=100){
lcd.println("Empty ");
digitalWrite(buzzer,LOW);
}
else if (resval>100 && resval<=300)
{
lcd.println("Low ");
digitalWrite(buzzer,LOW);

}

else if (resval>300 && resval<=330)
{
lcd.println("Medium ");
}
else if (resval>330){
lcd.println("High ");
digitalWrite(buzzer,HIGH);

}
delay(1000);
}

Esp8266 01 code is it correct I haven't uploaded it .just want to verify

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include
<BlynkSimpleEsp8266.h>

const int respin= A0;
const int buzzer= 8;
const int resval= 0;

char auth = " ";
char ssid= " ";
char pass=" ";

void setup ()
{
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
pinMode(respin, INPUT);
digitalWrite(buzzer,LOW);
Blynk.begin(auth,ssid,pass);
}
void loop ()
{
Sendsensor();
Blynk.run();
timer.run();
}
void Sendsensor(){
resval= analogRead(respin);

if (resval <=100){

}
else if (resval >100 && resval <=30){

}
else if (resval >300 && resval <=330){

}
else if(resval > 330){
Blynk.email("______","ESP8266 ALERT"," Evacuate the region");
Blynk.notify("ESP8266 ALERT - water level high");
}
}

It's posted in an inconvenient format, that's for sure. Use code tags instead, please.

Your code doesn't attempt to link anything to an ESP in any case. So as such, it won't send text messages etc.

So upload it and see if it works.

Again, but this is the last time I'm going to say it: forget about the UNO and solve it with the ESP. It'll save you much trouble. In fact, I'm not going to waste any time trying to help you get the UNO to talk to the ESP. I'll leave that to others who are actually motivated to do so. I think it's futile and redundant exercise.

@renuyadav the Arduino code looks ok, but in the ESP01 code you try to acces the "respin" on the Arduino which is not directly working since you are dealing with two independant MCUs here. Instead, I suggest to use the Arduino as "Main MCU" which checks the water level with a sensor on the A0 pin and - in case - directly "tells" the ESP01 to send an alert message.

I sadly don't have the time to build and test the code for you, but here are some ideas you can try to implement on your own:

By using the Serial.println("BlahBlah"); function, you can send some text messages from the Arduino to another device. The transmitted data is available on USB and the RX / TX pins.
First of all, you could try to build a code that sends a message to the serial monitor of the Arduino IDE when the water level or whatever value reaches the critical niveau.
Then you can connect the ESP01 to the Arduino according to the following diagram (diagram source, I'm not sure if the ESP01's GPIOs are 5V tolerant!!)

The transmitted messages from the Arduino UNO can now reach ESP01. Now, the idea is to "open a serial monitor" on the ESP01 and "listen for new messages".
This can be achieved by putting this piece of code (I didn't test it on the ESP01)

if (Serial.available() > 0) { //if there is data available

    String data = Serial.readString(); //this will store the received data into a variable

    //here, you can add some code to process the received message / send it to the blynk app

}

into the ESP01's loop() section. There mustn't be any delay in loop() because "we have to check continuously if there is a new message". (An alternative solution would be the serialEvent(); function)
You will have to put the Serial.begin(9600); method somewhere in the setup() function of both the Arduino and the ESP01.
The number 9600 is the BAUD-Rate and has to be the same on the ESP01 and the Arduino since it is something like the "language" the devices use to communicate.

I hope, this will help you with your project!

I can somehow agree with koraks - if you really want to learn to code with Arduino etc. you should have a look at the "examples" section of the Arduino IDE and start with simpler projects.

Just google it - i'm sure there was somebody having the same problem uploading some code to an ESP01 before