# reef-pi Guide 3: Temperature Controller

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/062/072/medium800/sensors_cyphastrea.jpg?1537337905 Cyphastrea coral in a Biocube 29G reef aquarium, powered by reef-pi. Light: Kessil A360)

Welcome to the third guide in reef-pi series.

[See the second part of this series here](https://learn.adafruit.com/reef-pi-power-controller)

In this guide, we'll be building a temperature controller using reef-pi. Corals are sensitive to temperature fluctuations and only survive in specific temperature. Higher order animals, such as marine fish can withstand much higher temperature fluctuations than coral. Tropical corals thrive at 78 degrees Fahrenheit. In reef aquariums,&nbsp;submersible heaters are used to keep the tank temperature at 78 degrees. For places where the indoor temperature gets really hot, chillers are used to cool down the aquarium water temperature to the desired level. A temperature controller automates heater and chiller on/off by sensing aquarium temperature, in turn maintaining a stable aquarium&nbsp;temperature.

Heaters are also prone to failures. Heater failure is one of the most common causes of tank crash (loss of all tank inhabitants). Temperature controllers can shut down heaters and alert users when aquarium temperature goes outside a range, providing an extra layer of safety net.

This guide assumes you have a working reef-pi installation with power controller module enabled.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/416/medium800/sensors_3FBFC80C-E5E6-49F4-8138-0D02EB91C04E.jpeg?1537767564)

# reef-pi Guide 3: Temperature Controller

## Parts

Temperature controller module in reef-pi does not require power controller features, i.e. users can use reef-pi to just monitor and log temperature, but for turning on/off heater or chiller requires power controller module. In this guide, we'll be extending the power controller.

We'll use submersible DS18B20 temperature sensors for monitoring temperature. The DS18b20 requires minimal circuit (only a single 4.7K resistor) for integration with Raspberry Pi. We'll use the existing PermaProto HAT for this. A&nbsp;DS18B20 sensor will be connected to the controller enclosure using a 3.5 mm audio jack. The probe itself will have a 3.5 mm male audio connector, and the controller enclosure will have a panel mount female audio jack connector.

Note: Due to our choice of 3.5 mm audio connector, we should always avoid plugging/unplugging the temperature sensor when reef-pi is running. Always power down reef-pi before connecting or disconnecting the sensor. The 3.5 mm audio jack causes +Ve and GND pins to be touched (shorted) every time the male connector is plugged in, causing the Raspberry Pi to reboot (which we do not want to happen).

reef-pi supports multiple DS18B20 sensors. It is common to use two or three of these for redundancy. I have tested with up to 7 sensors.

Featured
### Waterproof 1-Wire DS18B20 Digital temperature sensor

[Waterproof 1-Wire DS18B20 Digital temperature sensor](https://www.adafruit.com/product/381)
This is a pre-wired and waterproofed (with heat shrink) version of a 1 Wire DS18B20 sensor. Handy for when you need to measure something far away, or in wet conditions. While the sensor is good up to 125°C the cable is jacketed in PVC so we suggest keeping it under 100°C. Because they...

In Stock
[Buy Now](https://www.adafruit.com/product/381)
[Related Guides to the Product](https://learn.adafruit.com/products/381/guides)
![Angled Shot of the Waterproof 1-Wire DS18B20 Digital temperature sensor.](https://cdn-shop.adafruit.com/640x480/381-01.jpg)

Featured
### Panel Mount 1/8" / 3.5mm TRS Audio Jack Connector

[Panel Mount 1/8" / 3.5mm TRS Audio Jack Connector](https://www.adafruit.com/product/3692)
What _is_ this TRS bit? **T** urtle **R** ock **S** tudios? **T** ransmission **R** aman **S** pectroscopy? Not quite, more...

In Stock
[Buy Now](https://www.adafruit.com/product/3692)
[Related Guides to the Product](https://learn.adafruit.com/products/3692/guides)
![Panel Mount 1/8 inch / 3.5mm TRS Audio Jack Connector](https://cdn-shop.adafruit.com/640x480/3692-01.jpg)

Featured
### 3.5mm (1/8") Stereo DIY Plug

[3.5mm (1/8") Stereo DIY Plug](https://www.adafruit.com/product/1800)
Repair or design your very own audio cables with these nice and durable phono-jack connectors. This is a great plug to make your own cable with. it's made out of durable metal with a flexible, sturdy spring for strain-relief. Just solder the connector to some wires and you have a DIY audio...

In Stock
[Buy Now](https://www.adafruit.com/product/1800)
[Related Guides to the Product](https://learn.adafruit.com/products/1800/guides)
![3.5mm stereo plug.](https://cdn-shop.adafruit.com/640x480/1800-00.jpg)

Featured
### Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft

[Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft](https://www.adafruit.com/product/1311)
Perfect for bread-boarding, free wiring, etc. This box contains **6** spools of **solid-core** wire. These&nbsp;spools of solid-core wires are&nbsp;easily soldered to,&nbsp;keeps its shape pretty well when bent&nbsp;and is rated 80C and 300V (UL AWM style 1007). We...

In Stock
[Buy Now](https://www.adafruit.com/product/1311)
[Related Guides to the Product](https://learn.adafruit.com/products/1311/guides)
![Hook-up Wire Spool Set in box with 6 colorful wires coming out](https://cdn-shop.adafruit.com/640x480/1311-04.jpg)

# reef-pi Guide 3: Temperature Controller

## Circuit Construction

The DS18B20 sensor circuit requires only a 4.7K resistor to work with Raspberry Pi. We'll use the extra space available in Perma-Proto HAT to mount the 4.7 K resistor as well as three male header pins which will be used to connect with DS18B20 GND, +Ve and data wires. The sensor itself will be wired with a male audio jack and will be used to connect with the female audio jack mounted in the&nbsp;enclosure.

Following is a Fritzing breadboard view of the circuit. Two of the male header pin are directly connected to GND and 3.3V while the 4.7K resistor is used as a pull-up resistor (from the 3.3V power) on the data pin, in the center.&nbsp;

Note: though we are using only a single DS18B20 sensor, it is possible to connect multiple sensors (I have tested with maximum 7 sensors). The wiring remains the same (since the underlying one-wire protocol is a bus).

![](https://cdn-learn.adafruit.com/assets/assets/000/062/401/medium800/sensors_Screen_Shot_2018-09-22_at_5.35.24_PM.png?1537663043)

### Prepare Connectors

Connect a male audio jack with DS18B20 sensor. Assuming the tip of the male audio jack is upward, the longest terminal of the jack represents GND, left terminal represents +Ve and the right terminal represents data. Tin the DS18B20 wires and male audio connector terminals before soldering them together

![](https://cdn-learn.adafruit.com/assets/assets/000/062/407/medium800/sensors_02145B0B-DC91-46A9-82FC-6142FB98B664.jpeg?1537761121)

This is how the temperature sensor will look once connected with a male audio jack

![](https://cdn-learn.adafruit.com/assets/assets/000/062/410/medium800/sensors_30D105BE-DCFF-4EAB-B8FF-4A9427D7814E.jpeg?1537761178)

We'll use a female panel mount audio connector to connect the temperature sensor.

![sensors_F711EAC9-3A69-4BCA-AE3C-71F508A2021B.jpeg](https://cdn-learn.adafruit.com/assets/assets/000/061/335/medium640/sensors_F711EAC9-3A69-4BCA-AE3C-71F508A2021B.jpeg?1537775258)

![](https://cdn-learn.adafruit.com/assets/assets/000/061/336/medium800/sensors_4EC398F5-2872-4147-9EB9-A5200EAEB5C1.jpeg?1536543813)

Solder the male end of three male-female jumper wires with the female audio jack. Strip the male end of jumper wires and tin both jumper wires as well as male audio jack terminals before soldering. Opposite to the male audio connector, when the female audio connector is arranged upwards, the longest terminal represents GND, left terminal represents +Ve, and right terminal represents data. Throughout this build, the data pin is represented by yellow wires which in turn connect to Raspberry Pi GPIO 4.

### Making DS18B20 circuit

We'll be using 22 AWG solid core wires as jumpers to connect all the pins. The yellow wire is used to connect GPIO 4 with central male header pin. A 4.7K pull up resistor is soldered perpendicular to save space.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/536/medium800/sensors_reef-pi1.jpg?1537898575)

Since we are extending the power controller circuit, the entire DS18B20 circuit sits on the left side of the Perma Proto HAT, with ULN2803A (used by power controller circuit) sitting in central location, occupying bulk of the HAT.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/406/medium800/sensors_B84ED5FB-7409-46BA-9570-F6B8E3130790.jpeg?1537761099)

![](https://cdn-learn.adafruit.com/assets/assets/000/062/535/medium800/sensors_image.png?1537898217)

Next, we'll mount the female audio jack in the enclosure.

# reef-pi Guide 3: Temperature Controller

## Building The Housing

The temperature controller only adds a single audio jack connector to the existing enclosure. Mounting the female audio connector is fairly easy. Drill a hole in the enclosure&nbsp;using a Dremel or drill driver. I prefer to keep all the connectors on the bottom side. In this case, the female audio jack is closer to the input power connector (a 2.1 mm barrel jack)

![](https://cdn-learn.adafruit.com/assets/assets/000/062/411/medium800/sensors_FAB41474-104C-42AC-9CB6-88310A320D50.jpeg?1537761204)

![](https://cdn-learn.adafruit.com/assets/assets/000/062/412/medium800/sensors_BAF9C5F6-4A91-4039-8828-C353E3D739A1.jpeg?1537761221)

Re-mount the PermaProto HAT (and Raspberry Pi attached with it) in the enclosure.

The female panel mount audio jack is threaded and comes with a nut to attach it on an enclosure, which makes it trivial to mount them on these plastic enclosures. Connect the audio jack's jumper wires with appropriate male header pins.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/413/medium800/sensors_74951E4C-F0CF-4E3E-B046-B99BED0108DF.jpeg?1537761249)

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/062/414/medium800/sensors_8DB55F8C-12B8-483C-9047-944096C06C8E.jpeg?1537761275)

That's it, once wired, our temperature sensor module is ready for field testing. Close the enclosure lid. This is how the end product will look:

![](https://cdn-learn.adafruit.com/assets/assets/000/062/415/medium800/sensors_B5435E6B-D33C-45B5-B5D9-28744E6322E1.jpeg?1537767515)

Next we'll move on to reef-pi software configuration of the temperature sensor.

# reef-pi Guide 3: Temperature Controller

## Configuration & Testing

Connect the temperature sensor with the enclosure and power up reef-pi.

Warning: 

Once up and running, make sure temperature capability is enabled. If not, enable it under the **settings** section of the **configuration** tab. Reload reef-pi every time **settings** are updated.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/525/medium800/sensors_Screen_Shot_2018-09-24_at_11.33.23_PM.png?1537857302)

Refresh your browser after reef-pi is reloaded and the **temperature** tab should appear. Navigate to the temperature tab and create a new temperature controller by clicking on the **"+"** button. A new temperature item should be available from the **Sensor** drop-down (DS18B20 sensors always have a name starting with 28-). The **enable** option represents whether reef-pi will check this sensor or not. Once enabled, the **Check Frequency** option represents how frequently (seconds) reef-pi should check for sensor value. Next, the **alert and control** option allows sending an alert if the temperature goes outside a specified range or turning on heater or cooling devices. For this example, we'll just enable sensor monitoring.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/419/medium800/sensors_Screen_Shot_2018-09-24_at_1.15.19_AM.png?1537776934)

Once created, the new temperature controller will appear in the list. We can now use this new temperature control to chart the sensor data.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/422/medium800/sensors_Screen_Shot_2018-09-24_at_1.19.48_AM.png?1537777321)

### Charts & Dashboard

reef-pi provides two types of charts for each temperature controller. The first type of chart is simply known as **temperature** which indicates the latest temperature at check interval granularity. reef-pi will store one days worth of data when check interval is set to 1 minute (1440 values).

The other temperature chart is known as **tc** or temperature controller. Temperature controller chart stores hourly average temperature along with heater and cooler usage (in seconds) for past thirty days.

Configure the main dashboard to enable both types of temperature chart for the new sensor.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/062/420/medium800/sensors_Screen_Shot_2018-09-24_at_1.17.59_AM.png?1537777153)

Click on **update** to save the new dashboard configuration and then click on **Back to dashboard**. You should see the temperature charts in the main dashboard now. The example images are taken from a controller running for a few days. For new builds, the charts will be have limited data.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/421/medium800/sensors_Screen_Shot_2018-09-24_at_1.18.50_AM.png?1537777165)

### Adafruit IO

Other than the in-controller dashboard, reef-pi also allows data logging to the [Adafruit IO data service](https://io.adafruit.com/). You can enable adafruit.io in the **telemetry** section under&nbsp;the **configuration** tab. You'll need to specify your adafruit.io username and AIO Key. Once enabled, reef-pi will start emitting data to adafruit.io. reef-pi will automatically create a feed named the same as temperature controller name and with a tc **-** prefix. This feed will hold the temperature data and can be used to create a dashboard in Adafruit.io. The following is an example temperature dashboard using Adafruit.io integration.

![](https://cdn-learn.adafruit.com/assets/assets/000/062/417/medium800/sensors_temp.png?1537776797)

Temperature is one of the key requirement for reef aquariums. With this feature, reef keepers will be able to understand and explore daily and seasonal aquarium temperature variation while having an extra safety net&nbsp;during heater failure.

In the next guide, we'll build the necessary automation for stabilizing the second most important parameter of reef aquariums, salinity.


## Guide Products

### Waterproof 1-Wire DS18B20 Digital temperature sensor

[Waterproof 1-Wire DS18B20 Digital temperature sensor](https://www.adafruit.com/product/381)
This is a pre-wired and waterproofed (with heat shrink) version of a 1 Wire DS18B20 sensor. Handy for when you need to measure something far away, or in wet conditions. While the sensor is good up to 125°C the cable is jacketed in PVC so we suggest keeping it under 100°C. Because they...

In Stock
[Buy Now](https://www.adafruit.com/product/381)
[Related Guides to the Product](https://learn.adafruit.com/products/381/guides)
### Panel Mount 1/8" / 3.5mm TRS Audio Jack Connector

[Panel Mount 1/8" / 3.5mm TRS Audio Jack Connector](https://www.adafruit.com/product/3692)
What _is_ this TRS bit? **T** urtle **R** ock **S** tudios? **T** ransmission **R** aman **S** pectroscopy? Not quite, more...

In Stock
[Buy Now](https://www.adafruit.com/product/3692)
[Related Guides to the Product](https://learn.adafruit.com/products/3692/guides)
### 3.5mm (1/8") Stereo DIY Plug

[3.5mm (1/8") Stereo DIY Plug](https://www.adafruit.com/product/1800)
Repair or design your very own audio cables with these nice and durable phono-jack connectors. This is a great plug to make your own cable with. it's made out of durable metal with a flexible, sturdy spring for strain-relief. Just solder the connector to some wires and you have a DIY audio...

In Stock
[Buy Now](https://www.adafruit.com/product/1800)
[Related Guides to the Product](https://learn.adafruit.com/products/1800/guides)
### Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft

[Hook-up Wire Spool Set - 22AWG Solid Core - 6 x 25 ft](https://www.adafruit.com/product/1311)
Perfect for bread-boarding, free wiring, etc. This box contains **6** spools of **solid-core** wire. These&nbsp;spools of solid-core wires are&nbsp;easily soldered to,&nbsp;keeps its shape pretty well when bent&nbsp;and is rated 80C and 300V (UL AWM style 1007). We...

In Stock
[Buy Now](https://www.adafruit.com/product/1311)
[Related Guides to the Product](https://learn.adafruit.com/products/1311/guides)

## Related Guides

- [DIY Desktop Calculator with CircuitPython ](https://learn.adafruit.com/diy-rpn-desktop-calculator-with-circuitpython.md)
- [BLE Volume Knob with CircuitPython](https://learn.adafruit.com/bluetooth-le-hid-volume-knob-with-circuitpython.md)
- [reef-pi Guide 2: Power Controller](https://learn.adafruit.com/reef-pi-power-controller.md)
- [Spinning Disc Step Sequencer](https://learn.adafruit.com/spinning-disc-step-sequencer.md)
- [Adafruit DS2484 I2C to 1-Wire Bus Adapter Breakout](https://learn.adafruit.com/adafruit-ds2484-i2c-to-1-wire-bus-adapter-breakout.md)
- [Feather Freezer Door Alarm](https://learn.adafruit.com/feather-door-alarm.md)
- [Analog Knobs on Raspberry Pi 400 with CYBERDECK Hat](https://learn.adafruit.com/analog-knobs-on-raspberrypi-400-with-cyberdeck-hat.md)
- [Robotic Xylophone with Adafruit Grand Central](https://learn.adafruit.com/robotic-xylophone-with-circuit-python.md)
- [Pico W HTTP Server with CircuitPython](https://learn.adafruit.com/pico-w-http-server-with-circuitpython.md)
- [Data Logging with Feather and CircuitPython](https://learn.adafruit.com/data-logging-with-feather-and-circuitpython.md)
- [reef-pi Guide 5: Light Controller](https://learn.adafruit.com/reef-pi-lighting-controller.md)
- [Adafruit QT Py Activity Timer and Hydration Reminder](https://learn.adafruit.com/qt-py-activity-timer-and-hydration-reminder.md)
- [No-Code Room Occupancy Status ](https://learn.adafruit.com/no-code-room-occupancy-status.md)
- [Scrambled Number Security Keypad](https://learn.adafruit.com/scrambled-number-security-keypad.md)
- [Reindeer Mask with Animated Eyes](https://learn.adafruit.com/reindeer-mask-with-animated-eyes.md)
