Thermistor reading - analog input

Hi,

I have KTY81-110 sensors. I would like to measure temperatures (between 20 and 130 Celsius) using KTY81 + Raspberry PI Pico W. I assembled a simple, classic voltage divider:

3V3 (from the PI board)
|
3k3 resistor
|
Analog IN (of the Pi board)
|
KTY81 (PTC!!!)
|
GND

I’m absolutely new with Home Assistant, I have some experience and project using Arduino and ESP8266.

I’m looking for a ESPHome yaml code to reading an analog GPIO and convert the value to Celsius.
I usually found solutions only for a NTC resistor.

Or is there an example to use Ardino code within ESPHome yaml?

I saw pages and examples where they used max31865. Currently I don’t have any, and I would like to solve this measuring without using any of this IC.

Thank you. Sorry for the dummy question.

Today I found a possible solution:

I use the code bellow.
At ntc function I added three calibration points.
I got the values from the datasheet:
https://www.ret.hu/media/product/15245/523242/KTY81_SER.pdf
See: page 4.

In the yaml there are 6 reference values, but only EXACTLY 3 allowed to use.
So, I commented out the 3 other reference values for future use.

Now I use three KTY81.
As external reference temperature sensors, I can only use three DS18B20.
Currently seems to correct that I measured with these KTY81 sensors.

sensor:
  # Felso homeres Thermistor:
  -  platform: adc
     id: source_sensor0
     pin: GPIO26
     update_interval: 10s

  - platform: resistance
    sensor: source_sensor0
    configuration: DOWNSTREAM
    resistor: 3.3kOhm
    reference_voltage:  3.3V
    id: resistance_sensor0
    
  - platform: ntc
    sensor: resistance_sensor0
    calibration:
      - 0.815kOhm -> 0°C
      #- 1.0kOhm -> 25°C
      - 1.209kOhm -> 50°C
      - 1.696kOhm -> 100°C
      #- 1.970kOhm -> 125°C
      #- 2.211kOhm -> 150°C
    name: My temperature sensor
    filters:
       -  offset:  0
1 Like

I tried doing exactly what you are doing, just a few days ago… multiple problems cropped up. First, these sensors are extremely non linear. Second, the ADC on the esp chips is VERY noisy. So the values jump all over the place especially in the non-linear sections making the values basically unusable. EVEN WITH the max31865 chip the sensors jump all over the place. This is a known limitation of adc processing using esp chips.

I even hooked up a highly regulated variable DC power supply to test the ADC function and it was still extremely noisy.

The alternative might be a dedicated adc chip. However, I went a different direction with my temp probe as I wasted waaay too much time trying to get this working,

Did you ever get this working?

I’m struggling with this myself at the moment.

Could you share more about your different direction and whether it was successful?

A DS18b20 works great if you need a probe. Ive had some under my house for 2 years taped to various places on my water lines. If it gets to cold, strings of heat tape turn on to keep the water lines from freezing.

You gotta look at the documentation though!

Your timing on this is good. There is new code for Dallas sensors that you need to use to get rid of the scratchpad errors that have plagued all of us using ESPHome. I also use those exact same Dallas sensors. I’ll find my link and post it here.

Edit: found it.

My solution to the thermocouple problems was to not use it. I have a giant pellet stove project and figured out how to decode hex values coming out of an MCU… New working design - No Wifi board!! One ESP32 replaces all of it. · jazzmonger/wood-pellet-stove-with-TYWE1S-Tuya-chip · Discussion #33 · GitHub

I was actually talking about the 4.7k resistor the docs tell you to use, as well as in the specs for the DS18B20

The DS18B20 has a max temp of 125c so thats the limiting factor for stoves and such.

There’s a raging debate about what value of resistor to use on Dallas sensors, despite what the docs say. I did a huge amt of testing when I worked with the ESPHome devs to fix the scratchpad problem and actually ended up using 1k resistors. They work well. Of course, YMMV…

I havn’t personally tested multiple resistor values but, I do know that I tried using some DHT-11’s back in the day with no resistor and I was having issues and if I recall right, they were always 2-3 degrees off. Adding a 4.7k made them work much better and more accurate. Using 4.7k is just a habit now but, dont doubt 1k works just as well.

DHT11’s are notoriously inaccurate! In fact, so are these Dallas sensors, but thankfully you can calibrate them using a known value or reading from an accurate source.

I always hear that but, ive had a few that i installed way back when and they’ve been pretty good for me, atleast the temperature has always been within 1deg typically. I dont really use the the humidity for anything except its there as a data point. Ive never checked to see how accurate that is.