New automated home-brewery - Hardware suggestions please

OK so I think I have the joystick sorted. Basic operation is:
push button to release joystick to allow changes to be made, up/down/left/right - increase/decrease the X/Y value by one (can be held down and it will keep changing every 0.2s), push button again to lock joystick so movement will not change values.
I'll post code tonight.
Cheers!

Can anyone comment on my code and suggest if I am doing things "wrong"
Cheers!

//Global variables

int ledPin = 13;
int JoyPinx = 0;                 // Horizotal pot connected to analog pin 0
int JoyPiny = 1;                 // Vertical pot connected to analog pin 1
int JoyPinb = 2;                // Switch connected to digital pin 2
int Joy_x = 0;                   // variable to read the value from the analog pin 0
int Joy_y = 0;                   // variable to read the value from the analog pin 1
int Joy_b = 0;                   // variable to read the value from the analog pin 1
int X_value = 50;                //Initial X value
int Y_value = 50;                //Initial Y value
// Variables for button debounce
unsigned long Time_x_previous = 0;
unsigned long Time_y_previous = 0;
unsigned long Time_b_previous = 0;
unsigned long Debounce = 200;
// Variables for updating serial 
boolean Disp = false;
boolean Disp_e = false;
boolean B_state = false;


void setup() {
  pinMode(JoyPinb, INPUT_PULLUP);      // initialize the pushbutton pin as an input
  Serial.begin(9600);             //Start serial comms
}

void loop() {

  // Check for button push to release/freeze joystick
  if(digitalRead(JoyPinb) != HIGH){
    if(millis() - Time_b_previous > Debounce){
      B_state = !B_state;
      Time_b_previous = millis();
    }
  }

  // if joystick released read the value of the X-axis variable resistor and adjust X value
  Joy_x = analogRead(JoyPinx);    
  if(Joy_x > 600 || Joy_x < 300){
    if(B_state == true){
      if(millis() - Time_x_previous > Debounce){
        if(Joy_x > 600 && X_value < 100){
          X_value++;
        }
        else if(Joy_x < 300 && X_value > 0){
          X_value--;
        }
        Time_x_previous = millis();
        Disp = true;
      }
    }
    else {
      Disp_e = true;
    }
  }

  // if joystick released read the value of the Y-axis variable resistor and adjust Y value
  Joy_y = analogRead(JoyPiny);   // reads the value of the y-axis variable resistor 
  if(Joy_y > 600 || Joy_y < 300){
    if(B_state == true){
      if(millis() - Time_y_previous > Debounce){
        if(Joy_y > 600 && Y_value < 100){
          Y_value++;
        }
        else if(Joy_y < 300 && Y_value > 0){
          Y_value--;
        }
        Time_y_previous = millis();
        Disp = true;
      }
    }
    else {
      Disp_e = true;
    }
  }  
  // if X or Y value has changed update serial monitor
  if (Disp == true){
    Serial.print(X_value);
    Serial.print(" ");
    Serial.println(Y_value);
    Disp = false;

  }
  // If joystick is moved without being release display message
  if (Disp_e == true){
    Serial.println("Joystick not released");
    Disp_e = false;

  }
}

So 6 months later and no real progress on the control side of things. As far as the rest of the physical work I have the frame/pump/etc. made. It has made brewing 100x easier.
Update on what is coming up next. One issue is currently my thermocouple is place after the pump – normally during brewing this is not an issue until I go to cool down the wort. What I do is pump the hot wort through a plate heat exchanger (chiller) and back into the kettle until I reach a point when the wort coming out the chiller is ~18°C and ready to be pumped to the fermenter. With my current setup I only know the temp going into the chiller not coming out, so it is a bit of a guessing game when to swap from recirculating to pumping to the fermenter. This is where the project picks back up. So over the next couple of months my plan is to tackle the lack of post chiller temp reading. Plan:

  1. Get the TFT LCD up and running (bought a Elec Freaks shield), using the Henning Karlsen UTFT, UTouch and UTFT_Buttons libraries
  2. Build a DS18B20 thermowell sensor using a “Swagelok” compression fitting
  3. Install above sensor in kettle return,
  4. Write code to display temp on TFT LCD
  5. I have also got some casters to add to the stand to make moving it around easier,

