Blynk Solartracker

Why is your code double spaced? It’s so much harder to read that way.

When you use triple backticks they need to be on a line of their own.
When you post serial output it needs to have triple backticks too.

It appear that you’re no longer getting the error message, is that issue solved now?

Pete.

sorry for inconvenience, i am new in this forum and don’t know how to post code, but i will check and improve it soon.

now reading LDR value are not showing any issues, but still i can not able to start and stop Solar Tracker.

that Error come when i use Solar tracker On and off Switch on Blynk app.

below are the Serial Monitor Details

02:14:43.959 -> 0E (1935271) gpio: gpio_set_level(226): GPIO output gpio_num error
02:14:44.023 -> E (1935271) gpio: gpio_set_level(226): GPIO output gpio_num error
02:14:44.087 -> E (1935340) gpio: gpio_set_level(226): GPIO output gpio_num error
02:14:44.182 -> E (1935410) gpio: gpio_set_level(226): GPIO output gpio_num error
02:14:44.247 -> : Solar Tracker Off
02:14:44.247 -> Battery Voltage= 0.00
02:14:44.316 -> Solar Current= 0.00
02:14:44.392 -> Battery Current= 0.00
02:14:44.424 -> Average Value Top : 0
02:14:44.456 -> Average Value Down : 4
02:14:44.488 -> Average Value Left : 4
02:14:44.520 -> Average Value Right : 0
02:14:44.520 -> Vertical Servo Position : 90
02:14:44.551 -> Horizontal Servo Position : 90

Okay, let me know when you’ve done that and I’ll take a look.

Pete.

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 
int ldrrt =39; //LDR top right
int ldrld =34; //LDR down left
int ldrrd =35; //LDR down right


Servo horizontal; // horizontal servo
int servoh = 90;  // start at degree    
int servohLimitHigh = 180;
int servohLimitLow = 0;

