Obtaining wrong analog readings using the ESP32 devkitc v4

Kameluo
Posts: 1
Joined: Wed Apr 20, 2022 9:37 am

Obtaining wrong analog readings using the ESP32 devkitc v4

Postby Kameluo » Wed Apr 20, 2022 9:44 am

Hello,
Can someone help me find the problem. I am testing 6 temperature sensors (3 digital, 3 analog). The digital ones are "DS18B20" which I trust, the analog ones are "MCP9701A", "TC1047A" and "MCP9700A". By reading the analog sensors using Arduino-UNO or Arduino-mega the results of the 6 sensors are almost identical and I don't face any problem. But when make the test using the ESP32-devkitc-v4 I obtain wrong reading from the 3 analog sensors. In the code "serial monitor" I obtain a voltage value completely different from the one I measure physically by a multi-meter

For example : The 3 digital sensors a giving the value of 23.56C to 23.81C but for the "MCP9701A" analog sensor I obtain 16.26C and the voltage obtain in the serial monitor is 0.718 volts, however it is 0.851 volts by the multi-meter. And according to the calculations from the data-sheet: (0.851-0.4)/(19.5mVolts)= 23.12C which is so close to the digital sensors. I have the same problem with the other analog sensors, so if you can help me find my error, I will appreciate it.

Here are the data-sheets of the analog sensors:
MCP9701A and MCP9711A
https://ww1.microchip.com/downloads/en/ ... 01942G.pdf

TC1047A
https://ww1.microchip.com/downloads/en/ ... 21498D.pdf

Here is my code:

Code: Select all

#include <OneWire.h>
#include <DallasTemperature.h>
#include "driver/adc.h"

// GPIO where the DS18B20 is connected to
const int oneWireBus = 4;     
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(oneWireBus);

// Pass our oneWire reference to Dallas Temperature sensor 
DallasTemperature sensors(&oneWire);

#define analogInPin0 35
#define analogInPin1 32
#define analogInPin2 33

float analogTempTC1047=0.0;
float analogTempMCP9700=0.0;
float analogTempMCP9701=0.0;

float volt0=0.0;
float volt1=0.0;
float volt2=0.0;

int sensorValue0 = 0;
int sensorValue1 = 0;
int sensorValue2 = 0;

void setup() {
  // Start the Serial Monitor
  Serial.begin(9600);
  // Start the DS18B20 sensor
  sensors.begin();
}

void loop() {
  // put your main code here, to run repeatedly:
  sensorValue0 = analogRead(analogInPin0);
  sensorValue1 = analogRead(analogInPin1);
  sensorValue2 = analogRead(analogInPin2);

  volt0= (3.3/4096.0)*sensorValue0;
  analogTempMCP9701= ((volt0-0.4)/0.0195);

  volt1= (3.3/4096.0)*sensorValue1;
  analogTempTC1047= ((volt1-0.5)/0.01);
  
  volt2= (3.3/4096.0)*sensorValue2;
  analogTempMCP9700= ((volt2-0.5)/0.01);

  sensors.requestTemperatures();
  float temperatureC1 = sensors.getTempCByIndex(0);
  float temperatureC2 = sensors.getTempCByIndex(1);
  float temperatureC3 = sensors.getTempCByIndex(2);
  Serial.print("S1= ");
  Serial.print(temperatureC1);
  Serial.print("ºC");
  Serial.print(", S2= ");
  Serial.print(temperatureC2);
  Serial.print("ºC");
  Serial.print(", S3= ");
  Serial.print(temperatureC3);
  Serial.print("ºC,------- ");

  Serial.print("input sensor1= ");
  Serial.print(sensorValue0);
  Serial.print(", volt1=  ");
  Serial.print("= ");
  Serial.print(volt0, 3);
  Serial.print(", Analog sensor MCP9701 = ");
  Serial.print(analogTempMCP9701);

  Serial.print("----");
  Serial.print("input sensor2= ");
  Serial.print(sensorValue1);
  Serial.print(", volt2=  ");
  Serial.print("= ");
  Serial.print(volt1, 3);
  Serial.print(" --Analog sensor TC1047 = ");
  Serial.print(analogTempTC1047);
  
  Serial.print("----");
  Serial.print("input sensor3= ");
  Serial.print(sensorValue2);
  Serial.print(", volt2=  ");
  Serial.print("= ");
  Serial.print(volt2, 3);
  Serial.print(" --Analog sensor MCP9700 = ");
  Serial.println(analogTempMCP9700);
  delay(4000);
}
And here is the serial monitor output:

Code: Select all

S1= 23.56ºC, S2= 23.81ºC, S3= 23.50ºC,------- input sensor1= 895, volt1=  = 0.721, Analog sensor MCP9701 = 16.47----input sensor2= 747, volt2=  = 0.602 --Analog sensor TC1047 = 10.18----input sensor3= 752, volt2=  = 0.606 --Analog sensor MCP9700 = 10.59
S1= 23.56ºC, S2= 23.75ºC, S3= 23.50ºC,------- input sensor1= 894, volt1=  = 0.720, Analog sensor MCP9701 = 16.42----input sensor2= 747, volt2=  = 0.602 --Analog sensor TC1047 = 10.18----input sensor3= 755, volt2=  = 0.608 --Analog sensor MCP9700 = 10.83
S1= 23.56ºC, S2= 23.75ºC, S3= 23.50ºC,------- input sensor1= 905, volt1=  = 0.729, Analog sensor MCP9701 = 16.88----input sensor2= 746, volt2=  = 0.601 --Analog sensor TC1047 = 10.10----input sensor3= 753, volt2=  = 0.607 --Analog sensor MCP9700 = 10.67

rpiloverbd
Posts: 101
Joined: Tue Mar 22, 2022 5:23 am

Re: Obtaining wrong analog readings using the ESP32 devkitc v4

Postby rpiloverbd » Thu Apr 21, 2022 6:18 am

I think it's better to check the ESP32 separately. Disconnect it from the sensors and connect 5V input to the analog pins that you're using. See if you get the 5V reading in the serial monitor.

Who is online

Users browsing this forum: Basalt, Google [Bot] and 82 guests