ESP32 Analog Input from Grove Temp Sensor acting "Wonky."

Hello,

I am programming an ESP-32 WROOM to accept a Grove (101020015) temp sensor input.
I am using the translation algorithm provided by Seeed that works fine with the Uno Wifi Rev2 I have. With the ESP32 the analog input follows the last part of the formula: -300. I changed it from -273.15 to -300 and the output changed to that value. Am I missing a library file possibly?

See the screenshot.

//   Test ESP32 inputs

  #include <math.h>

  #define ONBOARD_LED  2   


const int switchPin = 4;    // Board Digital Input GPIO4
    int switchState = 0;

 const int B = 4275;               // B value of the thermistor;  +- 275 = .6 C (1.0 F)
    const uint32_t R0 = 100000;            // R0 = 100k; int type uint32_t required (unsigned 32 bit)
    const int tmp_adj_1 = 4;                      // sensor 1 calibration adjustment
     
    float space_temp_1;                      //    Grove - Temperature Sensor connect to (GPIO) input pin
    float sp_temp_1;
    float sp_temp_1F;
    float Low_Tmp_Alm = 38.00;      // Low Alarm Setpoint 
   
  

void setup()
{
    pinMode(ONBOARD_LED,OUTPUT);     //  Blink LED function
    pinMode(space_temp_1,INPUT);
    pinMode(switchPin,INPUT);       // Pressure Alarm Input
    
    Serial.println("Begin loop top..");
             // initialize serial:
    Serial.begin(115200);


  
}

void loop()
{
  digitalWrite(ONBOARD_LED,HIGH);            //  Blink for run indicator
     delay(200);
     digitalWrite(ONBOARD_LED, LOW);
     
     switchState = digitalRead(switchPin);       //Pressure Input Pin Read
     space_temp_1 = analogRead(39);            // Space Temp Input Read
     
     delay(500);
                 //  ***************** Low Alarm Function ***************

      float R1 = 1023.0 / space_temp_1 - 1.0;
      R1 = R0 * R1;
            
      float sp_temp_1 = 1.0 / (log(R1 / R0) / B + 1 / 298.15) - 300;
              // [  original value: -273.15  ] convert to temperature via datasheet
      float sp_temp_1F = (sp_temp_1 * 9 / 5) + 32 - tmp_adj_1;          
                                 
      Serial.println("........");
      Serial.println("                  Space Temp =     ");
      Serial.print(sp_temp_1);
      Serial.println();
      Serial.println("........");
       Serial.println();
}

The ESP32 ADC does not work well, is highly nonlinear, and may not be useful for this application.

Ouch. Are there any viable workarounds?

An external ADC module would work, or use a digital temperature sensor. The ESP32 ADC is more or less useless.

Where do I look at an external module? Or a digital sensor?
I hate to throw this thing to the scrap heap....

There are many choices that a Google search will flag. Personally, I like Adafruit's products as they are US-based with good customer service. DS18B20 and DHT22 come to mind. Try searching on their site.

many thanks...

Most hobby suppliers offer inexpensive external ADC modules, and they generally outperform the ADCs built in to most microprocessors. Adafruit, Sparkfun, etc.

This one is easy to use, very flexible and accurate: ADS1015 12-Bit ADC - 4 Channel with Programmable Gain Amplifier [STEMMA QT / Qwiic] : ID 1083 : $9.95 : Adafruit Industries, Unique & fun DIY electronics and kits

appreciate your lead...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.