I Read Your FAQ on BlynkTimer and made some changes in code,
i don’t know its right or not but Everything working fine, except LDR on and Off.
below is my revised code
#define BLYNK_TEMPLATE_NAME "Anant Akshay Urja R5"
#define BLYNK_AUTH_TOKEN "hnAnk_AC5D_qzr04NQgqlILmstMGOpDj"
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <WiFiClientSecure.h>
char ssid[] = "INTEX_CC3CBC"; // Honor 7X_1A08
char pass[] = "12345678"; //b42d9675
#include <ESP32Servo.h>
#include <time.h>
#include "ACS712.h"
#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN 4 // Temparture and Humididty Sensor of Boost Converter
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
unsigned long previousMillis = 0;
unsigned long interval = 30000;
const char* host = "script.google.com"; // Host & httpsPort
const int httpsPort = 443;
WiFiClientSecure Client;
const char* fingerprint = "0x56, 0xED, 0xC7, 0xDA, 0xBF, 0x51, 0x12, 0xC2, 0x79, 0x43, 0xC6, 0x01, 0xAB, 0xF7, 0x88, 0x98, 0x0F, 0x97, 0xB2, 0xB8";
String GAS_ID = "AKfycbwNJIa6FVXV8NMqXKrZXTl7PvKtHVjVH9X2LqqiG53MLeS6RerjVrLQNhFQnWiFi4L4"; //--> spreadsheet script ID
int solarvoltage = 34; // Solar Voltage Sensor
int batteryvoltage = 39; // Battery Voltage Sensor
float correctionfactor = 1.1;
float vout = 0.0;
float vin = 0.0;
float R1 = 30000 + 150000;
float R2 = 7500;
int value = 0.0;
int solarcurrent = 35; // Solar Current Sensor
int batterycurrent = 36; // Battery Current Sensor
ACS712 ACS(35, 5.0, 4095, 66);
double voltage = 0.0;
double current = 0.0;
// LDR pin connections
//name = analogpin;
int ldrlt =36; //LDR top left - BOTTOM LEFT <--- BDG
int ldrrt =39; //LDR top rigt - BOTTOM RIGHT
int ldrld =34; //LDR down left - TOP LEFT
int ldrrd =35; //ldr down rigt - TOP RIGHT
Servo horizontal; // horizontal servo
int servoh = 90; // start at degree
int servohLimitHigh = 180;
int servohLimitLow = 1;
// 65 degrees MAX
Servo vertical; // vertical servo
int servov = 90; // start at degree
int servovLimitHigh = 180;
int servovLimitLow = 1;
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, pass);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
//delay(1000);
}
unsigned long currentMillis = millis();
//if WiFi is down, try reconnecting every CHECK_WIFI_TIME seconds
if ((WiFi.status() != WL_CONNECTED) && (currentMillis - previousMillis >=interval)) {
Serial.print(millis());
Serial.println("Reconnecting to WiFi...");
WiFi.disconnect();
WiFi.reconnect();
previousMillis = currentMillis;
}
Serial.println(WiFi.localIP());
}
BLYNK_WRITE(V0)
{
int value = param.asInt();
Serial.println(value);
if(value == 0)
{
digitalWrite(23, LOW); // Solar Power On Off
Serial.println("solar Off");
}
if(value == 1)
{
digitalWrite(23, HIGH);
Serial.println("Solar On");
}
}
BLYNK_WRITE(V1)
{
int value = param.asInt();
Serial.println(value);
if(value == 0)
{
digitalWrite(22, LOW); // Battery Charging Power On Off
Serial.println("Battery Off");
}
if(value == 1)
{
digitalWrite(22, HIGH);
Serial.println("Battery On");
}
}
BLYNK_WRITE(V2)
{
int value = param.asInt();
Serial.println(value);
if(value == 0)
{
digitalWrite(21, LOW); // Cooling Fan for Boost Converter Power On Off
Serial.println("Fan Off");
}
if(value == 1)
{
digitalWrite(21, HIGH);
Serial.println("Fan On");
}
}
BLYNK_WRITE(V3)
{
int value = param.asInt();
Serial.println(value);
if(value == 0)
{
digitalWrite(36, LOW); // LDR Top Left Solar Tracker Power On off
digitalWrite(39, LOW); // LDR Top Right Solar Tracker Power On off
digitalWrite(34, LOW); // LDR Bottom Left Solar Tracker Power On off
digitalWrite(35, LOW); // LDR Bottom Right Solar Tracker Power On off
Serial.println("Solar Tracker Off");
}
if(value == 1)
{
digitalWrite(36, HIGH); // LDR Top Left Solar Tracker Power On off
digitalWrite(39, HIGH); // LDR Top Right Solar Tracker Power On off
digitalWrite(34, HIGH); // LDR Bottom Left Solar Tracker Power On off
digitalWrite(35, HIGH); // LDR Bottom Right Solar Tracker Power On off
Serial.println("Solar Tracker On");
}
//delay(100);
}
void Sensorvalue1()
{
int sdata = 0.0;
value = analogRead(solarvoltage);
vout = (value * 5.0) / 4096.0;
vin = vout / (R2/(R1+R2));
vin = vin - correctionfactor;
if (vin < 0.01) {
vin = 0.0;
}
Serial.print("Solar Voltage= ");
Serial.println(vin, 2);
sdata = vin;
Blynk.virtualWrite(V4, sdata);
//delay(100);
}
void Sensorvalue2()
{
int sdata = 0.0;
value = analogRead(batteryvoltage);
vout = (value * 3.3) / 4096.0;
vin = vout / (R2/(R1+R2));
vin = vin - correctionfactor;
if (vin < 0.01) {
vin = 0.0;
}
Serial.print("Battery Voltage= ");
Serial.println(vin, 2);
sdata = vin;
Blynk.virtualWrite(V5, sdata);
//delay(100);
}
void Sensorvalue3(){
for(int i = 0.0; i < 1000; i++);
{
voltage = (voltage + (0.0264 * analogRead(35)));
//delay (100);
}
voltage = voltage / 1000;
current = (voltage - 2.5) / 66;
if (current < 0.01) {
current = 0.0;
}
Serial.print("Solar Current= ");
Serial.println(current, 2);
Blynk.virtualWrite(V6, current);
//delay(100);
}
void Sensorvalue4(){
for(int i = 0.0; i < 1000; i++);
{
voltage = (voltage + (0.0264 * analogRead(36)));
//delay (100);
}
voltage = voltage / 1000;
current = (voltage - 2.5) / 66;
if (current < 0.01) {
current = 0.0;
}
Serial.print("Battery Current= ");
Serial.println(current, 2);
Blynk.virtualWrite(V7, current);
//delay(100);
}
void Sensorvalue5()
{
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V8, t);
Blynk.virtualWrite(V9, h);
Serial.print("Temperature : ");
Serial.println(t, 2);
Serial.print("Humidity : ");
Serial.println(h, 2);
//delay(100);
}
void Sensorvalue7()
{
int lt = analogRead(ldrlt); // top left
int rt = analogRead(ldrrt); // top right
int ld = analogRead(ldrld); // down left
int rd = analogRead(ldrrd); // down right
int dtime = 10; // dtime=diffirence time,
int tol = 10; // tol=toleransi
int avt = (lt + rt) / 2; // average value top
int avd = (ld + rd) / 2; // average value down
int avl = (lt + ld) / 2; // average value left
int avr = (rt + rd) / 2; // average value right
int dvert = avt - avd; // check the diffirence of up and down
int dhoriz = avl - avr;// check the diffirence og left and rigt
if (-1*tol > dvert || dvert > tol)
{
if (avt > avd)
{
servov = ++servov;
if (servov > servovLimitHigh)
{servov = servovLimitHigh;}
}
else if (avt < avd)
{servov= --servov;
if (servov < servovLimitLow)
{ servov = servovLimitLow;}
}
vertical.write(servov);
}
if (-1*tol > dhoriz || dhoriz > tol) // check if the diffirence is in the tolerance else change horizontal angle
{
if (avl > avr)
{
servoh = --servoh;
if (servoh < servohLimitLow)
{
servoh = servohLimitLow;
}
}
else if (avl < avr)
{
servoh = ++servoh;
if (servoh > servohLimitHigh)
{
servoh = servohLimitHigh;
}
}
else if (avl = avr)
{
//delay(1000);
}
horizontal.write(servoh);
}
Serial.print("Average Value Top : ");
Serial.println(avt);
Serial.print("Average Value Down : ");
Serial.println(avd);
Serial.print("Average Value Left : ");
Serial.println(avl);
Serial.print("Average Value Right : ");
Serial.println(avr);
Serial.print("time diffirence ");
Serial.println(dtime);
Serial.print("Vertical Servo Position : ");
Serial.println(servov);
Serial.print("Horizontal Servo Position : ");
Serial.println(servoh);
Serial.print("tolerans ");
Serial.println(tol);
//delay(dtime);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
WiFi.begin(ssid, pass);
initWiFi();
dht.begin(); // Initialize the DHT sensor
servoh = horizontal.read();
servov = vertical.read();
horizontal.attach(18);
horizontal.attach(16);
vertical.attach(17);
vertical.attach(5);
horizontal.write(90);
vertical.write(90);
pinMode(23,OUTPUT); // Solar Power On Off
pinMode(22,OUTPUT); // Battery Charging Power On Off
pinMode(21,OUTPUT); // Cooling Fan for Boost Converter Power On Off
pinMode(36,INPUT); // LDR Top Left Solar Tracker Power On off
pinMode(39,INPUT); // LDR Top Right Solar Tracker Power On off
pinMode(34,INPUT); // LDR Bottom Left Solar Tracker Power On off
pinMode(35,INPUT); // LDR Bottom Right Solar Tracker Power On off
pinMode(35,INPUT); // Solar Current Sensor
pinMode(36,INPUT); // Battery Current Sensor
pinMode(34,INPUT); // Solar Voltage Sensor
pinMode(39,INPUT); // Battery Voltage Sensor
pinMode(4,INPUT); // Temparture and Humididty Sensor of Boost Converter
timer.setInterval(1000L, Sensorvalue1);
timer.setInterval(1000L, Sensorvalue2);
timer.setInterval(1000L, Sensorvalue3);
timer.setInterval(1000L, Sensorvalue4);
timer.setInterval(1000L, Sensorvalue5);
timer.setInterval(1000L, Sensorvalue7);
}
void loop()
{
timer.run(),
Blynk.run();
}```