#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <version.h>
char auth[] = "authentication token";
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";
const int waterSens = A0
;int SensorValue;
BlynkTimer timer; // Announcing the timer
void myTimerEvent()
{
SensorValue = analogRead(A0);
Blynk.virtualWrite(V5, SensorValue);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, "SSID", "Password");
pinMode(waterSens,INPUT);
timer.setInterval(1000L,myTimerEvent);
int sensorValue = analogRead(waterSens);//read the sensor value
Serial.println(sensorValue);
if (sensorValue >= 500)
Serial.println("be careful");
Blynk.notify("be careful");//send notification
delay(1000);
}
void loop()
{
Blynk.run();
timer.run(); // running timer every second
}
This above is the code I am using to measure the water level sensor and push to the blynk app sadly I don’t have the code mcu (esp8266) and I need to make sure that this code works before I buy can someone help me …
When I complile it is perfect but don’t know if it work it would make my day if u can help
It will (or you’ll make some adjustments), but you’ll have to put all the code that is now in the loop into a function and call that with a timer. Aldo, you should grt rid of the delays… read what Pavel said…
It won’t execute because it’s not part of any function.
This isn’t a Blynk related thing, it’s basic C++, which is something you need to learn rather than asking for people to edit yourcode for you.
Your latest version (keep going back and editing your first post isn’t making this any easier to follow) will check your sensor once, at startup, then never again.
Yes, because it’s a proper function and is being called by a timer once every second.
By the way, there’s no point in defining the variable waterSens and assigning the value A0 to it if you don’t then use that variable when you’re doing the analogRead.
The same applied to your SSID and Wi-Fi password. You define variables to hold these, but use string literals in your Blynk.begin command instead.