I apologize again for not being able to explain the problem
I have sent an image to show the idea of the program to be implemented
I sent full code >>>the problem in Page call "Program"
want to digitalWrite ---> PUMP_PIN ----> HIGH for example 10 mins and then turn off the pump when moisture_percentage < DRY_SOIL
Then the pump will work for an example 10 mins and moisture will become : moisture_percentage > DRY_SOIL In this case I want to keep the pump closed
and I want when moistre become againe : moisture_percentage < DRY_SOIL I want the pump to run again for the previously set time then turn off
but when use millis or simple timer the pump diddn;t turn off because this function in LOOP
How can I solve this problem?
#include <SPIFFS.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <DNSServer.h>
#include <WebServer.h>
#include <WiFiManager.h>
#include <ArduinoJson.h>
#include <BlynkSimpleEsp32.h> // Blynk_Release_v0.6.1
#include "stationDefines.h" // Project definitions DHT
/* OLED */
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <dht.h> /* DHT11*/
#include <EasyButton.h>
Adafruit_SSD1306 display(1, 3, 23, 22, 60);
WiFiManager wifiManager;
dht DHT;
EasyButton button(oled_AP);
void setup()
{
startTimers(); //collect data from sensors
oledStart();
timer.setInterval(1000, displayData);
pin_Mode();
timer.setTimeout(1000, Config_WiFi);
display.ssd1306_command(SSD1306_DISPLAYOFF);
button.onPressedFor(5000, WiFi_initialization);
}
void loop()
{
if (Blynk.connected())
{
Blynk.run();
WiFi_control(); //when connected to Blynk we should chose if we want to run device auto by sensors or manual by buttons in Blynk APP
digitalWrite(Green_LED_PIN, HIGH); //when connected to blynk green led on
}
else
{
autoControlPlantation(); //when disconnected run device auto by sensors
digitalWrite(Green_LED_PIN, LOW); //when connected to blynk green led off
}
timer.run();//Give time of Blynk work
feedback();
button.read();
sleepOLED();
}
void pin_Mode()
{
pinMode(PUMP_PIN, OUTPUT);
pinMode(FAN_PIN, OUTPUT);
pinMode(LAMP_PIN, OUTPUT);
pinMode(Humidity_Reduction_Device_PIN, OUTPUT);
pinMode(Green_LED_PIN, OUTPUT);
pinMode(PUMP_Feedback, INPUT_PULLUP);
pinMode(FAN_Feedback, INPUT_PULLUP);
pinMode(LAMP_Feedback, INPUT_PULLUP);
pinMode(LAMP_Feedback, INPUT_PULLUP);
pinMode(Humidity_Reduction_Device_Feedback, INPUT_PULLUP);
pinMode(oled_AP, INPUT_PULLUP);
}
///////////////////////////////////////////////////////////////////////////////////////////////
/***************************************************
Choose between automatic and manual control through Blynk button
**************************************************/
void WiFi_control()
{
if (Auto == 0)
{
autoControlPlantation();
}
else
{
manual_Blynk();
}
}
/***************************************************
control from Blynk buttons
**************************************************/
void manual_Blynk()
{
if (pumpo == 1)
{
digitalWrite(PUMP_PIN, HIGH);
}
if (pumpo == 0)
{
digitalWrite(PUMP_PIN, LOW);
}
////////////////////////////////
if (fano == 1)
{
digitalWrite(FAN_PIN, HIGH);
}
else
{
digitalWrite(FAN_PIN, LOW);
}
/////////////////////////////////
if (Lampo == 1)
{
digitalWrite(LAMP_PIN, HIGH);
}
else
{
digitalWrite(LAMP_PIN, LOW);
}
////////////////////////////////
if (Humidity_Reduction_Device_o == 1)
{
digitalWrite(Humidity_Reduction_Device_PIN, HIGH);
}
else
{
digitalWrite(Humidity_Reduction_Device_PIN, LOW);
}
}
/***********************************************
Blynk Buttons definition
***********************************************/
BLYNK_WRITE(V2) //select Auto/Manual
{
Auto = param.asInt();
}
/////////////////////////////////////////////////
BLYNK_WRITE(V3) //Pump remote control
{
pumpo = param.asInt();
}
/////////////////////////////////////////////////
BLYNK_WRITE(V4) // FAN remote control
{
fano = param.asInt();
}
//////////////////////////////////////////////////
BLYNK_WRITE(V17) // LAMP remote control
{
Lampo = param.asInt();
}
//////////////////////////////////////////////////
BLYNK_WRITE(V6) // LAMP remote control
{
Humidity_Reduction_Device_o = param.asInt();
}
/***************************************************
Automatically Control the Plantation based on sensors reading
****************************************************/
void autoControlPlantation(void)
{
if (moisture_percentage < DRY_SOIL)
{
// want to digitalWrite ---> PUMP_PIN ----> HIGH for example 10 mins and then turn off the pump when moisture_percentage < DRY_SOIL
//Then the pump will work for an example 10 mins and moisture will become : moisture_percentage > DRY_SOIL In this case I want to keep the pump closed
//and I want when moistre become againe : moisture_percentage < DRY_SOIL I want the pump to run again for the previously set time then turn off
//but when use millis or simple timer the pump diddn;t turn off because this function in LOOP
//How can I solve this problem?
}
if (DHT.temperature > HOT_TEMP)
{
digitalWrite(FAN_PIN, HIGH);
}
if (DHT.temperature < COLD_TEMP)
{
digitalWrite(FAN_PIN, LOW);
}
if (LDRValue == LOW)
{
digitalWrite(LAMP_PIN, HIGH);
}
else
{
digitalWrite(LAMP_PIN, LOW);
}
if (DHT.humidity > HIGH_HUM)
{
digitalWrite(Humidity_Reduction_Device_PIN, HIGH);
}
if (DHT.humidity < LOW_HUM)
{
digitalWrite(Humidity_Reduction_Device_PIN, LOW);
}
}
/***************************************************
Send data to Blynk
**************************************************/
void sendUptime()
{
Blynk.virtualWrite(10, DHT.temperature); //virtual pin V10
Blynk.virtualWrite(11, DHT.humidity); // virtual pin V11
Blynk.virtualWrite(12, moisture_percentage); // virtual pin V12
}
void Initially_LOW() {
digitalWrite(PUMP_PIN, LOW);
digitalWrite(FAN_PIN, LOW);
digitalWrite(LAMP_PIN, LOW);
digitalWrite(Humidity_Reduction_Device_PIN, LOW);
}
Plant_Station_Q.zip (129 KB)