Howto: Sample code to control Motorized Ball Valve using BrewPi valve control expansion board


Hi All,

I have:


I was after some sample code, to help me control the valve using a (Spark) Particle Photon. Just simply opening and closing it.

I already have a BrewPi working away as a fermenter. I also currently have code on a Photon controlling a relay and taking temperature reading’s from DS18B20’s. Next step is to control the motorized ball valve and I can do my own little ghetto brew controller. I know the BrewPi will eventually do all this, but I can’t wait, and would also like to tinker in the mean time.

If this has already been covered in another thread, please link me to that. Or even an external website.



The valve control board can be set up as a cooler or heater in the latest version of BrewPi.

The code for the valve controller is part of the firmware here:


Hi Elco,

Thanks for the reply!!!

So, as I’m a newby could I use to do this? Or is there a better environment to do this in?

I was thinking of importing the following into my project:
#include “DS2408.h”
#include “ActuatorInterfaces.h”
#include “ControllerMixins.h”
#include “ValveController.h”

I noticed ControllerMixins.h is not in the page.

On another note, is there some info on where I would need to wire the RJ12 plugs into my particle?



I’m not sure, I haven’t tried that.
You can include the this file with empty mixins:

On the Spark we use a OneWire bus master IC and not do OneWire with bare microcontroller pins, for increased reliability. So it will not be a simple include and it works.

The DS2408 class takes a pointer to a OneWire class that provides the bus. You could provide one that implements pin OneWire.

You know you can add the OneWire board in the device manager for the BrewPi Spark, right? You can set it up as heater, cooler or manual actuator. If you set it up as manual actuator you get an open and close button in the device list.