Servo vertical; // vertical servo
int servov = 90;  // start at degree    
int servovLimitHigh = 180;
int servovLimitLow = 0;

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.print(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.print(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.print(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.print(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.print(" : 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 = 100; // LDR Value 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("Vertical Servo Position : ");
Serial.println(servov);

Serial.print("Horizontal Servo Position : ");
Serial.println(servoh);
}      

void setup()
{
Serial.begin(9600);
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
WiFi.begin(ssid, pass);

initWiFi();

dht.begin(); // Initialize the DHT sensor

horizontal.attach(18);
horizontal.attach(16);
horizontal.write(90);

vertical.attach(17);
vertical.attach(5);
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(50L,  Sensorvalue7); // Solar Tracker LDR and Servo
  timer.setInterval(123L,  Sensorvalue1); // Solar VOltage Sensor
  timer.setInterval(143L,  Sensorvalue2); // battery Voltage Sensor
  timer.setInterval(163L,  Sensorvalue3); // Solar Current Sensor
  timer.setInterval(183L,  Sensorvalue4); // Battery Current Sensor
  timer.setInterval(5000L,  Sensorvalue5); // Temprature and Humidity Sensor
}
void loop()
{
  timer.run(),
  Blynk.run(); 
  
  }```

You’re using the same four pins for two different things, you can’t do this.

The error message that you’re seeing…

is because you’re trying to write to GPIO pins that are input only (and which you’ve declared as inputs in your pinMode statements - twice!)…

You’ll see in the randomnerds tutorial I linked to earlier that these pins are input only…

Changing to GPIOs that are input/output isn’t the solution, because momentarily writing a 1 or 0 to these GPIOs won’t change the way in which your timed functions read these pins.

I’d suggest that you use a global variable to indicate whether tracking should be on or off, then check the state of this variable before moving either of your servos.

There are numerous other issues with your sketch, including…

  • You’re manually managing your WiFi connection, then using Blynk.begin() - which manages your WiFi and Blynk server connection, but is a blocking function which will prevent all code execution if a WiFi or Blynk connection can’t be established.

  • I don’t understand why you’ve staggered your timers in this way. As I said earlier, you just need to use a timer to call a function which then calls the other functions - or simply put all of the code in one function, but that’s probably not a good approach.

  • You’ve created aliases for som of your pins, such as ldrlt, ldrrt etc….

but you aren’t then using these aliases when referring to the pins.

  • You’re still doing millis comparisons in some parts of your code, 8nstead of using BlynkTimer…

Pete.

corrected this mistake, thanks for observing.

i changed those pin with input and output ADC2 Pin, because i planned to use SIM 800, rather then wifi.

can you tell me what exactly i mention in code, to make this happen, or can you suggest any article which explain this.

mention LDR pin aliases wherever Pin number mention for LDR.

Removed this because no i am no more using wifi.

but now i am facing issue with SIM 800 Module.
i remove all Sensor connection with ESP32 and trying to connect with only SIM 800 Module with blynk. but not getting succusses.

below is my revised code.

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xyz"
#define BLYNK_TEMPLATE_NAME "abc"
#define BLYNK_AUTH_TOKEN "123"

#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

const char auth[] = BLYNK_AUTH_TOKEN;

char apn[] = "airtelgprs.com";
char user[] = "";
char pass[] = "";
//int port = 8080;

#include <SoftwareSerial.h>
SoftwareSerial SerialAT(3, 1); // RX, TX

#define SerialMon Serial
#define SerialAT Serial1

#define TINY_GSM_DEBUG SerialMon

TinyGsm modem(SerialAT);

#include <ESP32Servo.h>
#include <time.h>
BlynkTimer timer;

#include "ACS712.h"
#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN 12 // Temparture and Humididty Sensor of Boost Converter
DHT dht(DHTPIN, DHTTYPE);


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;
int i = 0.0;

// LDR pin connections
//name = analogpin;
int ldrlt =33; //LDR top left 
int ldrrt =25; //LDR top right 
int ldrld =26; //LDR down left
int ldrrd =27; //ldr down right


Servo horizontal; // horizontal servo
int servoh = 90;  // start at degree    
int servohLimitHigh = 180;
int servohLimitLow = 0;

Servo vertical; // vertical servo
int servov = 90;  // start at degree    
int servovLimitHigh = 180;
int servovLimitLow = 0;


BLYNK_WRITE(V0)
{
  int value = param.asInt();
  Serial.print(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.print(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.print(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.print(value);
  if(value == 0)
  {
  digitalWrite(ldrlt, LOW); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, LOW); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, LOW); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, LOW); // LDR Bottom Right Solar Tracker Power On off
  Serial.println(" : Solar Tracker Off");

  }
  if(value == 1)
  {
  digitalWrite(ldrlt, HIGH); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, HIGH); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, HIGH); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, HIGH); // LDR Bottom Right Solar Tracker Power On off
  Serial.println(" : Solar Tracker On");
 }
   //delay(100);
//#define Interval 100l 
}

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(solarcurrent)));
  //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(batterycurrent)));
  //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()
{
servoh = horizontal.read();
servov = vertical.read();

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 = 100; // LDR Value 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("Vertical Servo Position : ");
Serial.println(servov);

Serial.print("Horizontal Servo Position : ");
Serial.println(servoh);

//delay(dtime);
}      

void setup()
{
SerialMon.begin(9600);
delay (10);

SerialAT.begin(9600); 
#define Interval 1000l

 Serial.println("Initializing modem...");
 modem.restart();

 String modemInfo = modem.getModemInfo();
 SerialMon.print("Modem Info: ");
 SerialMon.println(modemInfo);
  
Blynk.begin(auth, modem, apn, user, pass);

dht.begin(); // Initialize the DHT sensor

horizontal.write(90);
horizontal.attach(18);
horizontal.attach(16);

vertical.write(90);
vertical.attach(17);
vertical.attach(5);


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(ldrlt,INPUT); // LDR Top Left Solar Tracker Power On off
pinMode(ldrrt,INPUT); // LDR Top Right Solar Tracker Power On off
pinMode(ldrld,INPUT); // LDR Bottom Left Solar Tracker Power On off
pinMode(ldrrd,INPUT); // LDR Bottom Right Solar Tracker Power On off
pinMode(solarcurrent,INPUT); // Solar Current Sensor
pinMode(batterycurrent,INPUT); // Battery Current Sensor
pinMode(solarvoltage,INPUT); // Solar Voltage Sensor
pinMode(batteryvoltage,INPUT); // Battery Voltage Sensor
pinMode(4,INPUT); // Temparture and Humididty Sensor of Boost Converter


  timer.setInterval(50L,  Sensorvalue7); // Solar Tracker LDR and Servo
  timer.setInterval(123L,  Sensorvalue1); // Solar VOltage Sensor
  timer.setInterval(143L,  Sensorvalue2); // battery Voltage Sensor
  timer.setInterval(163L,  Sensorvalue3); // Solar Current Sensor
  timer.setInterval(183L,  Sensorvalue4); // Battery Current Sensor
  timer.setInterval(5000L,  Sensorvalue5); // Temprature and Humidity Sensor
}


void loop()
{
  Blynk.run();  
  timer.run();
  
  }```

and below is my Serial Monitor Output

21:47:36.623 ->     ___  __          __
21:47:36.623 ->    / _ )/ /_ _____  / /__
21:47:36.654 ->   / _  / / // / _ \/  '_/
21:47:36.687 ->  /____/_/\_, /_//_/_/\_\
21:47:36.717 ->         /___/ v1.2.0 on ESP32
21:47:36.750 -> 
21:47:36.750 ->  #StandWithUkraine    https://bit.ly/swua
21:47:36.782 -> 
21:47:36.817 -> 
21:47:36.817 -> [11478] Modem init...
21:47:47.000 -> [21780] Cannot init
22:25:22.240 -> ��..
22:25:33.154 -> Modem Info: 
22:25:33.154 -> [11053] 
22:25:33.154 ->     ___  __          __
22:25:33.186 ->    / _ )/ /_ _____  / /__
22:25:33.218 ->   / _  / / // / _ \/  '_/
22:25:33.250 ->  /____/_/\_, /_//_/_/\_\
22:25:33.283 ->         /___/ v1.2.0 on ESP32
22:25:33.314 -> 
22:25:33.314 ->  #StandWithUkraine    https://bit.ly/swua
22:25:33.347 -> 
22:25:33.347 -> 
22:25:33.347 -> [11175] Modem init...
22:25:43.563 -> [21477] Cannot init

I don’t really understand any of your responses to the issues I pointed out earlier. If you want assistance then you need to verbalise your questions better.

This makes no sense at all.

Pins 1 and 3 are the UART0 pins that are also connected to to the USB port (via a TTL to USB chip). You’re attempting to use them to also communicate with your SIM800.

The ESP32 also has two other hardware UARTs, so there is no need to use software serial to create a software UART.

You’ve already read this article, because you liked it yesterday, but you clearly haven’t understood it…

Pete.

ok @PeteKnight i will, i am new in this iOT field, i will try to explain as much as possible. but first of all i am trying to connect with ESP32, SIM800 and Blynk.
i checked your Article again and some other forum discussion also. from that i had done some changes in Code. But Still SIM800 not connecting.

Below is my Code.

#define BLYNK_PRINT Serial
#define BLYNK_TEMPLATE_ID "xyz"
#define BLYNK_TEMPLATE_NAME "ABC"
#define BLYNK_AUTH_TOKEN "123"

#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>

#define rxPin 16
#define txPin 17
HardwareSerial gsmSerial(2);
TinyGsm modem(gsmSerial);

#define TINY_GSM_DEBUG gsmSerial

const char auth[] = BLYNK_AUTH_TOKEN;
char apn[] = "airtelgprs.com";
char user[] = "";
char pass[] = "";

#include <ESP32Servo.h>
BlynkTimer timer;

#include "ACS712.h"
#include "DHT.h"
#define DHTTYPE DHT22
#define DHTPIN 13 // Temparture and Humididty Sensor of Boost Converter
DHT dht(DHTPIN, DHTTYPE);


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;
int i = 0.0;

// LDR pin connections
//name = analogpin;
int ldrlt =33; //LDR top left 
int ldrrt =25; //LDR top right 
int ldrld =26; //LDR down left
int ldrrd =27; //ldr down right


Servo horizontal; // horizontal servo
int servoh = 90;  // start at degree    
int servohLimitHigh = 180;
int servohLimitLow = 0;

Servo vertical; // vertical servo
int servov = 90;  // start at degree    
int servovLimitHigh = 180;
int servovLimitLow = 0;


BLYNK_WRITE(V0)
{
  int value = param.asInt();
  Serial.print(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.print(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.print(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.print(value);
  if(value == 0)
  {
  digitalWrite(ldrlt, LOW); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, LOW); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, LOW); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, LOW); // LDR Bottom Right Solar Tracker Power On off
  Serial.println(" : Solar Tracker Off");

  }
  if(value == 1)
  {
  digitalWrite(ldrlt, HIGH); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, HIGH); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, HIGH); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, HIGH); // LDR Bottom Right Solar Tracker Power On off
  Serial.println(" : Solar Tracker On");
 }
   //delay(100);
