BLYNK
BLYNK.IO       📲 GETTING STARTED       📗 DOCS       👉 SKETCH BUILDER

Thermistor, Photoresistor and Blynk not working

Thermistor, Photoresistor and Blynk not working
Hello. I’m trying to use a Thermistor to read the temperature and send it to the Blynk app. Also, I’m trying to use a Photoresistor to turn on some lights. Below is the code So far. The bord that I’m using is a ESP32. If I comment out the BlynkEdgent.begin(); and the BlynkEdgent.run(); the code works fine and I can see the 2 values in the serial monitor but if I uncomment them I get in the serial monitor a 0 value for the Photoresistor and a -268.1 for the Thermistor.
Can anybody tell me what I’m doing wrong?

#define BLYNK_TEMPLATE_ID "TMPLy1vivXtZ"
#define BLYNK_DEVICE_NAME "Curte"
#define BLYNK_FIRMWARE_VERSION        "0.1.0"
#define BLYNK_PRINT Serial
#define APP_DEBUG
#include "BlynkEdgent.h"

#define Sensor_Lumina 15
#define Reflectoare 2


const double VCC = 3.3;
const double R1 = 9850;            // 10k ohm series resistor
const double adc_resolution = 4096;
const double A = 0.001129148;
const double B = 0.000234125;
const double C = 0.0000000876741;

BLYNK_WRITE(V0)
{
  int ReflectoareV = param.asInt();
 // digitalWrite(Reflectoare,ReflectoareV);
}

void setup()
{
  Serial.begin(115200);
  BlynkEdgent.begin();

  pinMode(Sensor_Lumina,OUTPUT);
  pinMode(Reflectoare,OUTPUT);
  digitalWrite(Reflectoare,LOW);

  delay(100);
}

void loop() {
  BlynkEdgent.run();

  int Nivel_Lumina = analogRead(Sensor_Lumina);
  Serial.println(Nivel_Lumina);
 
  if (Nivel_Lumina < 1) {
   digitalWrite(Reflectoare,HIGH); 
  } else{
    digitalWrite(Reflectoare,LOW);
  }

  double Vout1, Rth1, TempOut1, TempIn1; 
  TempIn1 = analogRead(4);
  Vout1 = (TempIn1 * VCC) / adc_resolution;
  Rth1 = (VCC * R1 / Vout1)- R1;
  TempOut1 = (1 / (A + (B * log(Rth1)) + (C * pow((log(Rth1)),3))));   // Temperature in kelvin
  TempOut1 = TempOut1 - 273.15;  // Temperature in degree celsius
  Serial.print("Temperature = ");
  Serial.print(TempOut1+5,1);
  Serial.println("°C");

  delay(500);
}

Please edit your post and add triple backticks ``` before and after your whole sketch.

Sorry I did not know I can do that. Thanks for the info.

You should read this
https://docs.blynk.io/en/legacy-platform/legacy-articles/keep-your-void-loop-clean

GPIO15 is attached to ADC2 on the ESP32.
The ADC2 analog inputs cannot be used at the same time as WiFi.

As your Blynk connection is via WiFi, you need to use an ADC1 pin.

You should read this…

Pete.

Thank you for the advice. I changed the pins and now it works.

1 Like