In this article, we connect a KY-001 Temperature Sensor to a Raspberry Pi Pico, any Rp2040 type board will be suitable. We actually tested this with a Cytron Maker Pi Pico
We will use Micropython for these examples but of course you can use the Arduino IDE as well if you have Raspberry Pi Pico support enabled
The KY-001 Temperature Sensor is based on the DS18B20 digital thermometer
The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.
Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.
- Unique 1-Wire® Interface Requires Only One Port Pin for Communication
- Reduce Component Count with Integrated Temperature Sensor and EEPROM
- Measures Temperatures from -55°C to +125°C (-67°F to +257°F)
- ±0.5°C Accuracy from -10°C to +85°C
- Programmable Resolution from 9 Bits to 12 Bits
- No External Components Required
- Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND)
The sensor looks like this
Parts Required
You can connect to the module using dupont style jumper wire.
Name | Link | |
Raspberry Pi Pico | ||
37 in one sensor kit | ||
Connecting cables |
Schematic/Connection
Pico | SENSOR |
---|---|
GPIO28 | S |
3v3 | + |
GND | – |
Code Examples
Basic example – this requires 2 libraries, OneWire and ds18x20 they are in the github repo
import machine, onewire, ds18x20 from time import sleep # Initialization of GPIO28 ds_pin = machine.Pin(27) # Initialization of the sensor object ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin)) # Search for all matching sensors roms = ds_sensor.scan() # Serial output print("Found DS devices") print("Temperature (°C)") # Endless loop for continuous reading of the temperature while True: ds_sensor.convert_temp() sleep(1) # Based on the number of compatible sensors found it will count up for rom in roms: # Serial output of the measured temperature print(ds_sensor.read_temp(rom)) sleep(3)
REPL Output
Links