//#define Interval 100l 
}

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(solarcurrent)));
  //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(batterycurrent)));
  //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()
{
servoh = horizontal.read();
servov = vertical.read();

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 = 100; // LDR Value 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("Vertical Servo Position : ");
Serial.println(servov);

Serial.print("Horizontal Servo Position : ");
Serial.println(servoh);

//delay(dtime);
}      

void setup()
{
Serial.begin(9600);
delay (10);

gsmSerial.begin(9600);

 Serial.println("Initializing modem...");
 modem.restart();

  
Blynk.begin(auth, modem, apn, user, pass);

dht.begin(); // Initialize the DHT sensor

horizontal.write(90);
horizontal.attach(18);
horizontal.attach(16);

vertical.write(90);
vertical.attach(17);
vertical.attach(5);


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(ldrlt,INPUT); // LDR Top Left Solar Tracker Power On off
pinMode(ldrrt,INPUT); // LDR Top Right Solar Tracker Power On off
pinMode(ldrld,INPUT); // LDR Bottom Left Solar Tracker Power On off
pinMode(ldrrd,INPUT); // LDR Bottom Right Solar Tracker Power On off
pinMode(solarcurrent,INPUT); // Solar Current Sensor
pinMode(batterycurrent,INPUT); // Battery Current Sensor
pinMode(solarvoltage,INPUT); // Solar Voltage Sensor
pinMode(batteryvoltage,INPUT); // Battery Voltage Sensor
pinMode(13,INPUT); // Temparture and Humididty Sensor of Boost Converter
pinMode(16,INPUT);// Rx
pinMode(17,INPUT);// TX

  timer.setInterval(50L,  Sensorvalue7); // Solar Tracker LDR and Servo
  timer.setInterval(123L,  Sensorvalue1); // Solar VOltage Sensor
  timer.setInterval(143L,  Sensorvalue2); // battery Voltage Sensor
  timer.setInterval(163L,  Sensorvalue3); // Solar Current Sensor
  timer.setInterval(183L,  Sensorvalue4); // Battery Current Sensor
  timer.setInterval(5000L,  Sensorvalue5); // Temprature and Humidity Sensor
}

