Hi, I’ve had my Arduino a couple of days now so fairly new to this. I’ve just put my first project together which is plant moisture level sensor, which turns on a relay to control a pump once the moisture level is too low…but…what I want to do now is use the Arduino to monitor two moisture sensors (one for each plant) and also control a second relay/pump when the second plant becomes dry i.e. water two plants independently. I’ve written this so far, which works for one sensor/replay/pump but I’m unsure if the Arduino is even capable of multi-tasking? There are loads of inputs, i’m just not sure how (if it’s at all possible) to write the code so that it’ll do different outputs for each of the sensors. Anyway, here’s what I’ve written so far:
int sensorPin = 0;
int redPin2=2;
int redPin3=3;
int yellowPin4=4;
int yellowPin5=5;
int greenPin6=6;
int greenPin7=7;
int waterPump = 8;
int sensorValue=0;
void setup()
{
Serial.begin(9600);
pinMode(redPin2, OUTPUT);
pinMode(redPin3, OUTPUT);
pinMode(yellowPin4, OUTPUT);
pinMode(yellowPin5, OUTPUT);
pinMode(greenPin6, OUTPUT);
pinMode(greenPin7, OUTPUT);
pinMode (waterPump, OUTPUT);
}
void loop()
{
sensorValue = analogRead(sensorPin);
Serial.println(sensorValue);
delay(250);
if (sensorValue <= 400) // VERY WET
{
digitalWrite(greenPin7, HIGH);
digitalWrite(greenPin6, LOW);
digitalWrite(yellowPin5, LOW);
digitalWrite(yellowPin4, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, LOW);
}
else if (sensorValue <=500) // WET
{
digitalWrite(greenPin7, LOW);
digitalWrite(greenPin6, HIGH);
digitalWrite(yellowPin5, LOW);
digitalWrite(yellowPin4, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, LOW);
}
else if (sensorValue <=600) // MOIST
{
digitalWrite(greenPin7, LOW);
digitalWrite(greenPin6, LOW);
digitalWrite(yellowPin5, HIGH);
digitalWrite(yellowPin4, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, LOW);
}
else if (sensorValue <=700) // MILDY MOIST
{
digitalWrite(greenPin7, LOW);
digitalWrite(greenPin6, LOW);
digitalWrite(yellowPin5, LOW);
digitalWrite(yellowPin4, HIGH);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, LOW);
}
else if (sensorValue <=800) // GETTING DRY
{
digitalWrite(greenPin7, LOW);
digitalWrite(greenPin6, LOW);
digitalWrite(yellowPin5, LOW);
digitalWrite(yellowPin4, LOW);
digitalWrite(redPin3, HIGH);
digitalWrite(redPin2, LOW);
}
else // DRY
{
digitalWrite(greenPin7, LOW);
digitalWrite(greenPin6, LOW);
digitalWrite(yellowPin5, LOW);
digitalWrite(yellowPin4, LOW);
digitalWrite(redPin3, LOW);
digitalWrite(redPin2, HIGH);
digitalWrite(waterPump, HIGH); // Pump on for 10 Seconds
delay(10000);
digitalWrite(waterPump, LOW); // Pump off for 1 Second
delay(1000);
}
}