Esp 32 won't send sensor values to Blynk App

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();
}

So what is the problem you face exactly?

1 Like

It just keep reading a maximum “100”
Seems like it never actually reads the values.

Try adding in some more serial print statements to see the readings before you map them.

Pete.

1 Like

Tried that, still won’t read the values.
It keeps reading “4095” before mapping, and “100” after mapping.

I think you need to use a different pin.

https://docs.espressif.com/projects/esp-idf/en/latest/api-reference/peripherals/adc.html

Try GPIO pins 32-39, that is the ones connected to ADC1, as ADC2 cannot be used when using wifi.

3 Likes

Tried this, worked like a charm!
Thanks a thousand.

2 Likes