void loop()
{
  Blynk.run();  
  timer.run();
  }

and Below is my Serial Port Output

20:22:08.239 ->   / _  / / // / _ \/  '_/
20:22:08.239 ->  /____/_/\_, /_//_/_/\_\
20:22:08.272 ->         /___/ v1.2.0 on ESP32
20:22:08.303 -> 
20:22:08.303 ->  #StandWithUkraine    https://bit.ly/swua
20:22:08.367 -> 
20:22:08.367 -> 
20:22:08.367 -> [10171] Modem init...
20:22:18.610 -> [20473] Cannot init
20:29:13.643 -> [10048] 
20:29:13.643 ->     ___  __          __
20:29:13.675 ->    / _ )/ /_ _____  / /__
20:29:13.707 ->   / _  / / // / _ \/  '_/
20:29:13.739 ->  /____/_/\_, /_//_/_/\_\
20:29:13.771 ->         /___/ v1.2.0 on ESP32
20:29:13.802 -> 
20:29:13.802 ->  #StandWithUkraine    https://bit.ly/swua
20:29:13.835 -> 
20:29:13.835 -> 
20:29:13.835 -> [10171] Modem init...
20:29:24.097 -> [20473] Cannot init
20:31:53.494 -> Z���modem...
20:32:03.276 -> [10048] 
20:32:03.308 ->     ___  __          __
20:32:03.340 ->    / _ )/ /_ _____  / /__
20:32:03.340 ->   / _  / / // / _ \/  '_/
20:32:03.371 ->  /____/_/\_, /_//_/_/\_\
20:32:03.403 ->         /___/ v1.2.0 on ESP32
20:32:03.435 -> 
20:32:03.435 ->  #StandWithUkraine    https://bit.ly/swua
20:32:03.499 -> 
20:32:03.499 -> 
20:32:03.499 -> [10171] Modem init...
20:32:13.708 -> [20473] Cannot init

