1 Wire with DS18S20 digital thermometer
Created 02/10/2015 | Using 1 Wire with DS18S20 digital thermometer
In this tutorial we will use the 1 Wire Pi Zero or 1 Wire Pi Plus with a maxim integrated DS18S20 digital thermometer. For this you will need your Raspberry Pi, an 1 Wire Pi Zero or 1 Wire Pi Plus, and a maxim integrated DS18S20 digital thermometer.
You will need to enable i2c on your Raspberry Pi, see our other tutorial on i2c: I2C, SMBus and Raspbian Linux
Next install the OWFS (one wire file system) on your Raspberry Pi, see our other tutorial on owfs: OWFS with I2C support on Raspberry Pi
You need to reboot the Raspberry Pi once OWFS in installed before you can use the one wire file system.
Now all of the modules are installed and the Raspberry Pi is configured to use i2c we can begin building our project.
1 Wire Pi Zero or 1 Wire Pi Plus
Maxim integrated DS18S20 digital thermometer
Connecting the Sensor to the 1 Wire Pi Plus
If you haven’t done so install your 1 Wire Pi Plus onto the Raspberry Pi by connecting it onto the GPIO header. Make sure your Raspberry Pi is turned off when you do this to minimise the risk of damaging the Raspberry Pi or the 1 Wire Pi Plus.
Next connect the DS18S20 sensor to the 1 Wire Pi Plus. Pin 1 connects to GND, Pin 2 to OW on the 1 Wire Pi, Pin 3 connects to 5V.
For this tutorial we will start by creating a shell script to read the temperature from the sensor. You can use your favourite text editor for writing the program.
We need to create the mount point for the 1wire device with the following commands:
sudo mkdir /mnt/1wire
sudo owfs --i2c=ALL:ALL --allow_other /mnt/1wire/
Next we need to list all connected 1wire devices:
This will return a list of all the 1wire devices detected on the 1wire bus.
The DS18S20 sensors will appear in the list of devices with a number starting with 28. such as 28.0844C4030000 as shown below:
Using the sensors ID number we can now query the sensor to obtain the temperature. You must replace the 28.xxxxx number with the ID of your connected sensor.
Next we need to kill the owfs service and unmount the 1wire mountpoint
We also need to add sleep commands to pause the script to allow the OWFS file system to mount and unmount as the script runs.
Your script should now look like this.
/opt/owfs/bin/owfs --i2c=ALL:ALL --allow_other /mnt/1wire/
Save your program as "read1wire.sh" and change the permissions on the script:
sudo chmod +x read1wire.sh
Run it in a command terminal as root using
You will now have a temperature reading from your sensor on the console.