Here's a snippet of code I'm working on for an auto plant watering system. It is written for 2 potentiometers to control the upper and lower moisture levels in soil. The variable "zone1" is for the moisture sensor, "valve" is obviously valve.
The only error says "error compiling for board"
Any suggestions?
int zone1 = A0;
int valve1 = 2;
int potLow = A4;
int potHigh = A5;
void loop()
{
if(analogRead(zone1) <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve1,HIGH);} //open the valve
if(analogRead(zone1) >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve1,LOW); //close the valve
}
}
You could try reading the two "sticky" posts at the top of this forum:
How to use this forum - please read.
and
Read this before posting a programming question ...
Heres the whole thing Bob, I appreciate your help.
//First attempt at making a 4 zone auto watering system
//potPins values are just for setup purposes, must be calibrated once placed in soil
//potPins are to adjust the high and low moisture ranges for each zone
//must be used with Arduino Mega
const int zone1 = A0;
const int zone2 = A1;
const int zone3 = A2;
const int zone4 = A3;
const int potLow = A4;
const int potHigh = A5;
const int valve1 = 2;
const int valve2 = 3;
const int valve3 = 4;
const int valve4 = 5;
void setup()
{
pinMode(valve1,OUTPUT);
pinMode(valve2,OUTPUT);
pinMode(valve3,OUTPUT);
pinMode(valve4,OUTPUT);
}
void loop()
{
if(analogRead(zone1) <= potLow){ //read the value from the soil moisture sensor
digitalWrite(valve1,HIGH);} //open the valve
if(analogRead(zone1) >= potHigh){ //when value from soil moisture sensor reaches the upper limit
digitalWrite(valve1,LOW); //close the valve
}
}
and replies(supposed to be!) are mostly crap! they want to show that they are experts
but actually most are mediocre crap.
yes you need a SETUP() function.
please check arduino reference how to use this function - always helpul.
for inputs you need an INPUT setup
and for outputs like LED bulbs - you need an OUTPUT setup.
e.g. pinMode(ledBluePin, OUTPUT);
pinMode(micSensorPin, INPUT);
arduino IDE compilation error messages are NO GOOD AT ALL!
its an open source software/hardware.
the errors dont reflect the ACTUAL ERROR.
the error message in your case should read - "missing setup area" or something to that
effect.
i have been using arduino for about an year and sometimes i get
and error with reference to a CORE file error, which i overcome by
running the blank sketch and refreshing the libraries.
somehow this works to get rid of the CORE error!
disregard these nasty fools who mostlly mislead you.
sorry I did not see - already someone has replied with
the right solution!
Unable to publish the post. Please notice you can only post once every 5 minutes and only edit posts after 30 seconds. Once you reach 100 published posts this limit will be removed.
I have to wait 5 mins ha ha - so if a fool writes 100 posts mostly crap
this error will not appear! omg I just cant believe this!
Hello! One quick fix for me is to save the code to another location with or without a new name. This has fixed problems like this for me but it will need a setup nevertheless.