This is going from bad to worse!

A few observations…

You’ve defined these rxPin and txPin aliases, but don’t use them anywhere else. What’s the point in doing this?
The correct way to use aliases is to define them all near the beginning of your code then use them all (exclusively) throughout the rest of the sketch. In reality you’ve done this…

instead of pinMode(rxPin,INPUT); - except of course that you don’t need to have pinMode statements for your Serial2 port, and even if you did, how can you have a pin that is meant to be outputting (transmitting) data defined as an input and expect it to work?

Also, if you’d have defined all your aliases in one place, and used aliases for all of your pins, you’d realise that you are using pins 16 and 17 for something else…

____________________________

You are trying to send debug info relating to the TinyGSM/Sim800 processes to the serial port which is meant to be reserved for AT communications between the ESP32 and SIM800…

instead of to the Serial port.

____________________________

Are you certain that the SIM800 is actually listening for instructions, and sending its responses at 9600 baud?
If so, how have you established and tested this?

____________________________

Despite me stating and re-stating in my serial port tutorial how important it is to ensure that the devices are wired correctly (Tx to Rx, Rx to Tx) you’ve not shared any information about how you’ve actually wired-up your devices.
Clearly your servos and your SOM800 aren’t connected to the same pins, despite what your code says.

Neither have you provided any information about how you are powering your devices. The SIM800 module can draw up to 2A in Tx mode.

____________________________

Personally, I’d suggest that you go back to basics and start with a very simple Blynk GSM sketch, so that you’re eliminating all of your coding issues that arise from the rest of your code and hardware.

You might also want to think about a different type of GSM connectivity, as 2G communications are in the sunset period in most countries, so the SIM800 hardware wont function for that much longer.

Pete.

i apologize for that

Noted, thanks

will do the needful to make aliases for all pin and try to use them in rest of the code.
and change the pin number mistake of servo motor.

can you tell what code line will come here.

i am not sure about that, please guide me how to check this.

i insured that SIM 800 and ESP32 RX and TX wires are connected each other
SIM 800 RX wired to ESP32 TX
SIM800 TX wired to ESP32 RX

i am using Battery Shield

i had added RS270 Diod and 47 Ohm Resistor to reduce voltage from 5 volt to 4.2 volt.

you are right, i will go with simple GSM sketch with DHT 22 Sensor, and check if its work or any issues arise.

yes definetly, right now i am doing testing of product, many modifications are needed in this, i am planning to use 4G module in further Improvement in my solar charging Electric two wheeler kit.

thanks for your support.

i will get back after to you again after trying simple GSM blynk sketch

I don’t understand the question.

Connect an FTDI to the SIM800 and use the serial monitor to send an “AT” command to the board at 9600 baud. If you get an “OK” response then it’s talking at 9600 baud. If not the try all of the other baud rates.

That doesn’t tell me much about how you’ve routed your wires. Can the battery shield deliver 2 amps?

That’s already too complicated. Just het the board online with Blynk.

Which module exactly?
Is it supported by TinyGSM?

Pete.

1 Like

yes, in specification 3Amp Supply mention.

good news is my DHT22 Blynk and SIM800 simple code start working. i got device online and getting Reading of Temperature and humidity,

i will use this same sketch and add one by one device and see the result.

i am going to use SIM A7670C or SIM A7672S

and thank you very much for helping me in this issues.

Hi,

