Fig. 1: Waterproof temperature sensor (DS18B20). The long waterproof wire is led through a grouted whole in the box, where it is connected to the Raspberry Pi.

To measure water temperature we bought a waterproof temperature sensor produced py Sparkfun Electronics (Fig. 1). When Mr. Turtle floats on the water it drifts behind the platform and registers the surface water temperature.


To set up the temperature sensor on the Raspberry Pi we followed instructions on Raspberry Pi Tutorials. Additionally to the RasPi, wires and a breadboard/printed circuit board we need a 4.7 kΩ resistor.


With this Python 2 script the surface temperature is measured:

import RPi.GPIO as GPIO

GPIO.setup(12, GPIO.IN)
def temp_messen():
    # read 1-Wire Slave list
    file = open('/sys/bus/w1/devices/w1_bus_master1/w1_master_slaves')
    w1_slaves = file.readlines()

    # get current temperature for every 1-Wire Slave
    for line in w1_slaves:
        # extract 1-wire Slave
        w1_slave = line.split("\n")[0]
        # read file 1-wire Slave
        file = open('/sys/bus/w1/devices/' + str(w1_slave) + '/w1_slave')
        filecontent = file.read()

        # read temperature values and convert them
        stringvalue = filecontent.split("\n")[1].split(" ")[9]
        temperature = float(stringvalue[2:]) / 1000

        # print tamperature values
        print(str(w1_slave) + ': %6.2f C' % temperature)