Skip to content
Free IDE

← Components

DS18B20 temperature sensor

Digital temperature sensor: it sends the value already converted and checked by CRC over a single data wire (1-Wire bus). Each sensor has a 64-bit serial number written at the factory, so several can share the same pin. It uses the onewire and ds18x20 modules, which already come in the firmware. Request the conversion, wait 750 ms and read. It needs a 4.7 kΩ resistor between DQ and 3V3.

Pinout

18B20GNDDQVDD
PinConnect toNote
GND (1)GNDlooking at the flat face with the legs down, it is the one on the left
DQ (2)GPIO (e.g. 4) and a 4.7 kΩ resistor to 3V31-Wire data; several sensors can share the same GPIO
VDD (3)3V3accepts 3.0 to 5.5 V
FastTeacherFor teachers

From the syllabus to a planned semester

  • Teaching plan and calendar built automatically
  • Class diary ready to paste into SIGA
  • Slides and exercise lists with answer keys
Meet FastTeacher

Free Community edition · Windows

MicroPython example

import onewire, ds18x20
from machine import Pin
import time

# DQ on GPIO4, with a 4.7 kΩ resistor from DQ to 3V3
ds = ds18x20.DS18X20(onewire.OneWire(Pin(4)))
roms = ds.scan()  # one ROM (8 bytes) for each sensor on the wire
print("sensors:", len(roms))

while True:
    ds.convert_temp()  # all sensors measure at the same time
    time.sleep_ms(750)  # 12 bits: up to 750 ms to convert
    for rom in roms:
        print(ds.read_temp(rom), "°C")
    time.sleep(1)

Specifications

ItemValueSource
Power supply (VDD)3.0–5.5 VDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
Range−55 to +125 °C; ± 0.5 °C from −10 to +85 °CDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
Resolution9 to 12 bits (0.5 to 0.0625 °C); 12 bits from the factoryDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
Conversion time (max.)93.75 / 187.5 / 375 / 750 ms at 9 / 10 / 11 / 12 bitsDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
At power-upreads +85 °C (0550h) until the first conversionDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
DQ pull-up~4.7 kΩ to VDD (the text says ~5 kΩ)Datasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
Pin order (TO-92, flat face)1 GND, 2 DQ, 3 VDDDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf
64-bit ROMfamily 28h + 48-bit serial + CRCDatasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf — in the simulator the serial number comes from the part id (it is not from a real sensor)
Scratchpad bytes 5 to 7FFh, 0Ch, 10h (memory map figure)Datasheet DS18B20 (Maxim Integrated), user-web.icecube.wisc.edu/~kitamura/NK/Datasheets/Dallas_1Wire/DS18B20.pdf — Under review: the text says "all 1s"; check on a lab sensor
Factory TH and TL75 and 70 °C (4Bh and 46h)PyPlaca component catalog — Under review: the datasheet does not give them; values from published readings of new sensors
Parasite mode (VDD to GND)not simulatedUnder review: needs the "strong pull-up" during the conversion
Driveronewire and ds18x20 (frozen into the firmware)MicroPython v1.29.0: ports/esp32/boards/manifest.py and micropython-lib (onewire.py, ds18x20.py)

Values marked "Under review" will still be checked against the parts in the lab.

FastMindLocal AI assistant

The AI that remembers your life and lives on your computer

  • Long-term memory with the source of every answer
  • Works offline: your data stays on your PC
  • Reads PDFs, slides, photos and meeting recordings
Download free for Windows

Essential plan free forever

FastTeacherFor teachers

From the syllabus to a planned semester

  • Teaching plan and calendar built automatically
  • Class diary ready to paste into SIGA
  • Slides and exercise lists with answer keys
Meet FastTeacher

Free Community edition · Windows

FastMindLocal AI assistant

The AI that remembers your life and lives on your computer

  • Long-term memory with the source of every answer
  • Works offline: your data stays on your PC
  • Reads PDFs, slides, photos and meeting recordings
Download free for Windows

Essential plan free forever