Hi ,
I have hooked up solenoid and soil sensor , so that when soil is dry it turns on solenoid,
however data coming from soil sensor is not always sticking to a particular value, so even if it touches a default set value that defines dry state of soil , next cycle of loop it may jump to not dry .
In that case solenoid will turn on and off quickly which I think can damage it.
so I have decided to turn solenoid on for 45 seconds no matter what
#include <elapsedMillis.h>
const int solenoidPin = 6; // D6 : This is the output pin on the Arduino we are using
#define DHT11_PIN 8 // D8 to 2nd pin on DHT, leave 3rd pin unconnected 4th is gnd
const int8_t rainsense = 7; // analog sensor input pin A7
const int buzzerout = 2; // digital output pin D2 - buzzer output
int SENSE = 1; // Soil Sensor input at Analog PIN A1 Green wire
int val = 0;
int lightSensorPin = A8;
int analogValue = 0;
elapsedMillis timer0;
// the interval in mS
#define interval 45000
void setup() {
SOLENOID_STATE = false;
timer0 = 0; // clear the timer at the end of startup
pinMode(solenoidPin, OUTPUT); // Sets the pin as an output
pinMode(buzzerout, OUTPUT);
}
void loop() {
val = analogRead(SENSE);
val = val / 10;
int rainSenseReading = analogRead(rainsense);
analogValue = analogRead(lightSensorPin);
if (rainSenseReading < 500) {
rainMsg = F("It is raining heavily !");
}
if (rainSenseReading < 300) {
rainMsg = F("Moderate rain.");
}
if (rainSenseReading < 200) {
rainMsg = F("Light Rain Showers !");
}
if (rainSenseReading > 500) {
rainMsg = F("Not Raining.");
SOLENOID_STATE = true;
}
else SOLENOID_STATE == false;
// Turn on Solenoid Valve if soil moisture value less than 25
if (val < DRY_SOIL_DEFAULT && SOLENOID_STATE == true) {
soilMsg = F("Soil is dry. ");
// do not water pot if its raining or if it is night.
if (SOLENOID_STATE || analogValue > 300) {
soilMsg = soilMsg + F("Watering the plant.");
// turn solenoid off after 45 sec
digitalWrite(solenoidPin, HIGH);
digitalWrite(buzzerout, HIGH);
if ((!SOLENOID_STATE) && (timer0 > interval)) {
SOLENOID_STATE = false; // don't execute this again
digitalWrite(solenoidPin, LOW);
digitalWrite(buzzerout, LOW);
}
}
}
else {
digitalWrite(solenoidPin, LOW);
soilMsg = F("Soil is damp.");
SOLENOID_STATE = false;
digitalWrite(buzzerout, LOW);
}
}
am I going correct? :o