Getting 85C/185F readings with DS18B20 sensor at lower temperatures
Posted: Thu Jun 16, 2022 9:27 pm
For some strange reason, when the temperature gets around -24C/-12F (monitoring the temperature of a freezer) I occasionally get an invalid 85C/185F reading (happens around every handful or so of hours.) I originally believed it to be an issue with the cable I made up, so I made another assembly with another sensor and have the exact same issue. here's the code below:
Code: Select all
def go():
import time
import machine
import urequests
import network
import onewire, ds18x20
sta_if = network.WLAN(network.STA_IF)
dat = machine.Pin(12)
ds = ds18x20.DS18X20(onewire.OneWire(dat))
roms = ds.scan()
time.sleep(2)
def send_data():
url = 'http:/[web server address]/rsensor_ds18b20_e.php'
headerd = {'Content-Type': 'application/x-www-form-urlencoded'}
jsons = "data=" + str(ds18b20temp_f)
if sta_if.isconnected() == True:
try:
r = urequests.post(url, data=jsons, headers= headerd)
r.close()
except OSError:
pass
while True:
ds.convert_temp()
time.sleep(15)
ds18b20temp_c=ds.read_temp(roms[0])
ds18b20temp_f=ds18b20temp_c * 9.0/5.0 +32
send_data()