Hi All,
I am trying to build a garduino system from online instructions in order for my plants to be able to water themselves and for me to learn about arduinos. I have all the kit and its ready to go. The only problem is the code. Its taken from a code that involves light water and heat control but i have slightly modified it to omit light and temperture element. the code i am using is;
//define analog inputs to which we have connected our sensors
int moistureSensor = 0;
//define digital outputs to which we have connecte our relays (water)
int waterPump = 7;
//define variables to store moisture
int moisture_val;
//setup a variable to store seconds since arduino switched on
float start_time;
float seconds_elapsed;
float seconds_elapsed_total;
float seconds_for_this_cycle;
void setup() {
//open serial port
Serial.begin(9600);
//set the water, light, and temperature pins as outputs that are turned off
pinMode (waterPump, OUTPUT);
digitalWrite (waterPump, LOW);
}
void loop() {
// read the value from the moisture-sensing probes, print it to screen, and wait a second
moisture_val = analogRead(moistureSensor);
Serial.print("moisture sensor reads ");
Serial.println( moisture_val );
delay(1000);
}
//turn water on when soil is dry, and delay until soil is wet (line 41)
if (moisture_val < 850)
{
digitalWrite(waterPump, HIGH);
}
while (moisture_val < 850)
{
delay(10000);
}
digitalWrite(waterPump, LOW);
However when i run it these error messages are returned;
Guardinho_ReMix:42: error: expected unqualified-id before 'if'
Guardinho_ReMix:48: error: expected unqualified-id before 'while'
Guardinho_ReMix:53: error: expected constructor, destructor, or type conversion before '(' token
I would apreciate any help that can be given. I have tried to research the problem found that these are compiler errors. Is this correct and what can i do to fix this and save my flowers from certain death!!!
Many Thanks