Coming back to ask some advices on adding the automatic mode on my water pump, that takes care of watering the plant.
My idea is to have 2 switches , one that I use to manually to start the pump at any moment I want , and another one that, if activated, will take care of this task for me, if some conditions are met. ( see pictures below )
I’m using 2 threshold values:
- low_threshold = if soil_hum_percent is under this then START watering
- high_threshold = use to stop the pump when soil_hum_percent has passed this value
My implementation so far is shown below. I’m open to advices on how to do it better. Or, if its actually any good what I did so far.
PS : I’m making use of the function that reads my soil moisture to check if I need to water the plant or not. I dont know how correct this is.
bool auto_mode = 0;
byte low_threshold = 20;
byte high_threshold = 85;
Blynk.syncVirtual(V4); // will cause BLYNK_WRITE(V4) to be executed
// CAN I USE BLYNK.syncAll() here?
BLYNK_WRITE(V4) // Manual Mode button
bool value = param.asInt();
if (auto_mode == 1 && value == 1) // if auto_mode is enable when I want to manually turn on the PUMP, then disable it.
auto_mode = 0;
BLYNK_WRITE(V6) // Automatic mode button
auto_mode = param.asInt();
low_threshold = param.asInt();
high_threshold = param.asInt();
soilMoistureValue = analogRead(SoilPin);
soilmoisturepercent = constrain((map(soilMoistureValue, DryValue, WetValue, 0, 100)), 0, 100);
if (auto_mode == 1 && (soilmoisturepercent < low_threshold || soilmoisturepercent < high_threshold)) // if auto_mode is ON .. AND soil_hum_percent is in between my threshold values then
digitalWrite(relayPin, 0); // turn ON
digitalWrite(relayPin, 1); // turn OFF
Also this is how often I check the soil humidity:
This are my datastreams:
And the app itself ( web part ):