I will continue to run the “brewery” with the old “dumb” control panel and slowly incorporate more sensing and then controls. List of tasks to complete:

  1. Stuff above,
  2. Add flow monitoring
  3. Add pump speed control – PWM
  4. Replace thermocouple with 2nd DS18B20 sensor
  5. Add heating element control x2 – 1x on/off, 1x PWM
  6. Add PID temperature control of PWM element (on/off element control on set point)
  7. Add PID flow control of pump

Items 1-3 will be standalone. When I get to items 4-7 I will likely need to scrap the old control panel and swap over to a new “smart” panel.

Here are some photos of the current brewery as a reward for anyone that has bothered to sit through my ranting :grin:

“Dumb” Control Panel

Current brewery

Pump and thermocouple

Plate heat exchanger (chiller)

Brewing (Wychwood Hobgoblin clone)!

Hops being added

Also my mate is building his system based off of the BCS controller - http://www.embeddedcontrolconcepts.com/. My goal is to surpass his system in terms of function, my main points of differences will hopefully be

  1. Local touch screen control vs. web-based control needing an additional device (tablet / laptop)
  2. Flow monitoring & control
  3. Visual details of flow path (which hose goes where) for each step in the process

Interesting project. I can't figure out what the PWM/PID control of the pump is for though. Fine control of the chilling process?

wildbill:
Interesting project. I can't figure out what the PWM/PID control of the pump is for though. Fine control of the chilling process?

Control of the lauetering, I don't want to pump out of the mash/lauter tun too fast and get a stuck sparge (grain bed collapsing and not allowing the sweet wort to flow through it).
Typically for fly sparging you want (IIRC) 1qt/min (batch sparging can be higher), my pump puts out approx 32+ qt/min without any control. Most use a ball valve to throttle this back but I would like to try reduce the speed/power to the pump to reduce the flow. I need to run some test with a router speed control I have to check flowrate at the lowest possible motor speed that won't kill the motor. :slight_smile:

Soooooooooo... About time for an update to collect my thoughts :slight_smile:
I have tackled a few of the items on the list. I have got the temp probe made and connected to the ardunio, plus the flowmeter. I need to write some simple code to take the readings from both and display on the LCD, shouldn't be too hard...
I'll set myself a goal of 2 weeks to get both of these hooked up in a temporary box and displaying "stuff". So in 2 weeks I should have completed 1-4 from the first list and 2 from the second. From there I will need to buy a few more bits (relay board, SSR - both zero crossing and non-zero crossing, a better box to house it all in!) to complete the rest so it may be another while till anyone hears from me after 2 weeks.
Cheers!

This is very simliar to what i plan. Im very intested in how your getting on with this

Pesh

Just thinkin about the comment you made about the wort temp after the chiller im thinkin of putting a temp probe in there and adding a feed back loop back in to the copper back (like a rims set up) then do a temp read at chiller outlet and if temp >20c run wort back in to copper back (and back throught the chiller) or if temp =<20 run wort in to the fermentor, shouldnt be too hard (or expensive) to do.

Pesh

So... Yeah... 8 weeks! Should have know I wouldn't meet my deadline as I had 2 weddings, 1 overseas trip, 1 extra wedding party, 1 stag do and a whole lot of other stuff on :astonished:
But I have just got the temp displaying on the LCD, photos below. I thought I ran into a issue with the flow meter, as I mistakingly thought that the LCD sheild used all the interupt pins but I just double checked and saw there are in fact 2 spare that can be used so I will need to go back in include the flow as well.
Code is just hacked up examples at the moment so no point sharing as it would cause more confusion than help :blush:
I noticed that the DS18B20 is about 10x quicker to react to a temperature change.
So From my original list I have completed first list 1-4, and on my way with number 2 on the second list... it's coming together...slowly!
Need to buy a relay board capable of 240V 10A and the pump SSR and a box to store it all in.
Anyway on to the pictures

Pesho77:
Just thinkin about the comment you made about the wort temp after the chiller im thinkin of putting a temp probe in there and adding a feed back loop back in to the copper back (like a rims set up) then do a temp read at chiller outlet and if temp >20c run wort back in to copper back (and back throught the chiller) or if temp =<20 run wort in to the fermentor, shouldnt be too hard (or expensive) to do.

Pesh

Hi Pesh, glad you are interested in this (sorry that it takes me so long to do anything with it!)
I think you have summed up what my process will be. Currently I have a temp probe on the kettle return only which means I can divert it from returning to the kettle once the wort is down to pitching temp. I am adding a second probe before the chiller so if I want to do a whirlpool hop addition (say drop the wort to 70°C and add a bunch of hops for a 30 minute rest) I can easily tell when to stop the chilling water. I attached a quick sketch of the 2 temperature probe placements. What is your set up like?

TEMP.jpg

Goal achieved! Flow measurement is now included (just need to water test and calibrate now :roll_eyes:)
one small issue was with the TFT.h printNumI function will print only one number for single digits numbers... makes sense. But unless you clear the screen or something else the second digit of a two digit number will stay around and confuse the hell out of you (why is it saying I have 4 l/min when there is obviously no flow??????). Fix was to print blanks, e.g. print(" "), over the old value before printing the new one. But this also caused a flicker when the values were overprinted, so to solve that I added a if statement to only change the value if it had changed.
I'll tidy up the code in the nest few days and then post it up :smiley:
Cheers everyone!

Code cleaned up and included below.
Cheers!

/*
 D2 Brewing - Homebrew temperature and flow measurement

 Hardware
 Arduino Mega 2560
 SSD1289 3.2" TFT LCD (with ElecFreaks sheild)
 Temperature - DS18B20 Dallas 1-wire temperature sensor
 Flow - Saier SEN-HZ 21 WA flowmeter (ebay - similar to Seedstudios 1/2" flowmeter)

 Flow and temperature is polled every 0.1 seconds and updated to a 3.2" TFT LCD screen

 Libraries used:
 UTFT.h - http://www.henningkarlsen.com/electronics
 OneWire.h
 DallasTemperature.h

 Pin connections
 LCD - Elecfreaks TFT101 v2.0 Sheild (Mega)
 DS18B20 - Digital 8
 Flowmeter - Digital 18 (interupt 5)
 */

//include required libraries
#include <UTFT.h>
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is plugged into digital IO 8 on the Arduino
#define ONE_WIRE_BUS 8
// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) and Pass our oneWire reference to Dallas Temperature.
OneWire DS(ONE_WIRE_BUS);
DallasTemperature sensors(&DS);

// arrays to hold device addresses
DeviceAddress Thermometer;

//Global variables
int temp = 0;
int tempOld = 0; //Temp value to check if changed for LCD refresh
int time = 0; //Time value to check for polling sensors
volatile int flowTicks; //measuring the rising edges of the signal
int flow;
int flowOld; //Flow value to check if changed for LCD refresh
int hallsensor = 18;    //The pin location of the sensor

// Initilise up UTFT and declare which fonts we will be using
UTFT          myGLCD(SSD1289,38,39,40,41);
extern uint8_t SmallFont[];
extern uint8_t BigFont[];
extern uint8_t Dingbats1_XL[];

