Hello!
I have been trying to work on a home automation project using Blynk. However, it seems I have been unable to properly read sensor values to be sent to the Blynk app.
Here the code Iβve been using to read a moisture sensor
//HERE THE LIBRARIES ARE INCLUDED
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
//HERE THE BLYNK AUTHENTICATION TOKEN IS ADDED
char auth[] = "90ca360db7a********************";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "*****";
char pass[] = "*************";
//DEFINE BLYNK TIMER
BlynkTimer timer;
//DECLARATION OF VARIABLES
#define sensor 26
int value;
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000, sendvalue);
pinMode(sensor, INPUT);
}
void sendvalue(){
value = analogRead(sensor);
value = map(value, 1, 4095, 1, 100);
Blynk.virtualWrite(V5, value);
Serial.println(value);
}
void loop()
{
Blynk.run();
timer.run();
}