DS18B20 readings are wrong

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
ajocius
Posts: 81
Joined: Mon Feb 19, 2018 6:31 am

DS18B20 readings are wrong

Post by ajocius » Mon Mar 30, 2020 11:36 am

I have 5 DS18B20 temperature sensors connected via one wire non parasite to ESP32 running micropython. I do get readings that I post to influxdb and monitor over time. I noticed that all 5 sensors are reacting to temperature (increasing, decreasing), but seem to give me different readings. So graph lines are just parallel to each other. Difference between highest and lowest temp is around 7C, way to much from expected 0,5C accuracy specified on a datasheet. I connected sesnsors to 3,3V VCC and have 4,7KOhm pull up resistor between VCC and data.

Any thoughts why this behavior? Or are these sensors of bad quality (bought on Aliexpress) and there is nothing to do... It almost feels like I can just add or subtract constant amount from readings to get to the right temp, but does not feel right way to use sensors...

Image
Last edited by ajocius on Mon Mar 30, 2020 4:27 pm, edited 1 time in total.

kevinkk525
Posts: 775
Joined: Sat Feb 03, 2018 7:02 pm

Re: DS18B20 readings are wrong

Post by kevinkk525 » Mon Mar 30, 2020 1:07 pm

Since you bought them from Aliexpress (like I did), they are most likely cheap clones. Some of those have that kind of offset.
I also have multiple DS18B20s that show a temperature offset from each other but otherwise a very similar temperature curve.

I ended up accepting the fact that the chinese sensors I buy don't have the accuracy that the originals have. Therefore I implemented a simple offset into my projects and "calibrate" the sensors before deploying them.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

ajocius
Posts: 81
Joined: Mon Feb 19, 2018 6:31 am

Re: DS18B20 readings are wrong

Post by ajocius » Mon Mar 30, 2020 1:13 pm

Thx for quick response. Does that mean that you calculated individual offset per sensor and used simple procedure , like :
1. Reading temp
2. adding offset (can be positive or negative)
3. Using result temp?

Besides constant offset, did you see any other malfunctions? I intend to use it in greenhouse and trigger ventilation. So if sensor malfunctions, greenhouse can overheat (if ventilation is closed while it is hot) or get too cold (if door/window is left open overnight). Would be great to hear more about your project, seems like you used it in greenhouse as well?

Br,
Arunas

kevinkk525
Posts: 775
Joined: Sat Feb 03, 2018 7:02 pm

Re: DS18B20 readings are wrong

Post by kevinkk525 » Mon Mar 30, 2020 1:34 pm

That is exactly what I do. Measure individual sensor offset and then add the offset to all sensor readings.

Other than that I didn't notice any malfunctions. Use one sensor in my "greenhouse" to read the water temperature of my nutrient solution. Sensor still works fine.
Going to use 2 sensors this year, one for air and one for water. Don't expect any problems.

But if it is a critical component for heating and cooling, I'd suggest using 3 sensors, just in case one fails. Then you can always rely on a majority reading and replace the sensor that starts failing.

My project is pysmartnode: https://github.com/kevinkk525/pysmartnode

It's not a project for a specific use-case, it's more a smarthome framework for easily integrating components (sensors, switches, pumps) into a smarthome, which is controlled by home-assistant (but works without it, just uses mqtt). It exposes the configured components to Home-assistant for easy discovery and controlling. Developing new components for the framework is easy as a basic framework with functionality (like offsets) is provided.
If you have a look at it, make sure to check the branch "uasyncio_next" because I'm preparing it for the new uasyncio version that got merged and a lot of new features are added there. Will soon merge that branch into master when I'm done testing it (but it already works on my esp32 which I'm preparing for greenhouse duty).

My "greenhouse" is a hydroponic system in pvc pipes on my balcony :lol: No ventilation, only a pump that is connected to a sonoff s20 power socket (running the pysmartnode project) which is being turned on repeatedly for 10 minutes every hour. Other than that I'm measuring water temperature, water conductiviy EC/PPM for nutrient solution concentration, ph value (not yet working) and the water levels in the tank using a HCSR04. Currently all of that is still sitting on my desk xD Hope to get it integrated within the next 2 weeks.
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

ajocius
Posts: 81
Joined: Mon Feb 19, 2018 6:31 am

Re: DS18B20 readings are wrong

Post by ajocius » Mon Mar 30, 2020 2:32 pm

great to find someone with similar use of devices and micropython. Is your pH meter and EC/PPM meter integrated into HA as well? If yes, what devices do you use?

ajocius
Posts: 81
Joined: Mon Feb 19, 2018 6:31 am

Re: DS18B20 readings are wrong

Post by ajocius » Mon Mar 30, 2020 2:43 pm

I did find some suggestions to reduce pull up resistor value when sensor is connected to 3.3V, not 5V. Suggestion was to use 2,7 KOhm instead of 4.7 Ohm. Haven't tested yet, but then again, this parallel graphs indicates there is offset issue most likely, how you pointed out.

Ordered some from trusted distributer, will be interesting to see what values will I get there.

kevinkk525
Posts: 775
Joined: Sat Feb 03, 2018 7:02 pm

Re: DS18B20 readings are wrong

Post by kevinkk525 » Mon Mar 30, 2020 3:57 pm

ajocius wrote:
Mon Mar 30, 2020 2:32 pm
great to find someone with similar use of devices and micropython. Is your pH meter and EC/PPM meter integrated into HA as well? If yes, what devices do you use?
Every component using my pysmartnode framework gets integrated into HA (if the component got correctly implemented :D )
EC-Meter is actually not even a device. It's a cheap self-made one. The code works but it's only "lab-tested" yet: https://hackaday.io/project/7008-fly-wa ... er-arduino
The pH meter is: https://www.aliexpress.com/item/3280567 ... 4c4dxqnGlQ
However, I haven't tested the pH meter yet and the code is purely experimental. I'm hoping to get to it within the next 7 days.
ajocius wrote:
Mon Mar 30, 2020 2:43 pm
I did find some suggestions to reduce pull up resistor value when sensor is connected to 3.3V, not 5V. Suggestion was to use 2,7 KOhm instead of 4.7 Ohm.
Hmm that sounds rather strange. Especially because you're not using the sensors in parasitic mode, then I'd understand that.

There's an interesting repository with arduino code to check if your ds18 are counterfeit: https://github.com/cpetrich/counterfeit_DS18B20
Haven't tried mine yet.. But I'm pretty sure they are counterfeits :lol:
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

ajocius
Posts: 81
Joined: Mon Feb 19, 2018 6:31 am

Re: DS18B20 readings are wrong

Post by ajocius » Mon Mar 30, 2020 4:30 pm

Not sure how to post picture on this forum, tried with [img] and url from Google Photos, but picture does not show. After following graph for a day I see that lines are not always parallel. Need more testing...

User avatar
ghayne
Posts: 41
Joined: Sat Jun 08, 2019 9:31 am
Location: Cwmllynfell, Wales

Re: DS18B20 readings are wrong

Post by ghayne » Mon Mar 30, 2020 8:16 pm


kevinkk525
Posts: 775
Joined: Sat Feb 03, 2018 7:02 pm

Re: DS18B20 readings are wrong

Post by kevinkk525 » Mon Mar 30, 2020 8:39 pm

Very true, however, it's the same one that I posted :lol:
Kevin Köck
Micropython Smarthome Firmware (with Home-Assistant integration): https://github.com/kevinkk525/pysmartnode

Post Reply