void setup()
{
  //Start LCD and print "background"
  myGLCD.InitLCD();
  myGLCD.clrScr();
  sensors.begin();
  myGLCD.setColor(VGA_BLACK);
  myGLCD.setBackColor(VGA_WHITE);
  myGLCD.setFont(SmallFont);
  myGLCD.print("Temperature °C", 10, 10);
  myGLCD.print("Flow L/min", 10, 100);
  myGLCD.setFont(BigFont);

  pinMode(hallsensor, INPUT); //initializes digital pin 18 as an input
  attachInterrupt(5, rpm, RISING); //initialise interupt 5 (Mega2560 pin 18)
  sei();      //Enables interrupts
}

void loop()
{
  //Poll sensors if more than 0.1 seconds since last
  if(millis() - time > 100)
  {
    flow = (flowTicks / 7.5); //Pulse frequency = 7.5 x flow rate (L/min)
    sensors.requestTemperatures(); //get all 1-wire temperatures
    temp =  sensors.getTempCByIndex(0); //get first indexed sensors temperature (only 1 sensor available)

    //Update LCD if temperture has changed
    if(temp != tempOld)
    {
      myGLCD.print("  ", 160, 10);
      myGLCD.printNumI(temp, 160, 10);
      tempOld = temp;
    }
    //Update LCD if flow has changed
    if(flow != flowOld)
    {
      myGLCD.print("  ", 160, 100);
      myGLCD.printNumI(flow, 160, 100);
      flowOld = flow;
    }
    flowTicks = 0; //reset flow valuew
    time = millis(); //update time of last polling
  }
}

//This is the function that the flow sensor interupt calls
void rpm ()
{
  flowTicks++;  //This function measures the rising and falling edge of the hall effect sensors signal
}

Just water tested the flow sensor now and looks pretty good. Got 12 L/min which looks about right for the Iwaki/Resun MD40 pump I am running. I then reduced the power using a triac dimmer and the pump would run comfortably at 8 L/min (about 67% of total flow) and could push it down to 5 L/min but I would be worried that the motor fan wouldn't be cooling it enough for long term use.
Bit of a bugger as I would probably like around 4-5 L/min for lautering (but my pump is much bigger than the normal pumps run on my size home brewery), but good to know that this method could potentially allow for a reliable 33% reduction in flow with purely electronic methods.

My setup is still in the planning stage, but will end up as a 3 burner direct gas fired rims set up i want 2 displays to read fill levels of HLT and M/LT then change to Ltr's/MIn for sparge, and one display just for rims Ltr's/min, im using a bsc460 to control heat and arduino to do all the water.

I plan to input the total fill volume via buttons in to the HLT, then do M/LT fill volume then use a "start" button to set things off this will then fill HLT when full it should transfer the water to the M/LT then heat to 65c (or 50c for lager) and start the rims pump, then pause for me to mash in (turinig off the heat and pump) i then want to very slowly run the rims pump up to 2-3 Ltr's/min i want that to be as slow a run up as i can then ramp heat to 72c ish then mash out at 77c ish then open the tap on the HLT then M/LT to sparge after about 2-5 mins of sparge i want the BK to heat till 100c then pause till i add the hops then boil for 1 hour then chill to pitching temp.

If i get all that right ill only need to be there to start thing off mash in and add the hops, the rest of the time i can up my feet up.

Im looking for a way to remotely observe the kit through my lap top so see whats happening a simple gui it only needs to display what valves are open and flow rates i can see temps through the bsc main page already , and i have a wireless web cam so i can see the kit on a video feed. Ive been advised to use python to make a GUI but for now im trying to make a GUI for a kit before i have the kit so im putting that on hold till the kits ready ill post if i ever get it done.

Pesh

Hi to every one, this is a dumb question, im new in this forum, also with arduino, but im a brewer, my mayor question is if you can realy program a code for a brewery automatitacion, using the libraries of the dallas sensor, so how can i start ??

i want to control 2 pumps, some selenoids and a cuple of pumps, but how can you program an alarm to tel you that you have al ready mash for 45 minutos at 65 °C, is this posible?, and then the hops adition whith a back count?, please help!! thanks!