Hi all,
I am working on automated watering system, similar to this one (link below). But I would like to water 5 plants with 5 separate sensors and pumps. I have tried to modify the code below, but now the sensor readings are inaccurate and the pumps never turn on.
This is the original code for one plant, which worked great:
const int VAL_PROBE = 0; //Analog pin 0
const int MOISTURE_LEVEL = 450; // the value after the LED goes on
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(7, OUTPUT);
}
void loop()
{
digitalWrite(13,HIGH);
delay(2000);
int moisture = analogRead(VAL_PROBE);
Serial.print("Moisture = ");
Serial.println(moisture);
if(moisture < MOISTURE_LEVEL)
{
digitalWrite(7,LOW);
digitalWrite(13,LOW);
delay(10000);
}
else
{
digitalWrite(7,HIGH);
}
}
and this is how I modified it for 2 plants:
const int VAL_PROBE = 0; //Analog pin 1
const int MOISTURE_LEVEL = 750; // the value after the LED goes on
const int VAL_PROBE2 = 0; //Analog pin 2
const int MOISTURE_LEVEL2 = 750; // the value after the LED goes on
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
}
void LedState(int state)
{
digitalWrite(13,state);
}
void loop()
{
int moisture = analogRead(VAL_PROBE);
Serial.print("Moisture = ");
Serial.println(moisture);
if(moisture > MOISTURE_LEVEL)
{
LedState(HIGH);
digitalWrite(2,LOW);
}
else
{
LedState(LOW);
digitalWrite(2,HIGH);
}
int moisture2 = analogRead(VAL_PROBE2);
Serial.print("Moisture2 = ");
Serial.println(moisture2);
if(moisture > MOISTURE_LEVEL2)
{
LedState(HIGH);
digitalWrite(3,LOW);
}
else
{
LedState(LOW);
digitalWrite(3,HIGH);
}
delay(10000);
}
My setup is this:
A1-5- analog sensor input
D2-7- digital output to relays
D13- power for the sensors
I appreciate your help. Thanks