Kombucha Thermostat with CircuitPython + Feather

schematic.jpg

A. Background 

If you are a fan of sour, kombucha might be the drink 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) 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!  

 

B. Parts Required

1. For Kombucha Brewing:

2. For Kombucha Thermostat:

 

C. 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.  For the Temperature Sensor MCP9808 (Thermometer), plain male headers were used. Check out the assembly guides for more details: Feather assembly guide and MCP9808 thermometer assembly guide.   

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 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.

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. 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). 

3. Connecting the Thermometer to the Feather 

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 and the thermometer 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. 

Diagram created with Fritzing, Feather and MCP9808 diagrams are from the Adafruit fritzing library

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. Note: If you're using wire spool, you will have to strip the ends.  

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 (see below). 

Diagram created with Fritzing, Feather, PowerSwitch Tail and MCP9808 diagrams are from the Adafruit fritzing library

 

D. Software  

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 

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  Atom) 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. Once you have your code.txt file saved to your Feather (CIRCUITPY drive) and the serial REPL open you are ready to code! 

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 nativeio 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.    

# Load the libraries we need.
import adafruit_mcp9808
from board import *
import nativeio
import time

# Do one reading and print it out.
with nativeio.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).  

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

4. Write the code for the thermostat 

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  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.  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: 

    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 it is the code all together, it's easier to see the indentation this way: 

# Load the libraries we need.
import adafruit_mcp9808
from board import *
import nativeio
import time

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

    led = nativeio.DigitalInOut(D13)
    led.switch_to_output()
    power = nativeio.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

 

E. 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 a 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) 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). 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. 

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 PowersSwitch 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! 

 

F. Troubleshooting and Further Reading

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

1. Similar Maker Projects:

  • On-Air Streaming Sign with PowerSwitch Tail: This is a really good starting point for learning a bit about the capabilities of the PowerSwitch Tail. 
  • Sous Vide: Looking for a more robust thermostat? This guide uses a PID algorithm to keep the water bath at a very precise temperature. 

2. Help with CircuitPython (MicroPython): 

3. Help brewing kombucha 

New Years or BUST!

After a week of babysitting, eating junk food, and burning the candle at both ends it's no surprise I ended up with a cold to start off the new year! This seriously addictive 'mermaid' pillow is a kinesthetic dream that kept me occupied while I relaxed in bed #giftingwin. Although my new year started off slow, here's to a productive, healthy, happy January!! 

#tbt to that one time some Thai elephants stole a snack!

Elephants are sneaky for such big animals. That white bag in front of the mahout was swiftly lifted from the feed truck (not shown) and the watermelon smash began! The elephants were so excited, they definitely knew they'd gotten away with something. I'm not sure they actually got to EAT any of the watermelons but they sure enjoyed making watermelon juice out of them! This was taken at the Elephant Nature Park in Chiang Mai, Thailand - April 2016 

December is here!

I've been back in the united states for five months today! It is absolutely astonishing how fast the last few months have gone. I am working hard to hone my skills and patiently awaiting my next adventure. In lieu of that here is a #tbt to my adventures in India. The India gate in New Delhi was beautiful and the merchants constantly harassing me made for good subjects.