Arduino UNO pool control code problem

Thread Starter

aouate3

Joined Apr 17, 2011
91
Hello all, First off, i am a noob when it comes to the arduino platform, i ordered a Arduino UNO and i will be recieving it in the next few weeks, I am working on setting up a control system for my pool, and also our outdoor lighting, there are 4 relays i have wired, one for main pump, one for booster pump, one for spa blower, and one for the outdoor lighting, the relays are wired to the diode and transistor so they can be controlled by the arduino, all the wiring is setup and should be fine, i have even put a schematic on here if it helps at all, I am using the arduino 0022 software to write the code, i have copied the code from http://www.atari-source.org/node/65 and modifed it for my own uses, but i am unable to compile it be cause it errors out, same with the code when i copy it directly from the website in its full, unaltered state...

also in the schematic, there are two temperature sensors, which i havent coded yet, because i simply, do not know how to do it...


Here is my code so far

#include
int state_FilterPump=0, state_BoosterPump=0, state_SpaBlower=0, state_Lighting=0;
bool have_control=false; // Temp variable
int control_relay=0; // Temp variable

void setup()
{
pinMode(2, OUTPUT); // sets the digital pin as output
pinMode(4, OUTPUT); // sets the digital pin as output
pinMode(7, OUTPUT); // sets the digital pin as output
pinMode(8, OUTPUT); // sets the digital pin as ouput

// Prepare the serial ports
Serial.begin(9600);
Serial.flush();

}
void loop()
{
int serial_byte=0;

if (Serial.available()>0)
{
/* Here we wait for the first byte of a two byte control sequence. Send A, B or C to control filterpump,boosterpump, light, or blower.
*/

serial_byte=Serial.read();
if (!have_control)
{
have_control=true;
if (serial_byte=='A')
control_relay=2
else if (serial_byte=='B')
control_relay=4
else if (serial_byte=='C')
control_relay=7;
else if (serial_byte=='D')
control_relay=8;

// We have the control byte, now lets look for 1 or 0
if (serial_byte=='1')
{
// Turn specified relay on
if (control_relay==2
state_FilterPump=HIGH;
if (control_relay==4
state_BoosterPump=High;
if (control_relay==7
state_SpaBlower=HIGH;
if (control_relay==8
state_Lighting=HIGH;
}
else if (serial_byte=='0')
{
// Turn specified relay off
if (control_relay==2)
state_FilterPump=LOW;
if (control_relay==4)
state_BoosterPump=LOW;
if (control_relay==7)
state_SpaBlower=LOW;
If (control_relay==8)
state_Lighting=LOW;
}






What am i doing wrong, why cant i compile it, and is there any way to make it simpler? because of the fact i dont have the arduino yet, i can only assume i would turn on the relays by issueing a A1, B1, C1, or D1 command, and turn off the relays by issueing a A0, B0, C0, or D0 command
 

hgmjr

Joined Jan 28, 2005
9,027
Here is my code so far
Rich (BB code):
#include
int state_FilterPump=0, state_BoosterPump=0, state_SpaBlower=0, state_Lighting=0;
bool have_control=false; // Temp variable
int control_relay=0; // Temp variable
 
void setup()
{
pinMode(2, OUTPUT); // sets the digital pin as output
pinMode(4, OUTPUT); // sets the digital pin as output
pinMode(7, OUTPUT); // sets the digital pin as output
pinMode(8, OUTPUT); // sets the digital pin as ouput
 
// Prepare the serial ports
Serial.begin(9600);
Serial.flush();
 
}
void loop()
{
int serial_byte=0;
 
if (Serial.available()>0)
{
/* Here we wait for the first byte of a two byte control sequence. Send A, B or C to control filterpump,boosterpump, light, or blower.
*/
 
serial_byte=Serial.read();
if (!have_control)
{
have_control=true;
if (serial_byte=='A')
control_relay=2;
else if (serial_byte=='B')
control_relay=4;
else if (serial_byte=='C')
control_relay=7;
else if (serial_byte=='D')
control_relay=8;
}
 
// We have the control byte, now lets look for 1 or 0
if (serial_byte=='1')
{
// Turn specified relay on
if (control_relay==2)
state_FilterPump=HIGH;
if (control_relay==4)
state_BoosterPump=HIGH;
if (control_relay==7)
state_SpaBlower=HIGH;
if (control_relay==8)
state_Lighting=HIGH;
}
else if (serial_byte=='0')
{
// Turn specified relay off
if (control_relay==2)
state_FilterPump=LOW;
if (control_relay==4)
state_BoosterPump=LOW;
if (control_relay==7)
state_SpaBlower=LOW;
if (control_relay==8)
state_Lighting=LOW;
}
}
}
I have enclosed your code with code tags to make it easier to read.

hgmjr
 
Last edited:

hgmjr

Joined Jan 28, 2005
9,027
I put in bold red the changes that were needed to get the code to compile with the Arduino 0022.

That does not mean that it is bug free. That just got it to compile.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
The #include line is incomplete. Normally it is followed by a filename with .h extension. There seems to be something missing.

hgmjr
 

Thread Starter

aouate3

Joined Apr 17, 2011
91
ok, the http://www.atari-source.org/node/65 site, the text after the #include, and and before the void setup(), is it vital to the operation of this code? it seems to tell the starting serial byte, but is it possible to add that in somewhere else and eliminate the #include section all together?

OR is the #include section supposed to be put into a seperate file? and that files filename be put into to the arduino code?
 

hgmjr

Joined Jan 28, 2005
9,027
Diving into programming in C-language without studying the various C language constructs is going to be a bit painful for you. There are a number of tutorials on the Internet that will be useful for you to read.

hgmjr
 

hgmjr

Joined Jan 28, 2005
9,027
Congratulations on your first success.

As an beginner in the world of microcontrollers, you have chosen a good learning environment in the Arduino Uno.

If you invest some time to familiarize yourself with C-language, you will be able to clearly appreciate what each of the code lines mean/does.

Have you had any experience with programming in other languages perhaps?



hgmjr
 

Thread Starter

aouate3

Joined Apr 17, 2011
91
In html mostly, a little visual basic, but not much, i can understand code, and manipulate it to a extent, but when it comes to writing it, i cant do it..

html is the only language i can write efficiently
 

hgmjr

Joined Jan 28, 2005
9,027
For the Arduino Uno and its predecessor the Arduino Duemilanove, there are many example programs out there that you can study. The C-language is pretty easy to understand. The main thing to learn is that in C, like all programming languages, the syntax is important. The compiler will complain if you have even the slightest syntax error. The Arduino compiler gives you pretty clear hints as to what it has found. If you notice the numbers on each of the error messages, these are the line numbers in the source code where the error was found.

hgmjr
 

Thread Starter

aouate3

Joined Apr 17, 2011
91
Ok, yea, im going to starting looking into C, and hopefully writing a few programs to get me familiar, i also noticed something, i didnt press the insert button on my keyboard, when i was editing the code, it was deleting characters.. that was one of the reasons why it didnt compile, the other reason was, of course, me being new to this, and i appreciate all the help you have provided.
 

Thread Starter

aouate3

Joined Apr 17, 2011
91
i added the temperature code from http://pscmpf.blogspot.com/2008/12/arduino-lm35-sensor.html

and everything compiled properly :D

but i just wanted to check with you, and see if there will be any potential problems, interfacing wise, and also, how hard would it be to modify the processing program on that same site to relay info from two temperature sensors


Here is my current code

Rich (BB code):
#include "EEPROM.h"
int state_FilterPump=0, state_BoosterPump=0, state_SpaBlower=0, state_Lighting=0;
bool have_control=false; // Temp variable
int control_relay=0; // Temp variable

//declare variables for temperature
float tempEnvironment;
int tempPin = 0;

float tempWater;
int tempPin2 = 1;

void setup()
{
pinMode(2, OUTPUT); // sets the digital pin as output
pinMode(4, OUTPUT); // sets the digital pin as output
pinMode(7, OUTPUT); // sets the digital pin as output
pinMode(8, OUTPUT); // sets the digital pin as output

// Prepare the serial ports
Serial.begin(9600);
Serial.flush();

}
void loop()
{
int serial_byte=0;

if (Serial.available()>0)
{
/* Here we wait for the first byte of a two byte control sequence. Send A, B or C to control filterpump,boosterpump, light, or blower.
*/

serial_byte=Serial.read();
if (!have_control)
{
have_control=true;
if (serial_byte=='A')
control_relay=2;
else if (serial_byte=='B')
control_relay=4;
else if (serial_byte=='C')
control_relay=7;
else if (serial_byte=='D')
control_relay=8;
}

// We have the control byte, now lets look for 1 or 0
if (serial_byte=='1')
{
// Turn specified relay on
if (control_relay==2)
state_FilterPump=HIGH;
if (control_relay==4)
state_BoosterPump=HIGH;
if (control_relay==7)
state_SpaBlower=HIGH;
if (control_relay==8)
state_Lighting=HIGH;
}
else if (serial_byte=='0')
{
// Turn specified relay off
if (control_relay==2)
state_FilterPump=LOW;
if (control_relay==4)
state_BoosterPump=LOW;
if (control_relay==7)
state_SpaBlower=LOW;
if (control_relay==8)
state_Lighting=LOW;
}
{
tempEnvironment = analogRead(tempPin);           //read the value from the sensor
tempEnvironment = (5.0 * tempEnvironment * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempEnvironment);             //send the data to the computer
delay(1000);                           //wait one second before sending new data


tempWater = analogRead(tempPin2);           //read the value from the sensor
tempWater = (5.0 * tempWater * 100.0)/1024.0;  //convert the analog data to temperature
Serial.print((byte)tempWater);             //send the data to the computer
delay(1000);                           //wait one second before sending new data
}
}
}
 

hgmjr

Joined Jan 28, 2005
9,027
I guess you recognize that the code at the blogspot.com link is intended to run on your PC. It receives temperature data over the serial link and displays it in graphical format.

It is written and compiled by the IDE referred to as Processing. I have no experience in writing code using Processing. I do believe that it runs under JAVA. When it comes to Processing and Java I am out of my element.

For additional details, I would suggest that you consider availing yourself of the assistance that you can obtain from the Arduino website forum at www.arduino.cc.

hgmjr
 
Top