Programming Language?
Moderator: Post Moderators
- backyard brewer
- Posts: 3774
- Joined: Fri Feb 18, 2005 5:38 pm
- Location: Orange County, CA
- Contact:
Oh yeah. The hardware I'm making is designed as a Shield so it can plug right into the Arduino board and have 6 temp sensors and 6 relays. 2 temp sensors will control 2 of the relays, the remaining 4 will just record and log data. 2 of the relays will be controlled based on variables passed from the PC (pumps on/off) and 2 of the relays will be unused at this point but could obviously be controlled by code or any of the sensors.
All of the relays will have a manual override switch to turn the pumps or burners on at will.
All of the relays will have a manual override switch to turn the pumps or burners on at will.
Hey Derrin:
Why do many of the variables look like arrays? e.g. TempReading [0], Setpoint [0], OffTime [0], RelayStatus [0], RelayPin [0]
I don't see array increments anywhere nor do I see the use of anything but the first position ( [0] ). Maybe I'm missing something BUT if you're declaring array structures and only using one position, seems to me that you might be able to be more efficient.
Just my .02.
Dan
Why do many of the variables look like arrays? e.g. TempReading [0], Setpoint [0], OffTime [0], RelayStatus [0], RelayPin [0]
I don't see array increments anywhere nor do I see the use of anything but the first position ( [0] ). Maybe I'm missing something BUT if you're declaring array structures and only using one position, seems to me that you might be able to be more efficient.
Just my .02.
Dan
- backyard brewer
- Posts: 3774
- Joined: Fri Feb 18, 2005 5:38 pm
- Location: Orange County, CA
- Contact:
That's just a quick snip of code. I'm using most of the array positions. I have a lot of work to do. Most of the code here is for testing, but here's the entire sketch as i have it now:
Code: Select all
/*
Backyard Brewing Co.
Brewery Logging and Control System v 2.0
08/2008
The controller will need to monitor:
HLT Temperature
MLT Temperature Body
MLT Temperature Return
BK Temperature
Chiller Water Temperature In
Chiller Water Temperature Out
The controller will need to control:
Pump 1
Pump 2
HLT Burner
MLT Burner
The controller will need to know:
Pin assignments for all sensors and controls
Control setpoints for:
HLT Temperature
MLT Temperature
Pump 1 On/Off
Pump 2 On/Off
Override status of all relay switches
Program Flow:
Initialize the serial communication
Initialize all variables and set them to 0.
Turn off all relays
Begin Loop
Read all sensor pins and convert readings to temperature *F
Check serial buffer for input from PC to set setpoint variables
Check digital relay pins to see if they are over-ridden by the manual switches
Compare sensor readings to setpoints and set relay state accordingly
Check to make sure MLT pump is on before firing MLT burner if system is in mash mode
Send all variables and readings back to the PC
Loop
*/
#define LM34 0.48828125 // defines LM34 as .48828125 which is 500/1024 for the LM34 which produces .5mV per 1/2*F. The Arduino has 1024 resolution on the analog pin
// Variable Declarations
int i = 0; // Used for For loop control
int Mode = 0; // Sets the System Mode 0 = Off, 1 = Heat Up/Strike, 2 = Mash, 3 = X-Circulate, 4 = Boil
unsigned long OffTime [6] = {0, 0, 0, 0, 0, 0};
unsigned long Time = 0;
// Digital Pin definitions
int SensorPin [6] = {0, 1, 2, 3, 4, 5 };
int RelayPin [6] = {2, 3, 4, 5, 6, 7 };
int SwitchPin [6] = {8, 9, 10, 11, 12, 13 };
/*
Relay and manual override switch pin array position Relay/Switch:
0 = HLT Relay and switch
1 = MLT Relay and switch
2 = Pump 1 Relay and switch
3 = Pump 2 Relay and switch
4 = future use
5 = future use
*/
// Sensor Read definitions
float TempReading [6] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
/*
TempReadings array positions:
0 = HLT Temp
1 = MLT Main body Temp
2 = MLT Sparge/recirc return temp
3 = Boil Kettle Temp
4 = Chiller H20 inlet temp
5 = Chiller H20 Outlet temp
*/
// Status definitions
int SwitchStatus [6] = {0, 0, 0, 0, 0, 0 };
int RelayStatus [6] = {0, 0, 0, 0, 0, 0 };
/*
Status definitions for relays and manual switches.
0 = HLT Burner and switch
1 = MLT Burner and switch
2 = Pump 1 and override switch
3 = Pump 2 and override switch
4 = not used
5 = not used
*/
// Setpoint definitions
int Setpoint [6] = {0, 0, 0, 0, 0, 0 };
/*
Status definitions for setpoints from PC
0 = HLT temperature Setpoint
1 = MLT temperature Setpoint
2 = Pump 1 0 = off, 1 = on
3 = Pump 2 0 = off, 1 = on
4 = not used
5 = not used
*/
void setup(void) {
// initialize inputs/outputs
// start serial port
Serial.begin(9600);
// Set Digital Pin modes and turn all relays off
for ( i = 0; i <= 5; i ++)
{
pinMode(RelayPin [i], OUTPUT);
digitalWrite(RelayPin [i], LOW);
pinMode(SwitchPin [i], INPUT);
}
// end setup
}
void loop(void) {
// Program Loop
// Hard coded setpoints until PC interface is complete
Setpoint [0] = 86; // HLT Temperature Setpoint
Setpoint [1] = 86; // MLT Temperature Setpoint
Mode = 1; // Define System mode as Strike-in
// NEED CODE Read setpoints from serial buffer sent from PC
// Read all sensors
for ( i = 0; i <= 5; i++)
{
TempReading [i] = (analogRead(SensorPin [i]) * LM34); // Reads each analog pin, converts the reading to *F and stores it in the TempReading array
SwitchStatus [i] = (digitalRead(SwitchPin [i])); // Reads each digital pin and checks to see if the switch is on. True = switch on override
}
//temporary code for testing
for ( i = 0; i <= 5; i++)
{
Serial.print ( " Sensr ");
Serial.print ( i );
Serial.print ( " " );
Serial.print ( int (TempReading [i]));
}
Serial.println ();
for ( i = 0; i <= 5; i++)
{
Serial.print ( " Swtst ");
Serial.print ( i );
Serial.print ( " " );
Serial.print ( int (SwitchStatus [i]));
}
Serial.println ();
// Compare sensor reads to setpoints and set relays accordingly
// HLT Control
if (SwitchStatus [0] > 0) // Check status of override switch If switch is on override:
{
digitalWrite( RelayPin [0], LOW); // Turn burner relay off to prevent unwanted start
RelayStatus [0] = 1; // Set HLT Burner Status as on since switch is on
}
else // Override switch is off, allowing Arduino control of burner.
{
Time = millis() / 1000; // Sets Time to the current total program runtime in seconds.
if (TempReading [0] >= Setpoint [0] ) // Compare HLT: Temperature is at or above setpoint
{
digitalWrite( RelayPin [0], LOW); // Turn HLT Burner Off.
RelayStatus [0] = 0; // Set HLT Burner Status
OffTime [0] = Time; // Time stamps the off time for Burner.
Serial.print ("Burner is off OffTime = ");
Serial.print (OffTime [0]);
Serial.println ();
}
else
{
Serial.print ("Temp below setpoint. ");
Serial.println();
if ( Time - OffTime [0] < 30) // Check to confirm burner has been off at least 30 seconds
{
Serial.print (" Timer has not elapsed. Burner off. Timer = ");
Serial.println (Time - OffTime [0]);
}
else
{
digitalWrite( RelayPin [0], HIGH); // Turn HLT Burner On.
RelayStatus [0] = 1; // Set HLT Burner Status as on
Serial.print ("burner on. ");
Serial.println();
}
}
}
// End HLT Control
// MLT Control
// End MLT control
// Pump Control
// End Pump control
// NEED CODE Record all Sensor readings and print to serial port
Serial.println();
Serial.println();
delay(2000);
}
- backyard brewer
- Posts: 3774
- Joined: Fri Feb 18, 2005 5:38 pm
- Location: Orange County, CA
- Contact:
- backyard brewer
- Posts: 3774
- Joined: Fri Feb 18, 2005 5:38 pm
- Location: Orange County, CA
- Contact:
Initially it'll monitor 6 different temperatures and have 4 onboard relays. This version of code will accept 2 setpoints (from a rotary encoder) to control 2 of the relays based on 2 of the temperatures. With a quick software change, it could control the other two relays, but I don't see a need for the brewery or what it would control. So basically, it'll replace 2 Ranco controllers and 4 additional thermometers and record it all.dhempy wrote:Controller or measurement taker? How will it "control" something?
Dan
I still have a lot to work out. I want it to record the data ever minute or so to an SD card or USB flash drive so it's completely independent of the PC. The problem is I'm running out of pins. I'm looking at multiplexers, but I don't have one to play with yet. I just got the LCD last night. God bless UPS, my driver showed up at 8:58PM last night!!
What's not in the picture is a relay/sensor board that has the 4 relays and jacks for the 6 sensors. The Arduino plugs right into that board, they piggyback together.
I'll take a bunch more pictures as I get further.
Derrin's really done some slick work on the Arduino. The relay/sensor shield is pretty sweet. Now that I think of it, you might be able to use the EPROM memory to store your logging, depending on how much data you end up with. There isn't a lot of space there, but I've heard of other people logging to it and then doing a dump when it hooks up to a pc.
- brew captain
- Posts: 1158
- Joined: Sat Oct 01, 2005 8:41 am
- backyard brewer
- Posts: 3774
- Joined: Fri Feb 18, 2005 5:38 pm
- Location: Orange County, CA
- Contact:
- brew captain
- Posts: 1158
- Joined: Sat Oct 01, 2005 8:41 am