Home Brew Forums

Home Brew Forums (http://www.homebrewtalk.com/forum.php)
-   Electric Brewing (http://www.homebrewtalk.com/f170/)
-   -   Arduino, PID, or other? (http://www.homebrewtalk.com/f170/arduino-pid-other-313671/)

matho 03-21-2012 06:11 AM

1 Attachment(s)

Islandboy keep your head up, I found it daunting when I started but after a couple of months I have a good idea about programming the arduino. If you want plug and play then go for a PID but if you want to go for the custom look then use the arduino.The good thing about the arduino is you can build what you want, you can add a number of temperature probes( not just one like the PID) and you can control a number of outputs Here is a simple code for a thermostat that is PID controlled, it has all the building blocks you will need.

Quote:
//a simple thermostat
#include LiquidCrystal.h>
#include OneWire.h>
#include
OneWire ds(11);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
//*push*buttons
const int Button_up = A3;
const int Button_dn = A2;
const int Button_prev = A1;
const int Button_nxt = A0;
const int Heat = 9;
// variables
int WindowSize = 5000;
unsigned long windowStartTime;
double Setpoint, Input, Output;
boolean Start = false;
boolean Conv_start = false;
float set_temp = 20;
float Temp_c;
int temp;
byte data[2];
byte i;
byte Busy = 0;
//Specify the links and initial tuning parameters
PID myPID(&Input, &Output, &Setpoint,200,5,3, DIRECT);

void setup(void)
{
// Start up the library
l
cd.begin(16,2);
pinMode (Button_up,INPUT);
pinMode (Button_dn,INPUT);
pinMode (Button_prev,INPUT);
pinMode (Button_nxt,INPUT);
pinMode (Heat,OUTPUT);
windowStartTime = millis();
//tell the PID to range between 0 and the full window size
myPID.SetOutputLimits(0, WindowSize);
myPID.SetMode(AUTOMATIC);
}
void loop(void)
{
Temperature();
Setpoint = set_temp*16;
Input = Temp_c * 16;
lcd.setCursor(0,0);
lcd.print("Set Temp =");
lcd.setCursor(10,0);
lcd.print(set_temp);
lcd.setCursor(0, 1);
lcd.print("Temp =");
lcd.setCursor(7,1);
lcd.print(Temp_c);
if (!(digitalRead(Button_up))&& !(Start))
{
while (digitalRead(Button_up)==0){
}
set_temp= set_temp+0.25;
}
if (!(digitalRead(Button_dn))&& !(Start))
{
while (digitalRead(Button_dn)==0){
}
set_temp= set_temp-0.25;
}
if (digitalRead(Button_prev)==0)
{
while (digitalRead(Button_prev)==0){
}
Start = true;
}
if (digitalRead(Button_nxt)==0)
{
while (digitalRead(Button_nxt)==0){
}
Start = false;
digitalWrite(Heat,LOW);
}
if (Start)
{
PID_HEAT();
}

}
void Temperature(void)
{
ds.reset();
ds.skip();
// start conversion and return
if (!(Conv_start)){
ds.write(0x44,0);
Conv_start = true;
return;
}
// check for conversion if it isn't complete return if it is then convert to decimal
if (Conv_start){
Busy = ds.read_bit();
if (Busy == 0){
return;
}
ds.reset();
ds.skip();
ds.write(0xBE);
for ( i = 0; i // we need 2 bytes
data[i] = ds.read();
}
unsigned int raw = (data[1] Temp_c = (raw & 0xFFFC) * 0.0625;
Conv_start = false;
return;
}
return;
}
void PID_HEAT (void){
myPID.Compute();
/************************************************
turn the output pin on/off based on pid output
************************************************** */
unsigned long now = millis();
if(now - windowStartTime>WindowSize)
{ //time to shift the Relay Window
windowStartTime += WindowSize;
}
if(Output > now - windowStartTime) digitalWrite(Heat,HIGH);
else digitalWrite(Heat,LOW);

return;


}
the code is in deg c because that's what we use down here so you will have to use a formula to change it to deg F.

cheers steve

ScottSingleton 03-21-2012 06:05 PM

1 Attachment(s)

just to give you an idea of what my display looks like this is my PID tuning screen. The kettle is empty and the RIMS is disconnected but you can see how much info I can pack in a screen.

from here I can see the continual PID duty cycle, hold temp, actual temp and live adjust the tunings.



All times are GMT. The time now is 09:04 PM.

Copyright ©2000 - 2015, Jelsoft Enterprises Ltd.