# Kombucha Thermostat with CircuitPython and Feather 

## Overview

Hi, [Rebecca Minich](https://rebeccaminich.com/) here! I'm moonlighting as the CircuitPython wiz Scott Shawcroft today so I can share my Kombucha thermostat project. If you are a fan of sour, this fermented drink might be for you. Unfortunately, it comes with the health food price tag of $3/bottle. Brewing it is much cheaper and way more fun!

For a healthy culture and delicious tasting 'buch you'll need to maintain a pretty high temperature (~77F/25C)&nbsp;while brewing (5-7 days). Keeping the brew that warm is challenging in colder climates. With a little help from a terrarium heater and some electronics, I created a thermostat for brewing year round. Check it out below!&nbsp;&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/851/medium800/temperature_schematic.jpg?1485915079)

## Parts Required

## 1. FOR KOMBUCHA BREWING:

- [Glass/Ceramic container](https://smile.amazon.com/gp/product/B0139APG2O/ref=oh_aui_detailpage_o01_s01?ie=UTF8&psc=1):&nbsp;I highly recommend a container with a spigot.&nbsp;
- [SCOBY and starter liquid](https://smile.amazon.com/gp/product/B009ZW8RP4/ref=oh_aui_detailpage_o07_s02?ie=UTF8&psc=1):&nbsp;I bought my SCOBY from a local vendor but I've used this one too.
- [Green](https://smile.amazon.com/gp/product/B001E5E38K/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1) or[black tea](https://smile.amazon.com/gp/product/B003SO4JBG/ref=oh_aui_detailpage_o06_s00?ie=UTF8&psc=1)&nbsp;
- Sugar: When first starting out it's best to use regular white cane sugar&nbsp;

## &nbsp;

## 2. FOR KOMBUCHA THERMOSTAT:

- [Terrarium heater](https://smile.amazon.com/gp/product/B00TR6AA5I/ref=oh_aui_detailpage_o08_s00?ie=UTF8&psc=1): I have this one but any low output heater will do.
- [PowerSwitch Tail 2](https://www.adafruit.com/products/268) &nbsp;
- [Adafruit Feather](https://www.adafruit.com/products/2796): &nbsp;I used the Adalogger in case I decide to store temperature data.&nbsp;
- [High Accuracy Temperature Sensor Breakout Board&nbsp;(MCP9808)](https://www.adafruit.com/products/1782): AKA thermometer
- [Micro USB to USB cord](https://www.adafruit.com/products/2008) and [AC wall adapter](https://www.adafruit.com/products/1994): &nbsp;An old phone/kindle charger works fine. &nbsp;
- [Jumper Extension wires](https://www.adafruit.com/products/826)
- [Wire Spool (optional)](https://www.adafruit.com/products/1311): Depending on your Kombucha setup you may need extra long connectors. I used wire spool between my Feather and my PowerSwitch Tail.&nbsp;
- Misc: [Small Phillips head screwdriver](https://www.adafruit.com/products/3284), electrical tape, infrared thermometer.

# Kombucha Thermostat with CircuitPython and Feather 

## Hardware Setup

## 1. BOARD ASSEMBLY

Board assembly is new for me so I had some help with this step. For the Feather, we went with [socket female headers](../../../../assets/30195). For the Temperature Sensor MCP9808 (Thermometer), plain male headers were used. Check out the assembly guides for more details: Feather&nbsp;[assembly guide](../../../../adafruit-feather-m0-adalogger/assembly)&nbsp;and MCP9808 thermometer [assembly guide](../../../../adafruit-mcp9808-precision-i2c-temperature-sensor-guide/overview).&nbsp; &nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/852/medium800/temperature_feather_2886-01.jpg?1485922790)

&nbsp;

## 2. LOAD CIRCUITPYTHON FIRMWARE AND DRIVERS:

If you're starting from scratch you will need to load the CircuitPython frimware onto your board. Start by plugging your feather into your computer with the micro USB cord. Next, use [this guide](https://learn.adafruit.com/welcome-to-circuitpython/non-uf2-installation)&nbsp;to install CircuitPython onto your Feather. If you're a beginner I STRONGLY suggest doing this on Mac OS in the terminal. Keep in mind CircuitPython is in development right now, if something doesn't make sense don't give up! Post on the Adafruit message boards and they will help you. &nbsp;

Once you have the firmware flashed onto your board your computer should recognize it as a USB mass storage device called CIRCUITPY. Next, load the drivers for your thermometer. To do this got to the Adafruit CircuitPython repository and download the [lastest CircuitPython bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle/releases). The file should look like this `<adafruit-circuitpython-bundle-#.#.#.zip>` where "#.#.#" will be the latest release number. Once downloaded, open the .zip file and drag and drop the **adafruit\_bus\_device** folder and the **adafruit\_mcp9808.mpy** file onto your board (see picture below).&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/847/medium800/temperature_CircuitPython_downloads.jpg?1485911479)

## 3. CONNECTING THE THERMOMETER TO THE FEATHER&nbsp;

Now that you have the firmware and drivers installed, disconnect your Feather from your computer and grab your thermometer and jumper extension wires. Use the wires to connect the Feather to the thermometer following the diagram below. The **VDD** and **GND** pins will power your thermometer through the Feather. The **SCL** pin is the I2C clock pin and the **SDA** pin is the I2C data pin. Pinout diagrams for the [Feather](../../../../adafruit-feather-m0-adalogger/pinouts) and the [thermometer](../../../../adafruit-mcp9808-precision-i2c-temperature-sensor-guide/pinouts)&nbsp;may be helpful at this point. If you're following my board assembly the male end of the jumper extension wires will go to the feather and the female ends will go to the thermometer.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/848/medium800/temperature_MCP9808_FeatherM0Adalogger.jpg?1485911532)

###### Diagram created with [Fritzing](http://fritzing.org/download/), Feather and MCP9808 diagrams are from the Adafruit [fritzing library](https://github.com/adafruit/Fritzing-Library/).&nbsp;
## 4. CONNECTING THE POWERSWITCH TAIL 2 TO THE FEATHER

For this step, it is important to know where your PowerSwitch Tail will plug-in in relation to your kombucha brew vessel and thermometer. For reference, my kombucha is in a cabinet about a meter away from an outlet. I used wire spool to connect my Feather to my PowerSwitch tail so it was the right length.&nbsp;Note: If you're using wire spool, you will have to [strip the ends](https://learn.sparkfun.com/tutorials/working-with-wire/how-to-strip-a-wire). &nbsp;

Now that you have the correct length of wire, connect pin **A5** on the Feather to the **PowerSwitch tail at 1: +in** , tighten the screw on the top until the wire is secure. Connect the lower left **ground pin (GND)** to the **PowerSwitch tail at 2: - in**. Again, tighten the screw until the wire is secure. There are a number of pins that you can use to connect your Feather to your PowerSwitch Tail, I chose **A5** because it was on the same side of the board as the ground pin. If you choose to use a different pin make sure you edit this in the code&nbsp;below.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/849/medium800/temperature_MCP9808_FeatherM0Adalogger_PST_CROP.jpg?1485911598)

###### Diagram created with [Fritzing](http://fritzing.org/download/), Feather, PowerSwitch Tail and MCP9808 diagrams are from the Adafruit [fritzing library](https://github.com/adafruit/Fritzing-Library/).
# Kombucha Thermostat with CircuitPython and Feather 

## Software Setup

At this point your electronics should be connected (PowerSwitch Tail, Feather and Thermometer) and your feather should have CircuitPython firmware and thermometer drivers installed.

## 1. GETTING STARTED&nbsp;

Plug your Feather into your computer with a Micro USB cable. The Feather will show up on your computer as a USB mass storage device called "CIRCUITPY". Open a new text file in the editor of your choice (I use &nbsp;[Atom](https://atom.io/)) and save it to the CIRCUITPY drive as `code.txt`. To see the output of your Feather while coding you will need to connect a serial read–eval–print loop (REPL). If you are not sure how to open the serial REPL follow [this guide](../../../../micropython-basics-how-to-load-micropython-on-a-board/serial-terminal). Once you have your code.txt file saved to your Feather (CIRCUITPY drive) and the serial REPL open you are ready to code!&nbsp;

## 2. CONNECT THE THERMOMETER:

In your `code.txt` file use the code below to import the thermometer and supporting libraries. This will also import the I2C protocol from busio and rename the thermometer output (here we used t). Save the code to your Feather and check to see that the temperature is printed in your serial REPL. &nbsp; &nbsp;

```auto
# Load the libraries we need.
import adafruit_mcp9808
from board import *
import busio
import digitalio
import time

# Do one reading and print it out.
with busio.I2C(SCL, SDA) as i2c:
    t = adafruit_mcp9808.MCP9808(i2c)
    print("temperature in celsius:", t.temperature)
```

## 3. CONNECT TO THE LED AND THE POWERSWITCH TAIL

For this section you do not need to have the PowerSwitch Tail plugged into the wall, the microcontroller will power its LED. This code labels your indicator LED at pin D13 and switches it to output. Next, it connects the PowerSwitch Tail to the Feather through pin A5. If you used a different pin to connect to the PowerSwitch Tail, you will need to change the code here (edit A5).&nbsp;&nbsp;

```auto
    led = digitalio.DigitalInOut(D13)
    led.switch_to_output()
    power = digitalio.DigitalInOut(A5)
    power.switch_to_output()
```

## 4. WRITE THE CODE FOR THE THERMOSTAT&nbsp;

I wanted to use as little power as possible to make my heater smart so I am using a pretty simple thermostat. First, the while loop creates an infinite loop for the microcontroller. Inside the loop, the &nbsp;temperature sampling is delayed to every 5 minutes with a sleep function. Since I am dealing with a large vat of tea, the temperature shouldn't fluctuate very much. To test your sensor you may want to change the `time.sleep()` function to something shorter or comment it out. As is, the print statement will output the temperature to the serial REPL every 5 minutes. The print statement is helpful during setup but can be commented out when you save the code to your board.&nbsp; The thermostat is a simple if/elif statement which turns the power on if the temperature falls below 24.5C and turns the power off if the temperature is over 26.5C. This works for me but if you are looking for something more exact you can may consider a PID function:&nbsp;

```auto
    while True:
          #setting 5 minutes delay for temp sampling
          time.sleep(300)
          print (t.temperature)
          if t.temperature < 24.5:
              power.value = True
              led.value = True
          elif t.temperature > 26.5:
              power.value = False
              led.value = False

```

Here is all of the code put together:&nbsp;

```auto
# Load the libraries we need.
import adafruit_mcp9808
from board import *
import busio
import digitalio
import time

# Do one reading and print it out.
with busio.I2C(SCL, SDA) as i2c:
    t = adafruit_mcp9808.MCP9808(i2c)
    print("temperature in celsius:", t.temperature)

    led = digitalio.DigitalInOut(D13)
    led.switch_to_output()
    power = digitalio.DigitalInOut(A5)
    power.switch_to_output()

    while True:
        #setting 5 minutes delay for temp sampling
        time.sleep(300)
        print (t.temperature)
        if t.temperature < 24.5:
          power.value = True
          led.value = True
        elif t.temperature > 26.5:
          power.value = False
          led.value = False
```

# Kombucha Thermostat with CircuitPython and Feather 

## Connecting the Pieces 

## 1. TESTING THE THERMOSTAT

Start by plugging your Feather into the wall socket with the micro USB AC adapter. If you have an infrared thermometer this would be a good time to use it. Measure the temperature of your thermometer and make sure it is behaving like you expect. If you don't have an infrared thermometer try this:

Check for the OFF position - To increase the temperature hold the thermometer in your closed hand, it should exceed 27C (~80F)&nbsp;quickly and the power should turn off. When the power is off the red indicator light on the PowerSwitch Tail AND the LED light on the Feather should be OFF.

Check for the ON position - Place the thermometer, temperature sensor side down, on a cold surface (a hard counter or window should work, if not, try the fridge).&nbsp;Once the temp is below 24.5 C (~75F) the power should turn ON. When the power is ON both the indicator light on the PowerSwitch Tail AND the LED on the Feather should be ON.&nbsp;

## 2. CONNECT THE HEATER AND ASSEMBLE THE PIECES.

If you're confident that your thermometer and thermostat code are functioning you can start connecting the pieces. The schematic below is an overview of my setup. Start by securing your thermometer to your kombucha brew vessel with electrical tape. Make sure the temperature sensor is touching the brew vessel. Next attach your heater to the kombucha vessel. Plug the PowerSwitch tail into the wall outlet and plug the heater into the PowerSwitch Tail. Next plug your Feather into a wall outlet with the micro USB AC adapter. Observe your thermostat over the next few days to ensure that everything is functioning normally. Last but not least, brew for 5-7 days, and ENJOY YOUR 'BUCH!&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/038/850/medium800/temperature_KombuchaFritz.jpg?1485912181)

# Kombucha Thermostat with CircuitPython and Feather 

## Troubleshooting 

# F. Troubleshooting and Further Reading

Having trouble? Here are some great resources to get your thermostat up and running:

## 1. SIMILAR MAKER PROJECTS:

- [On-Air Streaming Sign with PowerSwitch Tail](../../../../internet-streaming-on-air-sign?view=all#hardware-setup): This is a really good starting point for learning a bit about the capabilities of the PowerSwitch Tail.&nbsp;
- [Sous Vide](../../../../sous-vide-powered-by-arduino-the-sous-viduino/sous-vide): Looking for a more robust thermostat? This guide uses a PID algorithm to keep the water bath at a very precise temperature.&nbsp;

## 2. HELP WITH CIRCUITPYTHON (MICROPYTHON):&nbsp;

- [MicroPython Basics: What is MicroPython?](../../../../micropython-basics-what-is-micropython/overview)
- [MicroPython Basics: Blink a LED](../../../../micropython-basics-blink-a-led/overview)
- [MicroPython Basics: Load Files & Run Code](../../../../micropython-basics-load-files-and-run-code/overview)
- [CircuitPython documentation](https://circuitpython.readthedocs.io/en/latest/shared-bindings/nativeio/ __init__.html)

## 3. HELP BREWING KOMBUCHA&nbsp;

- [pH for Kombucha](http://www.organic-kombucha.com/kombucha_and_ph.html)
- [How to Tell if Your SCOBY is Healthy](http://kombuchahome.com/signs-of-a-healthy-kombucha-brew/)
- [Best Types of Sugar for Your Brew](http://kombuchahome.com/types-of-sugar-to-use-for-brewing-kombucha/)
- [Trouble Shooting Guide](http://users.bestweb.net/~om/kombucha_balance/)&nbsp;


## Related Guides

- [Adafruit Feather M0 Adalogger](https://learn.adafruit.com/adafruit-feather-m0-adalogger.md)
- [NeoPixel Novelty Cufflinks with Scrolling Text](https://learn.adafruit.com/neopixel-novelty-cufflinks-with-scrolling-text.md)
- [Synchronized NeoPixel Shoelaces with WLED](https://learn.adafruit.com/neopixel-shoelaces-with-wled.md)
- [NYE Circuit Playground Drop](https://learn.adafruit.com/nye-circuit-playground-drop.md)
- [Simple Vertical Wordclock](https://learn.adafruit.com/vertical-wordclock.md)
- [reef-pi Guide 3: Temperature Controller](https://learn.adafruit.com/reef-pi-guide-3-temperature-controller.md)
- [Make It Glow: How to Solder NeoPixels, A Beginner's Guide](https://learn.adafruit.com/make-it-glow-how-to-solder-neopixels-a-beginners-guide.md)
- [ANO Directional Navigation and Scroll Wheel Rotary Encoder and Breakout](https://learn.adafruit.com/ano-rotary-encoder.md)
- [Adafruit Metro ESP32-S3](https://learn.adafruit.com/adafruit-metro-esp32-s3.md)
- [Data Logging with Feather and CircuitPython](https://learn.adafruit.com/data-logging-with-feather-and-circuitpython.md)
- [LED Matrix Scoreboard](https://learn.adafruit.com/led-matrix-scoreboard.md)
- [reef-pi Guide 5: Light Controller](https://learn.adafruit.com/reef-pi-lighting-controller.md)
- [Fog Machine with Motion Sensor and Adafruit IO](https://learn.adafruit.com/fog-machine-remote-trigger.md)
- [Compost Friend!](https://learn.adafruit.com/compost-optimization-machine.md)
- [Adafruit Chainable DS18B20 Extender Breakout](https://learn.adafruit.com/adafruit-chainable-ds18b20-extender-breakout.md)
- [Chinese Dragon Puppet with Motion-Reactive Flame Effect](https://learn.adafruit.com/chinese-dragon-puppet-with-motion-reactive-flame-effect.md)
