/** code and circut : Ali.haghighat panah ☻
* ☺
*
*
*
*/
//-----------------[ON or OFF]
// #define AHP_BLYNK_OFF //Me: trun off Blynk and "send_Data2Blynk" , actives "send_Data2File"
//-----------------------
// #define XDD "|" // Me: change the string value to any character you want for the delimiter of "send_Data2File"
//==================[HEADER FILES]==================V
#include "DHTesp.h"
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#include <WiFi.h>
#include <OneWire.h>
#include "ThingSpeak.h"
#include <ESP32Servo.h>
// -------[blynk]---------V
#ifdef AHP_BLYNK_OFF //temp
/* Fill-in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPL4HmeajZ2I"
#define BLYNK_TEMPLATE_NAME "AHP BLYNK group 17 Ro pro"
#define BLYNK_AUTH_TOKEN "VMJ_-HXz1_XBVfof2RaG1Fes5wKKIVoC"
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <BlynkSimpleEsp32.h>
// #include <Servo.h>
#endif
//==================[PIN DEFINE]==================V
#define DHT_PIN 15
#define DALLAS_TEMP_PIN 4 // ☺Me:unknown
#define PUSH_BUTTON 2
#define SOIL_MOIST_PIN 33 // potentiometer
#define RELAY_GURDAN_PUMP 12 // LED
#define RELAY_CITY_PUMP 14 // LED
#define BUZZER 13
#define WIFI_LED 32
#define TRIG_PIN 25
#define ECHO_PIN 26
//==================[Objects]==================V
OneWire oneWire(DALLAS_TEMP_PIN); // Setup a oneWire instance to communicate with dallas temperature sensor
DallasTemperature dallasTemp(&oneWire);
LiquidCrystal_I2C Green_LCD = LiquidCrystal_I2C(0x26, 16, 2);
LiquidCrystal_I2C Blue_LCD = LiquidCrystal_I2C(0x27, 16, 2);
DHTesp dhtSensor; // set up DHT22 sensor
WiFiClient client;
Servo servo;
#ifdef AHP_BLYNK_OFF //temp
BlynkTimer timer;
#endif
//==================[Golbal variable]==================V
// Sensor reading variables
float dht_temp;
float dht_humidity;
float soil_temp;
//ThingSpeak channelID and Write API key
unsigned long myChannelNumber = 1974516;
const char * myWriteAPIKey = "FPK1MESWX9ONBY8F";
//Time variables
unsigned long cloud_lastTime = 0;
unsigned long cloudDelay = 15000; //seconds intervals to update ThingSpeak cloud
unsigned long screen_lastTime = 0;
unsigned long screenDelay = 2000; //seconds intervals to update the serial monitor and Green_LCD
int LCD_view = 0; // a variable to switch what's being displayed on the Green_LCD
bool cloudUpdate = false; // A flag to track if the last cloud update was successful
// Variables to caliberate the soil Moisture sensor
const int dryValue = 590; //you need to replace this value with Value_1
const int wetValue = 300; //you need to replace this value with Value_2
int soil_moistValue; // The analogue reading of the sensor
int soil_moistPercent;
const int moistThreshold = 60; // Water pump is activated ones soil moisture falls bellow this level
bool soil_isDry = false;
String myStatus = "";
//WiFi Credentials
const char ssid[] = "Wokwi-GUEST";
const char pass[] = "";
const int sensorMin = 0; // sensor minimum, discovered through experiment
const int sensorMax = 600; // sensor maximum, discovered through experiment
// -----------------[♦ AHP ♦]-----------------V
int Blynk_mode_get = 0;
int Plant_mode = 0;
int count = 0;
int lcd_state = 0;
int lcd_old_state = 0;
boolean pump_led_flag_CITY = false;
boolean pump_led_flag_GURDAN = false;
//----{Timer}------V
int seconds = 00;
int minutes = 00;
int hours = 00;
boolean list_flag = true;
//--{sensors}------V
int sensor_moist_data = 0;
int sensor_temperature_data = 0;
float sensor_humidity_data = 0;
int sensor_waterLVL_data = 0;
int sensor_TankerVol = 0;
float sensor_waterLVL_data_percent = 0;
//------{LCD)-----V
char line0[17];
char line1[17];
//---{tanker)-=---- V
//source: https://tankerplastic.com/%D9%85%D8%AE%D8%B2%D9%86-%D8%A2%D8%A8/
#define PI_NUM 3.14
uint8_t tanker_index = 22;
//مخزن آب عمودی
// const int tanker_volumes [] = { 80, 100, 150, 220, 350, 500, 550, 900, 1000, 1000, 1500, 1500, 2000, 3000, 4000, 5000, 5000, 6000, 8000, 10000, 15000, 20000};
//------- tanker_index : ---{ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21}
const int tanker_Diameter[] = { 50, 52, 55, 60, 69, 85, 72, 133, 88, 109, 121, 108, 132, 153, 183, 188, 222, 222, 195, 255, 255, 290 , 50 };
const int tanker_height [] = { 58, 75, 85, 102, 132, 119, 170, 132, 212, 145, 172, 200, 188, 208, 180, 225, 160, 190, 295, 235, 325, 335, 60 };
//===========================[BLYNK : READ | WRITE | Functions]===========================V
#ifdef AHP_BLYNK_OFF //temp
// This function is called every time the Virtual Pin 0 state changes
BLYNK_WRITE(V0) // Me: az site (Blynk) dade dar (ESP32) neveshte (write) mish
{
// Set incoming value from pin V0 to a variable
int value = param.asInt(); // assigning incoming value from pin V1 to a variable
// String i = param.asStr();
// double d = param.asDouble()
// Update state
Blynk.virtualWrite(V1, value); // Me: meghdare [value] be vritual pin (V1) dade mishe
Serial.println("blynk swicth: " + String(value));
//Me: etefaghi ke dare in ja moyofet in hast ke az blynk dare ,.......... {EDAM TOZIE BADAN MINVISAM}
}
BLYNK_WRITE(V4) //Me: plant silder get data
{
Plant_mode = param.asInt();
// Serial.println("Plant: " + String(value));
}
BLYNK_WRITE(V5) //Me: plant swicth button get data
{
Blynk_plant_mode (param.asInt());
}
// This function is called every time the device is connected to the Blynk.Cloud
// Me: dastortar khodemon ro dar in ghsmate migozriam ta bad az in key (MUC : ESP32) be (Blynk) mostal shode ejra beshe
BLYNK_CONNECTED()
{
// Change Web Link Button message to "Congratulations!"
/* Me:☻
Blynk.setProperty(V3, "offImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations.png");
Blynk.setProperty(V3, "onImageUrl", "https://static-image.nyc3.cdn.digitaloceanspaces.com/general/fte/congratulations_pressed.png");
Blynk.setProperty(V3, "url", "https://docs.blynk.io/en/getting-started/what-do-i-need-to-blynk/how-quickstart-device-was-made");
*/
}
// /* Me: eyk tabe karvorid dige
// BLYNK_READ(V5) // Widget in the app READs Virtal Pin V5 with the certain frequency
// {
// // This command writes Arduino's uptime in seconds to Virtual Pin V5
// Blynk.virtualWrite(5, millis() / 1000);
// }
// */
// This function sends Arduino's uptime every second to Virtual Pin 2.
#endif
//===========================[BLYNK : READ | WRITE | Functions]===========================V
//V==============V[♦ MAIN PORGRAM ♦}V==============V
void setup() {
Serial.begin(115200);
//---------------[pin mode]---------------V
pinMode(PUSH_BUTTON, INPUT_PULLUP); // 2
pinMode(RELAY_GURDAN_PUMP, OUTPUT); // 12
pinMode(RELAY_CITY_PUMP, OUTPUT); // 14
pinMode(BUZZER, OUTPUT); // 13
pinMode(WIFI_LED, OUTPUT);
pinMode(TRIG_PIN, OUTPUT); // Sets the trigPin as an Output // 4
pinMode(ECHO_PIN, INPUT); // Sets the echoPin as an Input
//---------------[LCD config]---------------v
Green_LCD.init();
Green_LCD.backlight();
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("IOT Group 7");
Blue_LCD.init();
Blue_LCD.backlight();
Blue_LCD.clear();
Blue_LCD.setCursor(0, 0);
Blue_LCD.print("Code by:");
Blue_LCD.setCursor(0, 1);
Blue_LCD.print("Haghighat panah");
delay(1000);
Blue_LCD.clear();
Green_LCD.clear();
//---------------[others config]---------------v
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
dallasTemp.begin(); // Start the DS18B20 sensor
//-------------[WIFI]--------------------------------V
connectToWiFi(5);
//---------------[ThingSpeak]------------------------------V
// ThingSpeak.begin(client); // Initialize ThingSpeak
//---------------[blynk]------------------------------V
#ifdef AHP_BLYNK_OFF //temp
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass); // turn on
// Setup a function to be called every second
timer.setInterval(2000L, send_Date2Bylnk); // turn on
timer.setInterval(2000L, checkBlynkStatus); // turn on
// timer.setInterval(1000L, temp1); //temp: turn on
// timer.setInterval(1000L, temp2); //temp: turn on
// timer.setInterval(1000L, temp3); //temp: turn on
// timer.setInterval(1000L, temp4); //temp: turn on
#endif
}
void loop() {
/*
// Reading from DHT22 Sensor
TempAndHumidity dht = dhtSensor.getTempAndHumidity();
dht_temp = dht.temperature;
dht_humidity = dht.humidity;
// Reading from Dallas Temperature sensor
dallasTemp.requestTemperatures();
soil_temp = dallasTemp.getTempCByIndex(0);
// Reading from the Soil moisture sensor
soil_moistValue = analogRead(SOIL_MOIST_PIN);
soil_moistPercent = map(soil_moistValue, dryValue, wetValue, 0, 100);
if (soil_moistPercent > 100)
soil_moistPercent = 100;
if (soil_moistPercent < 0)
soil_moistPercent = 0;
// Activate Water Pump and Alarm if moisture level falls below threshold
if (soil_moistPercent < moistThreshold) {
digitalWrite(RELAY_GURDAN_PUMP, HIGH);
digitalWrite(BUZZER, HIGH);
soil_isDry = true;
}
else {
digitalWrite(RELAY_GURDAN_PUMP, LOW);
digitalWrite(BUZZER, LOW);
soil_isDry = false;
}
// Update sensor readngs on displays every "screenDelay" seconds
if ((millis() - screen_lastTime) >= screenDelay) {
update_Display(LCD_view);
screen_lastTime = millis();
}
// Also update Screen if button is pushed
if (digitalRead(PUSH_BUTTON) == LOW) {
LCD_view++;
if (LCD_view > 3) {
LCD_view = 0;
}
update_Display(LCD_view);
}
// Update Sensor readings on cloud every "cloudDelay" seconds
if ((millis() - cloud_lastTime) >= cloudDelay) {
update_ThingSpeak();
cloud_lastTime = millis();
}
*/
// Serial.println(digitalRead(PUSH_BUTTON));
// delay(100);
// blynk_button();
#ifdef AHP_BLYNK_OFF //temp
Blynk.run();
timer.run();
#endif
// --------------------[wifi}--------------------V
if (WiFi.status() != WL_CONNECTED) {
Serial.println("WiFi connection lost. Reconnecting...");
connectToWiFi(5);
}
// --------------------[DHT]--------------------V
TempAndHumidity dht = dhtSensor.getTempAndHumidity();
sensor_temperature_data = dht.temperature;
sensor_humidity_data = dht.humidity;
soil_test(SOIL_MOIST_PIN, Blynk_mode_get);
//----------[water indictor(ultraSonic sensor) & tanker ]----V
int temp = ultraSonic();
// Serial.println(String(temp) + "cm");
tanker(temp);
//-----------[pump]----V
if (pump_led_flag_GURDAN) {
digitalWrite(RELAY_GURDAN_PUMP, HIGH);
tone(BUZZER, 700);
} else {
digitalWrite(RELAY_GURDAN_PUMP, LOW);
// noTone(BUZZER);
}
//-----------[File date send]---V
#ifndef AHP_BLYNK_OFF
send_Data2File();
#endif
/*
if (pump_led_flag_CITY) {
digitalWrite(RELAY_CITY_PUMP, HIGH);
tone(BUZZER, 500);
} else {
digitalWrite(RELAY_CITY_PUMP, LOW);
// noTone(BUZZER);
}
if(!pump_led_flag_GURDAN && !pump_led_flag_CITY) noTone(BUZZER); */
#ifndef AHP_BLYNK_OFF //temp
#endif
}
//^==============^[♦ MAIN PORGRAM ♦}^==============^
// ====================[Functions]====================V
void update_Display(int viewOption) {
Serial.println("Air Temp: " + String(dht_temp, 2) + "°C");
Serial.println("Humidity: " + String(dht_humidity, 1) + "%");
Serial.println("Soil Temp: " + String(soil_temp, 2) + "°C");
Serial.println("soil Moisture: " + String(soil_moistPercent) + "%");
Serial.println("---");
switch (viewOption) {
case 0: //Green_LCD screen zero also Notifies when Soil is dry
if (!soil_isDry) {
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("Temp: " + String(dht_temp, 2) + char(223) + "C");
Green_LCD.setCursor(0, 1);
Green_LCD.print("Humidity: " + String(dht_humidity, 1) + "%");
}
else {
Green_LCD.clear();
Green_LCD.setCursor(5, 0);
Green_LCD.print("ALERT!");
Green_LCD.setCursor(0, 1);
Green_LCD.print("Soil is Dry");
}
break;
case 1: //Green_LCD Screen one also flashes if Soil moisture is too low
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("Soil Temp: " + String(soil_temp, 2) + "C");
Green_LCD.setCursor(0, 1);
Green_LCD.print("Soil Moist: " + String(soil_moistPercent) + "%");
break;
case 2: //Gives the current status of the soil moisture and the water pump
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("Moisture is ");
Green_LCD.setCursor(0, 1);
Green_LCD.print("Pump is ");
if (soil_isDry) {
Green_LCD.setCursor(10, 0);
Green_LCD.print("LOW");
Green_LCD.setCursor(8, 1);
Green_LCD.print("ON");
}
else {
Green_LCD.setCursor(12, 0);
Green_LCD.print("OKAY");
Green_LCD.setCursor(8, 1);
Green_LCD.print("OFF");
}
break;
// Green_LCD Screen three
case 3:
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("Last CloudUpdate");
Green_LCD.setCursor(0, 1);
if (cloudUpdate)
Green_LCD.print("Successful");
else
Green_LCD.print("Failed !");
Green_LCD.setCursor(13, 1);
Green_LCD.print(String((millis() - cloud_lastTime) / 1000) + "s");
break;
}
}
void update_ThingSpeak() {
// set the fields with the values on thingspeak
ThingSpeak.setField(1, dht_humidity);
ThingSpeak.setField(2, dht_temp);
// ThingSpeak.setField(3, soil_temp);
ThingSpeak.setField(4, soil_moistPercent);
if (soil_moistPercent < moistThreshold)
myStatus = String("Soil Moisture level is OKAY");
else
myStatus = String("Soil Moisture level TOO LOW !");
ThingSpeak.setStatus(myStatus);
int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
if (x == 200) {
Serial.println("Channel update successful.");
cloudUpdate = true;
}
else {
Serial.println("Problem updating channel. HTTP error code " + String(x));
cloudUpdate = false;
// Notify the Update error in Green_LCD
Green_LCD.clear();
Green_LCD.setCursor(0, 0);
Green_LCD.print("Cloud Update");
Green_LCD.setCursor(0, 1);
Green_LCD.print("Error " + String(x));
delay(1000);
Green_LCD.clear();
}
}
//----------------[♦ AHP functions ♦]----------------V
//Me:
void soil_test(int pin_soil, int mode) {
// read the sensor:
// dark = 10-20
// midummedium = 21-50
// bright = 51-80
int sens_dataSet[] = {500, 2000, 4000, 6000};
sensor_moist_data = map(analogRead(pin_soil), 0, 4095, 0, 10000);
// int sensor_moist_data =analogRead(pin_soil) ;
/*
updateDisplay(2);
Green_LCD.setCursor(0, 0);
Green_LCD.print("S: " + String(sensor_moist_data));
Green_LCD.setCursor(0, 1);
Green_LCD.print("B: " + String(Blynk));
*/
//Me: replacment for Green_LCD,clear function lag for not having delay-------------V
lcd_state = sensor_moist_data;
if (lcd_state != lcd_old_state) { //Me: old Green_LCD print
Green_LCD.clear();
updateDisplay(2);
Green_LCD.setCursor(0, 0);
Green_LCD.print("S: " + String(sensor_moist_data));
}
delay(500);
lcd_old_state = lcd_state; // Me: {lcd_old_state} va {lcd_state} = (Global vars) hastand
Green_LCD.setCursor(0, 1);
Green_LCD.print("B: " + String(mode));
// do something different depending on the range value:
switch (mode) {
case 0: // your hand is on the sensor
if (sens_dataSet[0] < sensor_moist_data && sensor_moist_data <= sens_dataSet[1]) {
Serial.println("dark");
pump_led_flag_GURDAN = true;
}
else pump_led_flag_GURDAN = false;
break;
case 1: // your hand is close to the sensor
if (sens_dataSet[1] < sensor_moist_data && sensor_moist_data <= sens_dataSet[2]) {
Serial.println("dim");
pump_led_flag_GURDAN = true;
}
else pump_led_flag_GURDAN = false;
break;
case 2: // your hand is a few inches from the sensor
if (sens_dataSet[2] < sensor_moist_data && sensor_moist_data <= sens_dataSet[3]) {
Serial.println("medium");
pump_led_flag_GURDAN = true;
}
else pump_led_flag_GURDAN = false;
break;
case 3: // your hand is nowhere near the sensor
if (sensor_moist_data > sens_dataSet[3]) {
Serial.println("bright");
pump_led_flag_GURDAN = true;
}
else pump_led_flag_GURDAN = false;
break;
default:
// pump_led_flag_GURDAN = false ;
Serial.println("not setuped Mode");
break;
}
// delay(100); // delay in between reads for stability
}
#ifdef AHP_BLYNK_OFF //temp
void send_Date2Bylnk() {
Blynk.virtualWrite(V2, millis() / 1000);
Blynk.virtualWrite(V6, sensor_waterLVL_data); // water level
Blynk.virtualWrite(V10, sensor_waterLVL_data_percent); // water level percentage
Blynk.virtualWrite(V7, sensor_temperature_data); // temperature
Blynk.virtualWrite(V8, sensor_humidity_data); // humidity
Blynk.virtualWrite(V9, sensor_moist_data); // moisture
}
void Blynk_plant_mode(int plant_mode_button) {
if (plant_mode_button == 1) {
Serial.println("sending : " + String(Plant_mode));
Blynk_mode_get = Plant_mode;
}
}
void checkBlynkStatus() { // called every 3 seconds by SimpleTimer
bool isconnected = Blynk.connected();
if (isconnected == false) {
Serial.print("Blynk Not Connected ");
digitalWrite(WIFI_LED, LOW);
} else if (isconnected == true) {
digitalWrite(WIFI_LED, HIGH);
//Serial.println("Blynk Connected");
}
}
#endif
void send_Data2File() {
if (list_flag) {
list_flag=false;
Serial.println("Time | Tanker Volume | Water level | Water level percent | Soil moisture level | Temperature level | Humidity level");
// ("00:00:00 | 10 | 10 | 10.00 | 1122 | 100 | 50.0 ")
Serial.println("------------------------------------------------------------------------------------------------------------------------------------");
} else {
// for (long seconds = 00; seconds < 60; seconds = seconds + 1) {
// float temp = dht.readTemperature(); //Reading the temperature as Celsius and storing in temp
// float hum = dht.readHumidity(); //Reading the humidity and storing in hum
Serial.print(String(hours)+":"+String(minutes)+":"+String(seconds));
Serial.print(" | "+String(sensor_TankerVol));
Serial.print(" | "+String(sensor_waterLVL_data));
Serial.print(" | "+String(sensor_waterLVL_data_percent));
Serial.print(" | "+String(sensor_moist_data));
Serial.print(" | "+String(sensor_temperature_data));
Serial.println(" | "+String(sensor_humidity_data));
/*
Serial.print(String(hours)+":"+String(minutes)+":"+String(seconds));
Serial.print(" | "+String(sensor_TankerVol));
Serial.print(" | "+String(sensor_waterLVL_data));
Serial.print(" | "+String(sensor_waterLVL_data_percent));
Serial.print(" | "+String(sensor_moist_data));
Serial.print(" | "+String(sensor_temperature_data));
Serial.println(" | "+String(sensor_humidity_data));
*/
seconds++;
if (seconds >= 59) {
minutes = minutes + 1;
seconds=0;
}
if (minutes > 59) {
hours = hours + 1;
minutes = 0;
}
delay(1000);
// }
}
}
void connectToWiFi(int reconect_tries) {
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, pass, 6);
while (WiFi.status() != WL_CONNECTED && reconect_tries < 10) {
delay(100);
Serial.print(".");
reconect_tries++;
}
if (WiFi.status() == WL_CONNECTED) {
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
Green_LCD.setCursor(0, 0);
Green_LCD.print("Connecting WiFi");
Green_LCD.clear();
Green_LCD.print("Connected to:");
Green_LCD.setCursor(0, 1);
Green_LCD.print(WiFi.localIP());
delay(500);
Green_LCD.clear();
} else {
Serial.println("");
Serial.println("Failed to connect to WiFi");
}
}
int ultraSonic() { // MeE: this function converts sound wave to distance (CM)
long duration = 0;;
float distance = 0;;
// Clears the trigPin
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(ECHO_PIN, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2; // MeE : (0.034) is the sped of sound
return Postive_round(distance);
}
void tanker (int Distanceee) { // MeE: this function works works with cylinder tanks volume
// Me: Tammi mohasebat ba estfade az vahad (Cm) hasteh
// MeE: Here we are going to get the distance of the empty part of Tenaker
int empty_height = ( tanker_height [tanker_index] - Distanceee );
if (empty_height < 0) empty_height = 0; // Me: if the empty space was negative number it means it the tanker already empty so we give thw value [0]
//-----------------[ V = πr2 h]-------------------------V
//MeE: the reference had D: diameter we have to convert to radius first
unsigned int tanker_radius = tanker_Diameter[tanker_index] / 2; // (r=d/2)
unsigned int tanker_full_volume =( PI_NUM * (tanker_radius * tanker_radius) * tanker_height [tanker_index])/1000; // (V1 = πr2 h1)
unsigned int water_level = (PI_NUM * (tanker_radius * tanker_radius) * empty_height)/1000 ; // ( V2 = πr2 h2)
float water_level_percent = ((float)water_level / (float)tanker_full_volume) * 100;
// --------------------[Conditions ]--------------------V
if(water_level_percent >= 85.0) pump_led_flag_CITY = true;
else pump_led_flag_CITY = false;
// --------------------[(LCD or Serial),print]--------------------V
Blue_LCD.setCursor(0, 0);
Blue_LCD.println("wLV:" + String(water_level) + "L");
Blue_LCD.setCursor(10, 0);
Blue_LCD.println(String(water_level_percent) + "%");
// Blue_LCD.print(" ");
// Blue_LCD.println("wLV:" + String(water_level) + "L " + String(water_level_percent) + "%");
Blue_LCD.setCursor(0, 1);
Blue_LCD.println("TANK_VOL:" + String(tanker_full_volume )+"L");
updateDisplay(1); // clear lcd
delayMicroseconds(1000);
// Serial.println("wLV:" + String(water_level) + "L|" + String(water_level_percent) + "%");
// Serial.println("TANK_VOL:" + String(tanker_full_volume)+"L");
sensor_waterLVL_data = water_level;
sensor_waterLVL_data_percent = water_level_percent;
sensor_TankerVol = tanker_full_volume;
}
int Postive_round(float value) { //MeE: this function rounds the number
int upperVal = value;
float decimalVal = value - upperVal;
if (decimalVal < 0.5) return upperVal;
else return upperVal + 1;
}
void updateDisplay(uint8_t address) {
if(address == 1){
Blue_LCD.setCursor(0,0);
Blue_LCD.print(line0);
Blue_LCD.print(line1);
} else if (address == 2){
Green_LCD.setCursor(0,0);
Green_LCD.print(line0);
Green_LCD.print(line1);
}
}
// ------------------[test functions]------------------V
#ifdef AHP_BLYNK_OFF //temp
void temp1() {
Blynk.virtualWrite(V6, sensor_waterLVL_data);
}
void temp2() {
TempAndHumidity dht = dhtSensor.getTempAndHumidity();
sensor_temperature_data = dht.temperature;
Blynk.virtualWrite(V7, sensor_temperature_data);
}
void temp3() {
TempAndHumidity dht = dhtSensor.getTempAndHumidity();
sensor_humidity_data = dht.humidity;
Blynk.virtualWrite(V8, sensor_humidity_data);
}
void temp4() {
Blynk.virtualWrite(V9, sensor_moist_data);
}
#endif
//----------------[unused functions]----------------V
// Me: dokem test bare taghir mode (plant)
void blynk_button () {
int t_array[] = {0, 1, 2, 3};
if (digitalRead(PUSH_BUTTON) == LOW) {
Blynk_mode_get = t_array[count];
count++;
// Serial.println(dcount);
// delay(100);
delay(100);
if (count >= 4 ) count = 0;
}
}