ADC pins are giving random Average Value without connected any sensor pin (without connected LDR pins)
i am trying to find cause from different posts and video but can’t able to find

below is my serial monitor output

23:16:47.887 -> Average Value Down : 4095
23:16:47.887 -> Average Value Left : 2216
23:16:47.887 -> Average Value Right : 2047
23:16:47.887 -> Vertical Servo Position : 152
23:16:47.887 -> Horizontal Servo Position : 152
23:16:48.088 -> Average Value Top : 1237
23:16:48.088 -> Average Value Down : 4095
23:16:48.088 -> Average Value Left : 2832
23:16:48.088 -> Average Value Right : 2500
23:16:48.089 -> Vertical Servo Position : 150
23:16:48.089 -> Horizontal Servo Position : 150
23:16:48.089 -> Solar Voltage= 0.00
23:16:48.101 -> Battery Voltage= 0.00
23:16:48.228 -> Solar Current= 0.00
23:16:48.395 -> Battery Current= 0.00
23:16:48.631 -> Temperature: 26.80
23:16:48.631 -> Humidity: 99.90
23:16:48.631 -> ------------------------------------------

and below is my updated code

#define BLYNK_TEMPLATE_ID "ABC"
#define BLYNK_TEMPLATE_NAME "XYZ"
#define BLYNK_AUTH_TOKEN "123"

#define TINY_GSM_MODEM_SIM800 // Select your modem:

#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>


char auth[] = BLYNK_AUTH_TOKEN;
char apn[]  = "airtelgprs.com"; // Your GPRS credentials
char user[] = "";
char pass[] = "";

BlynkTimer timer;

#define rxPin 16
#define txPin 17
HardwareSerial Sim800L(2);
TinyGsm modem(Sim800L);

#include <DHT.h>
#define DHTPIN 13
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

#include "ACS712.h"
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;
int i = 0.0;

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;

#include <ESP32Servo.h>
Servo horizontal; // horizontal servo
int servoh = 90;  // start at degree    
int servohLimitHigh = 180;
int servohLimitLow = 0;

Servo vertical; // vertical servo
int servov = 90;  // start at degree    
int servovLimitHigh = 180;
int servovLimitLow = 0;

// LDR pin connections
//name = analogpin;
int ldrlt =32; //LDR top left
int ldrrt =33; //LDR top rigt
int ldrld =25; //LDR down left
int ldrrd =26; //ldr down rigt


void DhtSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); //Read temperature as Celsius (the default)
 
  if (isnan(h) || isnan(t)) {
    Serial.println(F("Failed to read from DHT sensor!"));  // Check if any reads failed and exit early (to try again).
    return;
  }
  Serial.print("Temperature: ");
  Serial.println(t);
  Serial.print("Humidity: ");
  Serial.println(h);
  Serial.println("------------------------------------------");
  
  Blynk.virtualWrite(V0, t);
  Blynk.virtualWrite(V1, h);
  timer.setInterval(5000L, DhtSensor);

}

void SolarVoltageSensor()
{
  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(V2, sdata);
  timer.setInterval(100L, SolarVoltageSensor);
  //delay(100);

}
void BatteryVoltageSensor()
{
  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(V3, sdata);
  timer.setInterval(100L, BatteryVoltageSensor);
  //delay(100);
}


