Go Down

Topic: Ramp - Soak, Beer brewing, single step mash sketch (Read 3515 times) previous topic - next topic

skyl4rk

I wrote a script to control a single step mash for brewing beer using the Arduino board. The input is from a thermistor and the output turns a pump and heater on.

This is less impressive than it sounds, because 1. I don't have a thermistor, 2. I don't have parts for a pump or heater control circuit, 3. I don't have a pump or electric heater and 4. I don't have an electric brewing system.

This script can turn on LED lights (which represent ON signals to the heater and pump) at the appropriate times. At this time I am using a potentiometer to represent a thermistor, so to check it I am manually adjusting the "temperature" while the script runs.

Actually, I have a draft three step mash script written, but I want to get my thermistor and adjust this script so it works with the values that the thermistor returns before I work out the bugs.

This script seems to work, I will just have to adjust the temperature values to match what the thermistor returns and change the times to fit real brewing times.

Code: [Select]

int T = 0;  //initialize variables, T is the input from the thermistor

int oneT = 600;   // oneT is the desired mash temperature, as returned by the thermistor and determined by measurement
int oneTmin = 580;  // the temp when you want the heater to kick in  
int oneTmax = 620;  // the temp when the heater should turn off

int oneS = 0;  // If oneS is 0, then the mash has not yet started.  If it is 1, then the mash has started.
int oneC = 0;  // If oneC is 0, then the mash is not yet complete.  If it is 1, then the mash is complete.

long startone = 0;  // placeholder for the starting time for mash 1
long stopone = 0;  // placeholder for the stop time for mash 1
long remaining = 0; // difference between startone and stopone
int remainsecs = 0;  // convert to something close to a second like integer

void setup(){  // run setup once
pinMode(4, OUTPUT);  // initialize pin 4 as output, will be used to trigger heater relay circuit
pinMode(8, OUTPUT);  // initialize pin 8 as output, will be used to trigger pump relay circuit
Serial.begin(9600);  // sends serial data to pc, allow for reading the temp and status as reported by Serial.print
}

void loop(){ // loop this as long as Arduino has power or until reset button is pressed
delay(3000); // 3 second delay between loops
T = analogRead(2);  // get voltage from thermistor
Serial.print("Temperature: ");  // print thermistor value to pc, this is not really temp but a number between 1 and 1024
Serial.print(T);
Serial.print("\n");

if (oneC == 1){  // if mash is complete, loop this
 digitalWrite(4, LOW);  // LOW tells board to output 0V on pin
 digitalWrite(8, LOW);
Serial.println("MASH STEP 1 COMPLETE");  // this prints out every 3 seconds when mash is done
}

if (oneC == 0){  // if mash is not complete do the next big loop
 if (oneS == 0){  // if mash has not been started, do this loop
   if (T < oneT){  // if temperature is less than mash temp, do this
   digitalWrite(4, HIGH); // HIGH tells board to output 5V on pin, this turns pump and heater on
   digitalWrite(8, HIGH);
   }
   if (T > oneT){ // if temp is more than mash temp, do this loop
   digitalWrite(4, LOW);  // turn off heat and pump
   digitalWrite(8, LOW);
   oneS = 1;  // start mash by toggling oneS to YES (or 1)
   startone = millis(); // start mash clock, reads milliseconds from this moment
   stopone = startone + 50000; // calculate the end of mash, here just an arbitrary 50000 milliseconds, later will be 3.6 million milliseconds or 60 minutes
   Serial.print("Started Mash Step 1 at ");
   Serial.print(millis());  // still need to convert this into human readable time, it is milliseconds now
   Serial.print("\n");
   }    
 }  
 if (oneS == 1){  // If mash has started do this loop, note we have already tested that mash has not completed.
 long curtime = millis(); // set variable curtime to the elapsed time since program started
 remaining = (-1)*(curtime - stopone); // caculate how many milliseconds until mash is complete
 remainsecs = (int)(remaining/1000); // convert into human readable second like intervals but not exact
 Serial.print(remainsecs);  // print it to screen
 Serial.print(" - ");
 Serial.print("Remaining");
 Serial.print("\n");  
 if (curtime < stopone){  // if we have not yet reached the end of the mash, do this
   if (T < oneTmin){  // if the mash temp is less than the minimum temp set in variables above, do this
     digitalWrite(4, HIGH); // pour on the heat
     digitalWrite(8, HIGH);
   }
   if (T > oneTmax){  // if mash temp is over the maximum temp set above, turn off the heat
     digitalWrite(4, LOW);
     digitalWrite(8, LOW);
   }
 }
   if (curtime > stopone){  // if we reach the end of the mash time
     digitalWrite(4, LOW);  // turn off the heat and pump
     digitalWrite(8, LOW);
     Serial.print("Stopped Mash Step 1 at ");  // print stop time (not really necessary or useful, just for checking)
     Serial.print(millis());
     Serial.print("\n");
     oneC = 1;  // set mash status to complete, or oneC to YES (1)
     Serial.print("\n");
     Serial.println("MASH STEP 1 COMPLETE");  // print this once every big loop
   }
 }  
}
}

skyl4rk

This is the uncommented version which works in Arduino.

Code: [Select]

int T = 0;

int oneT = 600;
int oneTmin = 580;
int oneTmax = 620;

int oneS = 0;
int oneC = 0;

long startone = 0;
long stopone = 0;
long remaining = 0;
int remainsecs = 0;

void setup(){
pinMode(4, OUTPUT);
pinMode(8, OUTPUT);
Serial.begin(9600);
}

void loop(){
delay(3000);
T = analogRead(2);
Serial.print("Temperature: ");
Serial.print(T);
Serial.print("\n");

if (oneC == 1){
 digitalWrite(4, LOW);
 digitalWrite(8, LOW);
Serial.println("MASH STEP 1 COMPLETE");
}

if (oneC == 0){
 if (oneS == 0){
   if (T < oneT){
   digitalWrite(4, HIGH);
   digitalWrite(8, HIGH);
   }
   if (T > oneT){
   digitalWrite(4, LOW);
   digitalWrite(8, LOW);
   oneS = 1;
   startone = millis();
   stopone = startone + 50000;
   Serial.print("Started Mash Step 1 at ");
   Serial.print(millis());
   Serial.print("\n");
   }    
 }  
 if (oneS == 1){
 long curtime = millis();
 remaining = (-1)*(curtime - stopone);
 remainsecs = (int)(remaining/1000);
 Serial.print(remainsecs);
 Serial.print(" - ");
 Serial.print("Remaining");
 Serial.print("\n");  
 if (curtime < stopone){
   if (T < oneTmin){
     digitalWrite(4, HIGH);
     digitalWrite(8, HIGH);
   }
   if (T > oneTmax){
     digitalWrite(4, LOW);
     digitalWrite(8, LOW);
   }
 }
   if (curtime > stopone){
     digitalWrite(4, HIGH);
     digitalWrite(8, HIGH);
     Serial.print("Stopped Mash Step 1 at ");
     Serial.print(millis());
     Serial.print("\n");
     oneC = 1;
     Serial.print("\n");
     Serial.println("MASH STEP 1 COMPLETE");

   }
 }  
}
}

big93

take a vid and post it, it sounds intresting...

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy