Blynk app isn't displaying sensor values

Hello, I was designing a temperature sensor to display 4 temperature readings on Blynk app but the output always shows 0. When I remove the blynk part it shows proper readings but after adding the blynk part it starts showing 0 in both blynk app and in serial monitor.

Serial monitor readings:

Invalid voltage reading for V_NTC1
Raw Master reading: 0
Raw Slave reading: 0
Master Voltage: 0.00
Master Temperature: 0.00
Slave Voltage: 0.00
Slave Temperature: 0.00
Raw Coolant_IN reading: 0
Raw Coolant_OUT reading: 0
V_NTC1: 0.00
V_NTC2: 0.00

This shows with blynk code.

When I remove the blynk part from the code it shows proper data

The code

#include <U8g2lib.h>
#include <Wire.h>

U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE, /*SCL=*/22, /*SDA=*/21);

#define BLYNK_TEMPLATE_ID "TMPL3LavZCULb"
#define BLYNK_TEMPLATE_NAME "Greaves Temperature Sensor"

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

// Blynk authentication token
char auth[] = "Jqr5zbODmKfx1asQdCWRtfM1OyENsnDN";

// WiFi credentials
char ssid[] = "No Internet";
char pass[] = "1335555777777";

// Analog pins for temperature sensors
int Coolant_IN = 25;
int Coolant_OUT = 26;
int Master = 27;
int Slave = 13;

const float NTCR_fixed = 560;       // Fixed resistor value in ohms (adjust as needed)
const float NTCR01 = 1526;          // NTC resistance at T0_ref
const float NTCbeta = 8000;         // Beta value for NTC thermistor
const float NTC_T0_ref = 29.0 + 273.15;  // Reference temperature in Kelvin (29°C)

BlynkTimer timer;
unsigned long lastMillis = millis();

void setup() {

  Serial.begin(115200);
  
  u8g2.begin();

  WiFi.begin(ssid, pass);
  Blynk.begin(auth, ssid, pass);

  pinMode(Coolant_IN, INPUT);
  pinMode(Coolant_OUT, INPUT);
  pinMode(Master, INPUT);
  pinMode(Slave, INPUT);

  // Set a timer to run the displayReadings function every second
  timer.setInterval(1000L, displayReadings);
}

void loop() {
  Blynk.run();
  timer.run();  // Run the timer
}

void displayReadings() {
  u8g2.clearBuffer();  // Clear the display buffer
  u8g2.setFont(u8g2_font_7x14_tr);  // Choose a suitable font

  readThermocouple();
  readNTC();

  u8g2.sendBuffer();  // Send buffer to display after all readings are printed
}

void readThermocouple() {

  analogReadResolution(12);
  analogSetAttenuation(ADC_0db);

  int Temp3 = analogRead(Master);
  int Temp4 = analogRead(Slave);

  // Debugging: Print raw analog values
  Serial.print("Master ADC Reading: ");
  Serial.println(Temp3);
  Serial.print("Slave ADC Reading: ");
  Serial.println(Temp4);

  float MasterVolt = 3.3 * (Temp3 / 4095.0);
  float SlaveVolt = 3.3 * (Temp4 / 4095.0);

  // Debugging: Print calculated voltages
  Serial.print("Master Voltage: ");
  Serial.println(MasterVolt);
  Serial.print("Slave Voltage: ");
  Serial.println(SlaveVolt);

  // Adjust conversion factors based on your sensors' specifications
  float MasterTemp = (MasterVolt / 40.0) / 0.00015;
  float SlaveTemp = (SlaveVolt / 40.0) / 0.00007;

  // Debugging: Print calculated temperatures
  Serial.print("Master Temperature: ");
  Serial.println(MasterTemp);
  Serial.print("Slave Temperature: ");
  Serial.println(SlaveTemp);

  // Display Master and Slave readings on OLED
  u8g2.setCursor(0, 10);
  u8g2.print("Master -----");
  u8g2.setCursor(90, 10);
  u8g2.print(MasterTemp, 0);
  u8g2.setCursor(110, 10);
  u8g2.print("'C");

  u8g2.setCursor(0, 25);
  u8g2.print("Slave ------");
  u8g2.setCursor(90, 25);
  u8g2.print(SlaveTemp, 0);
  u8g2.setCursor(110, 25);
  u8g2.print("'C");

  // Send data to Blynk
  Blynk.virtualWrite(V1, MasterTemp);
  Blynk.virtualWrite(V2, SlaveTemp);
}