void SolarCurrentSensor(){
  for(int i = 0.0; i < 1000; i++);
  { 
      voltage = (voltage + (0.0264 * analogRead(solarcurrent)));
      timer.setInterval(100L, SolarCurrentSensor);
  //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(V4, current);
  timer.setInterval(100L, SolarCurrentSensor);
  //delay(100);
}
void BatteryCurrentSensor(){

  for(int i = 0.0; i < 1000; i++);
    { 
      voltage = (voltage + (0.0264 * analogRead(batterycurrent)));
      timer.setInterval(100L, BatteryCurrentSensor);
  //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(V5, current);
  timer.setInterval(100L, BatteryCurrentSensor);
  //delay(100);
  }

  void SolarTracker()
{

 servoh = horizontal.read();
 servov = vertical.read();

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 = 90; // LDR Value 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)
 {
  timer.setInterval(1000L, SolarTracker);
 //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("Vertical Servo Position : ");
Serial.println(servov);

Serial.print("Horizontal Servo Position : ");
Serial.println(servoh);

timer.setInterval(1000L, SolarTracker);
//delay(dtime);
}  

BLYNK_WRITE(V6)
{
  int value = param.asInt();
  Serial.print(value);
  if(value == 0)
  {
  digitalWrite(ldrlt, LOW); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, LOW); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, LOW); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, LOW); // LDR Bottom Right Solar Tracker Power On off
  Serial.println(" : Solar Tracker Off");

  }
  if(value == 1)
  {
  digitalWrite(ldrlt, HIGH); // LDR Top Left Solar Tracker Power On off
  digitalWrite(ldrrt, HIGH); // LDR Top Right Solar Tracker Power On off
  digitalWrite(ldrld, HIGH); // LDR Bottom Left Solar Tracker Power On off
  digitalWrite(ldrrd, HIGH); // LDR Bottom Right Solar Tracker Power On off
  Serial.print(" : Solar Tracker On");
 }
  delay(100);
}


void setup()
{
  Serial.begin(115200); // Debug console 
  delay(2000);
 
  Sim800L.begin(9600, SERIAL_8N1, rxPin, txPin); //Sim800L.begin(9600,SWSERIAL_8N1,D3,D4); 
  delay(3000);

  Serial.println("Initializing modem..."); // To skip it, call init() instead of restart()
  modem.restart();
  Blynk.begin(auth, modem, apn, user, pass);

  dht.begin();

  horizontal.write(90);
  horizontal.attach(4);
  horizontal.attach(15);

  
  vertical.write(90);
  vertical.attach(18);
  vertical.attach(5);

pinMode(ldrlt,INPUT); // LDR Top Left Solar Tracker Power On off
pinMode(ldrrt,INPUT); // LDR Top Right Solar Tracker Power On off
pinMode(ldrld,INPUT); // LDR Bottom Left Solar Tracker Power On off
pinMode(ldrrd,INPUT); // LDR Bottom Right Solar Tracker Power On off
pinMode(18,OUTPUT); // Servo Vertical Top Left Solar Tracker Power On off
pinMode(5,OUTPUT); // Servo Vertical Top Right Solar Tracker Power On off
pinMode(4,OUTPUT); // Servo Horizontal Bottom Left Solar Tracker Power On off
pinMode(15,OUTPUT); // Servo Horizontal Bottom Right Solar Tracker Power On off
pinMode(solarcurrent,INPUT); // Solar Current Sensor
pinMode(batterycurrent,INPUT); // Battery Current Sensor
pinMode(solarvoltage,INPUT); // Solar Voltage Sensor
pinMode(batteryvoltage,INPUT); // Battery Voltage Sensor

  timer.setInterval(50L, SolarTracker); // Solar Tracker LDR and Servo
  timer.setInterval(123L, SolarVoltageSensor); // Solar VOltage Sensor
  timer.setInterval(143L, BatteryVoltageSensor); // battery Voltage Sensor
  timer.setInterval(163L, SolarCurrentSensor); // Solar Current Sensor
  timer.setInterval(183L, BatteryCurrentSensor); // Battery Current Sensor
  timer.setInterval(5000l, DhtSensor); // Temprature and Humidity Sensor
}

void loop()
{
  timer.run();
  Blynk.run();
}

It’s difficult to say what the cause is without knowing more about your hardware setup.

But, I’d start by running a very simple sketch that reads the values from each of your four LDR pins and prints them to your serial monitor - without any processing or the values first - and see what the results look like.

Obviously induced current from other circuitry could be an issue here, but it’s impossible to say based on the data you’ve shared.

You are t doing yourself any favours by not following-through on tidying up your code before moving on to investigating other issues.

Pete.

Good suggestion, I will try this and let you know the result

Thanks

i wanna make iot solar tracker using blynk. can you help me?

If I were you, I’d do a Google search for a solar tracker project that uses an ESP32 as it’s MCU.

Build that and get it working without Blynk, then decide what function you want Blynk to perform with the project, then add-in the Blynk code afterwards.

Pete.