Hi all.
First of all, I am new to coding, I know it's not tidy or very logic for that matter but I am trying. I am an old boy ish so can handle criticism. Please dont baffle me with advanced coding and tricks, I am looking for help getting the basic idea up and running then develope from there.
PLAN.
2 litre resevoir on the wall. plant pot has moisture sensor. Tank will fill up on demand based on moisture levels, using a solenoid for inlet and peristaltic pumps will add nutrients. Resevoir uses like a float switch to cut off when full. Once full, the feed will be delivered in short bursts using a submersible pump in the res over set time, taking further readings as it goes to avoid flooding or over feeding. Once i get 1 going I plan to scale it up to 8 pots but thats another day, one step at a time.
code is below. It all works at this simple level, what I am struggling to do, don't laugh.
I was trying to use my float switch in the resevoir 'tankfullsw' when LOW (empty), to switch 'insolenoid' on until full. Then off again when float swich 'tankfullsw' is HIGH.
I am basically struggling with command parameters and decoding the errors they throw up. Any help appreciated.
int sensor1Pin = A1; // sensor1
int sensor2Pin = A0; // sensor2
int sensor1Value = 0; // variable to store the value coming from the sensor
int sensor2Value = 0;
int insolenoid = 3; // control pin 3 for water inlet solenoid.
int tankfullsw = 4; //pin 4 for float switch in resevoir
int tankfullswstate=0; // flag to indicate if resevoir is full 0=empty 1=full
void setup() {
Serial.begin(9600);
pinMode(insolenoid, OUTPUT);
pinMode(tankfullsw, INPUT);
digitalWrite(insolenoid,LOW);
digitalWrite(tankfullsw,HIGH);
}
void loop() {
// read the value from the sensors
sensor1Value = analogRead(sensor1Pin);
sensor2Value = analogRead(sensor2Pin);
digitalRead(tankfullsw);
delay(3000);
if (tankfullswstate=1)
{
digitalWrite(insolenoid,HIGH);
}
else if (tankfullswstate=0)
{
digitalWrite(insolenoid,LOW);
}
Serial.print("sensor1 = " );
Serial.print(sensor1Value);
if (sensor1Value>601) //600 is threshold for feeding (
{
Serial.println(" needs feeding");
} else{
Serial.println( " all good");
}
Serial.print("sensor2 = " );
Serial.print(sensor2Value);
if (sensor2Value>601)
{
Serial.println(" needs feeding");
}
else
{
Serial.println(" all good");
}
delay(5000);
}