---
title: "1-Wire Driver with DS18B20 Temperature Sensor Demo"
description: "[![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/1-Wire-DS18B20-Wiring-Closeup-1024x576.jpg)](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/1-Wire-DS18B20-Wiring-Closeup.jpg)[![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Parallax_Serial_Terminal_EXAMPLE1.png)](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Parallax_Serial_Terminal_EXAMPLE1.png) ##### Description This QuickByte shares two SPIN2…"
url: "https://obex.parallax.com/docs/quick-bytes/propeller-2/1-wire-driver-with-ds18b20-temperature-sensor-demo/"
updated: "2026-09-29"
category: Propeller 2
---

# 1-Wire Driver with DS18B20 Temperature Sensor Demo

[![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/1-Wire-DS18B20-Wiring-Closeup-1024x576.jpg)](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/1-Wire-DS18B20-Wiring-Closeup.jpg)[![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Parallax_Serial_Terminal_EXAMPLE1.png)](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Parallax_Serial_Terminal_EXAMPLE1.png)

##### Description

This QuickByte shares two SPIN2 code examples that enable the P2 to communicate with 1-wire devices. We are using
 the common DS18B20 1-wire temperature sensor in these examples, although the driver could be extended for any
 1-wire device.

- **Example 1:**Search 1-wire bus for DS18B20 device, display the serial number and temperature on a
   serial terminal.
- **Example 2:** Based on a known DS18B20 serial number, read the temperature and display on a serial
   terminal.

##### Connect Up Your Hardware

![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/DS18B20_QB_Pinout.png)

**1 = GND** (Connect to one of the GND pins on your P2 breakout board)

**2 = P2 I/O Pin** (Connect to an I/O pin, P7 used in the example code)

**3 = 3.3V** (Connect to One of the Vxx pins on your P2 breakout board)

##### Load the Code

The two example code archives are available to download from the Source Code link below.

Open Propeller Tool and load the code example.

**Tip:** Unzip the example code archive and then use PropellerTool to open the main file, which in
 the case of these examples can be identified by the _demo tag at the end of the filename. You can always find
 the main file of any PropellerTool archive by consulting the “_README.txt” file inside the archive. All the
 source code files are listed, with the main file at the top.

In the example code files, ensure the 1-wire I/O pin matches the pin connected to your sensor. We have used pin 7
 in the example, but you can change it to any spare I/O pin you prefer:

![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Code_Setup_OW_Pin.png)

And for example 2, also ensure the serial number of the 1-wire device matches your serial number! You can read
 your serial number using code example 1.

![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Code_Setup_OW_Serial.png)

Within PropellerTool:

1. Press F7 to identify your P2, and make a note of the COM port number
2. Press F10 to load the Code into the P2 microcontroller
3. Press F12 to open the Parallax Serial Terminal (PST) software

The code will now be running in your P2, and will be waiting to receive a keypress on the serial terminal before
 it starts transmitting data. This allows you time to set up your serial terminal as follows:

Within the PST:

1. Select the correct COM port number for your microcontroller (from the F7 step above)
2. Click Enable
3. Click inside the text box near the top of the PST window, then press enter

Once you press Enter, the output from the P2 program will be displayed in the terminal. This is the typical
 output from Example 1:

![](/qbi/1-Wire Driver With DS18B20 Temperature Sensor Demo - Parallax_files/Parallax_Serial_Terminal_EXAMPLE1.png)

Connecting 1-wire devices to the Propeller P2 is very simple, and in most cases they do not require any
 additional components, such as pull-up or series resistors, as the P2 SmartPins can emulate those functions.

For help please feel free to ask your questions here, or for a wider audience of helpers at our Forums: [https://forums.parallax.com](https://forums.parallax.com/).

##### Parts Used

- [DS18B20
   TO-92 Digital Thermometer Temperature IC Sensor](https://www.parallax.com/product/ds18b20-to-92-digital-thermometer-temperature-ic-sensor/)
- [3" Jumper Wires (1 bag of 10)](https://www.parallax.com/product/3-jumper-wires-1-bag-of-10/)
- [P2 Edge
   Module](https://www.parallax.com/product/ds18b20-to-92-digital-thermometer-temperature-ic-sensor/)
- [P2 Edge Breadboard](https://www.parallax.com/product/p2-edge-module-breadboard/)
- [Prop Plug Rev E](https://www.parallax.com/product/prop-plug/)
- [USB Mains Adapter, 18W, 5V, 3A](https://www.parallax.com/product/usb-mains-adapter-18w-5v-3a/)
- [USB A to DC 2.1mm Jack Cable](https://www.parallax.com/product/usb-a-to-dc-2-1mm-jack-cable/)
- [USB A to Micro B Cable](https://www.parallax.com/product/usb-a-to-micro-b-cable/)

##### Source Code

- [1-Wire Driver with DS18B20
   Quick Byte Code](/qbi/downloads/1-Wire-Driver-with-DS18B20-Quick-Byte-Code-28306.zip)

##### Programming Language

- [Spin 2](https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/)
- [PASM2](https://docs.google.com/spreadsheets/d/1_vJk-Ad569UMwgXTKTdfJkHYHpc1rZwxB-DcIiAZNdk/)

##### Tools and Operating System

- [Propeller
   Tool for Windows](https://www.parallax.com/package/propeller-tool-software-for-windows-spin-assembly-2/)
- [FlexProp for Windows, Mac and Linux](https://www.patreon.com/totalspectrum)

##### Additional Resources

- [Propeller 2
   Spin Documentation](https://docs.google.com/document/d/16qVkmA6Co5fUNKJHF6pBfGfDupuRwDtf-wyieh_fbqw/edit)

##### Document Author

- Michael Mulholland

##### Source Code Author

- Jon McPhalen