void readNTC() {
  int IN_ADC = analogRead(Coolant_IN);
  int OUT_ADC = analogRead(Coolant_OUT);

  // Debugging: Print raw ADC values
  Serial.print("Coolant_IN ADC: ");
  Serial.println(IN_ADC);
  Serial.print("Coolant_OUT ADC: ");
  Serial.println(OUT_ADC);

  float IN_Voltage = 3.3 * (IN_ADC / 4095.0);
  float OUT_Voltage = 3.3 * (OUT_ADC / 4095.0);

  // Debugging: Print calculated voltages
  Serial.print("IN Voltage: ");
  Serial.println(IN_Voltage);
  Serial.print("OUT Voltage: ");
  Serial.println(OUT_Voltage);

  // Calculate resistance and temperature
  float IN_R = NTCR_fixed * ((3.3 / IN_Voltage) - 1.0);
  float OUT_R = NTCR_fixed * ((3.3 / OUT_Voltage) - 1.0);

  float IN_Temp = 1 / ((log(IN_R / NTCR01) / NTCbeta) + (1 / NTC_T0_ref)) - 273.15;
  float OUT_Temp = 1 / ((log(OUT_R / NTCR01) / NTCbeta) + (1 / NTC_T0_ref)) - 273.15;

  // Debugging: Print calculated temperatures
  Serial.print("Coolant IN Temperature: ");
  Serial.println(IN_Temp);
  Serial.print("Coolant OUT Temperature: ");
  Serial.println(OUT_Temp);

  // Display Coolant readings on OLED
  u8g2.setCursor(0, 40);
  u8g2.print("Coolant IN ----");
  u8g2.setCursor(90, 40);
  u8g2.print(IN_Temp, 0);
  u8g2.setCursor(110, 40);
  u8g2.print("'C");

  u8g2.setCursor(0, 55);
  u8g2.print("Coolant OUT ---");
  u8g2.setCursor(90, 55);
  u8g2.print(OUT_Temp, 0);
  u8g2.setCursor(110, 55);
  u8g2.print("'C");

  // Send data to Blynk
  Blynk.virtualWrite(V3, IN_Temp);
  Blynk.virtualWrite(V4, OUT_Temp);
}

Please don’t delete and help me figure out my mistake

1 Like

@Subhasish Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Please also replace the photograph of your computer screen with the serial monitor text - copied and pasted and with triple backticks at the beginning and end.

The forum is set-up to allow new users to edit their posts for up to 24 hours after they are created. If your post hasn’t been edited to correct the formatting within that 24 hour period then the screen photograph and unformatted code will be removed.
When you created the post you were shown the correct way to post code with triple backticks.

Personally, I never respond to requests for help until forum users have corrected these basic rules about how to post code correctly.
The solution to your problem is very simple, as you have made a common error when using the ESP32 board. Fix your code formatting etc and I’ll share the solution with you.

Pete.

Okay I have done that.

You’ve chosen pins for your sensors that are internally connected to ADC2, which can’t be used at the same time as WiFi.

Read this link…

and change your wiring and code to use ADC1 pins.

Pete.

1 Like

I will correct it thanks…

Does it also impact the Coolant In and Coolant out readings because of that?

Because coolant in and coolant out is also showing 0

Yes, any pin where you are doing an analogRead() command.

Pete.

1 Like