The script verifies and compiles just fine. I just wanted to post my code here incase of a better way to write this.
future plans: (indoor plants) add ventilation controllers, air temp. humidity sensors etc.
I would prefer to use a switch...case statement for the valve controller and a separate function to turn on pump if a valve is open
this is just a quick draft really. I have not acquired all the hardware together yet.
hardware:
arduino uno R3
4 12v DC solenoid valves
12v DC pump
relays
tubing
watering rings
55 gallon barrel.
//pump resources
const int pumpPin = 4;
//solenoid valve resources 0-3
const int slndPin0 = 0;
const int slndPin1 = 1;
const int slndPin2 = 2;
const int slndPin3 = 3;
//sensory input
const int analog0 = A0;
const int analog1 = A1;
const int analog2 = A2;
const int analog3 = A3;
//Values
#define trigger 250 //moisture level to start watering()
//moisture level
int humidity0 = 0;
int humidity1 = 0;
int humidity2 = 0;
int humidity3 = 0;
//sensor sample collector
long int moistureSum0 = 0;
long int moistureSum1 = 0;
long int moistureSum2 = 0;
long int moistureSum3 = 0;
void setup() {
Serial.begin(9600);
pinMode(pumpPin, OUTPUT);
pinMode(slndPin0, OUTPUT);
pinMode(slndPin1, OUTPUT);
pinMode(slndPin2, OUTPUT);
pinMode(slndPin3, OUTPUT);
}
void loop() {
delay(3000);
waterTest();
//feed plant 0
if (humidity0 <= trigger){
digitalWrite(slndPin0, HIGH);
delay(250);
digitalWrite(pumpPin, HIGH);
delay(1500);
digitalWrite(pumpPin, LOW);
digitalWrite(slndPin0, LOW);
}
//feed plant 1
if (humidity1 <= trigger){
digitalWrite(slndPin1, HIGH);
delay(250);
digitalWrite(pumpPin, HIGH);
delay(1500);
digitalWrite(pumpPin, LOW);
digitalWrite(slndPin1, LOW);
}
//feed plant 2
if (humidity2 <= trigger){
digitalWrite(slndPin2, HIGH);
delay(250);
digitalWrite(pumpPin, HIGH);
delay(1500);
digitalWrite(pumpPin, LOW);
digitalWrite(slndPin2, LOW);
}
//feed plant 3
if (humidity3 <= trigger){
digitalWrite(slndPin3, HIGH);
delay(250);
digitalWrite(pumpPin, HIGH);
delay(1500);
digitalWrite(pumpPin, LOW);
digitalWrite(slndPin3, LOW);
}
if(pumpPin, HIGH){
digitalWrite(pumpPin, LOW);
}
}
void waterTest() {
for (int i = 0; i < 30; i++) {
moistureSum0 = moistureSum0 + analogRead(analog0);
moistureSum1 = moistureSum1 + analogRead(analog1);
moistureSum2 = moistureSum2 + analogRead(analog2);
moistureSum3 = moistureSum3 + analogRead(analog3);
}
humidity0 = moistureSum0 / 30; //get the average soil humidity
humidity1 = moistureSum1 / 30;
humidity2 = moistureSum2 / 30;
humidity3 = moistureSum3 / 30;
// print the results to the serial monitor:
Serial.print("Humidity0 = " );
Serial.print(humidity0);
Serial.print("\t Humidity1 = ");
Serial.print(humidity1);
Serial.print("\t Humidity2 = ");
Serial.print(humidity2);
Serial.print("\t Humidity3 = ");
Serial.println(humidity3);
Serial.println();
moistureSum0 = 0; //reset the readings
moistureSum1 = 0;
moistureSum2 = 0;
moistureSum3 = 0;
delay(3000); //3 second delay
}
WateringProgram-C.ino (2.68 KB)