-->
Page 1 of 2

Reading temperature

PostPosted: Sun Oct 11, 2020 11:17 pm
by tandrews
I am using an ESP8266 to read the temperature of my smoker. It is a thermistor. I am using a 150k resistance. I have calculated the proper beta coefficient and have found the readings to be extremely accurate when it's below a threshold (around 200f/94c). In fact, I find it stops at 224f and won't go any higher.
Is there a limit to the ADC? I had considered just using the MAX6755 I have, but wasn't sure if I was perhaps just missing something simple.

Code:

Code: Select all// which analog pin to connect
#define THERMISTORPIN A0

// resistance at 25 degrees C
#define THERMISTORNOMINAL 45000

// temp. for nominal resistance (almost always 25 C)
#define TEMPERATURENOMINAL 25

// The beta coefficient of the thermistor (usually 3000-4000)
#define BCOEFFICIENT 3148.36

// the value of the 'other' resistor
#define SERIESRESISTOR 147000

float getSteinhartCelsius(float resistance) {
  /**
     Returns the steinhart calculation
  */
  float steinhart;
  steinhart = resistance / THERMISTORNOMINAL;     // (R/Ro)
  steinhart = log(steinhart);                  // ln(R/Ro)
  steinhart /= BCOEFFICIENT;                   // 1/B * ln(R/Ro)
  steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To)
  steinhart = 1.0 / steinhart;                 // Invert
  steinhart -= 273.15;                         // convert to C
  return steinhart;
}

float analog_average_read()
{
  /**
     Reads a number of samples and averages those samples.
  */
  float average = 0.0f;

    average = analogRead(THERMISTORPIN);
average = (1023 / average) - 1;
  average = SERIESRESISTOR / average;
  return asF(getSteinhartCelsius(average));
}

Re: Reading temperature

PostPosted: Mon Oct 12, 2020 5:03 pm
by davydnorris
The ADC on chip is 10bit with a range of 0 - 1.0V, so it's not particularly accurate. You need to make sure your input voltage is within the 0-1 Volt range though.

Re: Reading temperature

PostPosted: Sat Oct 24, 2020 3:45 am
by eriksl
It surely isn't particularly accurate, you can say that :D. That's not because the range is 10 bits (which is a fairly big range imho). It's because of other factors:
- integration of all sorts of RF signal paths in the chip that will disturb the measurements
- current flow in the chip various greatly due to the RF "power" step, which will also disturb the ADC
- even 10 bits of accuracy is already hard to achieve realisticly without really good analog circuitry outside the chip

There is a special API function to do a oversampling measurement of the ADC. This requires the WLAN function to be completely shut down. If you do both, the obtained results may get sort of usable.

There are two other approaches that are much simpler, which is to extend the digital domain to outside the chip: use I2C. Then connect either one of the many temperature measurement chips (LM75, TMP75 etc) or connect a proper ADC.

Re: Reading temperature

PostPosted: Sat Oct 24, 2020 7:56 pm
by davydnorris
@eriksl regarding your comment on using a dedicated temp measurement chip - the OP is measuring the temp of a smoker oven, so this is going to get hot!

They will also want to have the ESP unit outside the smoker and the sensor inside and attached by wires that won't melt, so the thermistor approach is probably the best.

However I completely agree with you in terms of adding an I2C based ADC or even a voltage/current sensor like the INA219 - that's how I would do it.

To the OP - you can get prebuilt INA219 modules from Adafruit complete with Arduino libraries. It's very well supported.