IOT Projects

Solar Panel Monitoring System using ESP8266 Nodemcu

Solar panel monitoring system using esp8266:

Solar Panel Monitoring System using ESP8266 Nodemcu- I have been using Nodemcu ESP8266 WiFi module, Voltage sensor 0-25V, DHT11 Temperature and Humidity module, and Relay modules in different beginners, intermediate, and advanced level projects. In my previous 4 tutorials,

  1. 12v Battery Voltage Monitor using LEDs and LM339 comparator
  2. Wireless battery voltage monitor using Arduino and Bluetooth
  3. Wireless Battery Voltage Monitoring using Arduino, NRF24L01, & Bluetooth
  4. Esp8266 Iot battery monitor, battery voltage monitoring using nodemcu esp8266 wifi module

In all these 4 tutorials, I have explained how to monitor the battery voltage using different technologies. You might be thinking why am I talking about these 4 projects, well the answer is monitoring a battery or monitoring a solar panel are exactly the same. I will be using the same voltage sensor and the same Nodemcu ESP8266 for monitoring the Solar Panel. The only difference is that, this time I am doing it for the solar panel instead of 12V battery. I highly recommend you should read my previous articles to understand things in more depth. Anyways,

In this project we will monitor the solar panel using Blynk application through ESP8266 Nodemcu. The advantage of using the Nodemcu ESP8266 and Blynk application is, we can monitor the Solar Panel voltage and other parameters from anywhere in the world using our cell phone. So, this is basically an IoT based project. For this project we will require the following components:

  • DHT22 or DHT11 temperature sensor
  • NodeMCU
  • Voltage sensor
  • Relay module

Note: this old version of the Blynk app is no more functional. For the blynk mobile App setup and Blynk.cloud dashboard setup ready my article on the New Blynk V2.0. In this article I have explained how to migrate your projects from Blynk 1.0 to the new Blynk V2.0. You can also watch the video.



Amazon Links:

Nodemcu ESP8266 WiFi Module:

DHT11 Temperature and Humidity Module:

Voltage sensor 0-25v:

One-Channel Relay Module:

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Getting Started with Nodemcu ESP8266:

Nodemcu ESP8266 is a 3.3V compatible controller board and it can programmed using the Arduino IDE. The time you install the Arduino IDE you won’t see the Nodemcu ESP8266 in the boards list. So, first you will need to install the board before you can use it with the Arduino IDE. I have a very detailed tutorial on “Nodemcu ESP8266 Arduino IDE Board Manager URL Link Installation and first project”. In this article I explained the Nodemcu ESP8266 Pinout, technical specs, and I also explained how to write your very first program to control an LED. In this article I also explained how to setup your Blynk library. I highly recommend to read this article, if you have not yet setup your Nodemcu ESP8266, this article will really help you in getting started. Once you have installed the Nodemcu ESP8266 board and the necessary libraries then you are all set. Now let’s take a look at the circuit diagram.




Solar Panel Monitoring System Circuit Diagram:

Now for circuit connections we will connect the positive terminal of the solar panel with the positive terminal of the voltage sensor and negative terminal of the solar panel with the negative terminal of the voltage sensor. The OUT pin of the voltage sensor will be connected with the A0 of the NodeMCU ESP8266 and connect the ground of the voltage sensor with the ground of the NodeMCU Module. This part is for measuring the voltage and now we will connect the temperature sensor in order to measure the temperature of the solar panel and then we will connect the relay module with which we can connect the inverter or battery. For measuring the temperature of the system we have connected temperature sensor DHT11. The VCC pin of the sensor will be connected with 3V of the NodeMCU, ground of the DHT11 will be connected with the ground of the NodeMCU and data pin will be connected with the D4. This is the complete circuit diagram.

Solar Panel Monitoring

DHT11 sensor module is not the ideal choice for this project as it doesn’t make physical contact with the solar panel, you can use the DS18B20 one-wire digital temperature sensor. Currently, I have this DHT11 sensor so that’s why I am using this sensor module. Anyways it’s a prototype model to help you get started with your project, you can change the temperature sensor and relay module as per your requirement. When you have completed all the connections, make sure there are no short circuits, the continuity is ok, and everything is connected as per the circuit diagram, then the next step is to design the Blynk application.



Blynk App for the solar Panel monitoring system:

Now we will design application in the Blynk in order to monitor the status of the solar panel in the mobile. If you do not have Blynk application, download it from the play store, and make account. During the registration enter a valid email id, because while making the Blynk application you will be emailed an Authentication token which you will have to use in the Nodemcu ESP8266 programming. So, after downloading and installing the Blynk Application, Open the Blynk application.

Click on the create new project

Solar Panel Monitoring

Then select ESP8266 and in hardware select NodeMCU and in connection type select Wi-Fi. Give the name to the project in our case the project name is solar panel monitor and click on create.

Solar Panel Monitoring

The Auth token will be sent to the email which will be used in coding. Now in the widget box select the gauge. Now we will give it name voltage and use it as virtual pin V0 and set the maximum value to 25.

Solar Panel Monitoring

Solar Panel Monitoring

Click on the PIN and select virtual pin V0.



Now insert labeled value and give it name as temperature and set the value between 18 to 100

Solar Panel Monitoring

Now insert another label and give it name humidity and assign it virtual pin 2

Solar Panel Monitoring

Now again in the wedge box we will insert a super chart and give it name as voltage and select the virtual pin V0 and give the minimum and maximum between 0 to 25.

Solar Panel Monitoring

Now click on the add data stream and we will make graph for both temperature and humidity. Our Blynk App for the Solar Panel Monitoring System is ready.



Blynk library for Arduino IDE:

To write code we will first installed the Blynk library. In order to install the Blynk library in the Arduino IDE click on the sketch and select the manage library.

Solar Panel Monitoring

Now in search, write Blynk and click on install

Solar Panel Monitoring

After the installation is finished, we will install temperature sensor library and now we will write DHT sensor in the search and click on the install.

Solar Panel Monitoring

Now after installing the temperature sensor library we will install the simple timer library. Click on the sketch and then click on the insert zip file and select the zip file library. Download the Simple timer library:

Solar Panel Monitoring

After installing all the three libraries, now you can start writing your code.




Solar Panel Monitoring System ESP8266 Code:

#include 
#include 
#include 

#define DHTPIN 2
#define DHTTYPE    DHT11     

DHT_Unified dht(DHTPIN, DHTTYPE);

// inverter on voltage and cutoff voltage
float on_voltage = 12.0;
float off_voltage = 11.5;

// refresh interval
uint32_t delayMS = 1000;

int pinValue1; // inverter virtual pin

int Voltage_sensor = A0; // voltage sensor 
int inverter = D2; // relay

// voltage sensor
float correctionfactor = 0; // adjust this for calibration
float vout = 0.0; 
float vin = 0.0; 

// two resistors 30k and 7.5k ohms
float R1 = 30000;  //   
float R2 = 7500; //  
int value = 0; 

char data[80];

SimpleTimer timer;

// Blynk token you received via email
char auth[] = "YOUR_BLYNK_AUTH_TOKEN";

// Your WiFi credentials
char ssid[] = "electronic_clinic";
char pass[] = "123456";


void setup() {
  Serial.begin(9600);
  pinMode(Voltage_sensor, INPUT); 
  pinMode(inverter, OUTPUT);
  digitalWrite(inverter, HIGH);
  
  dht.begin();
  
  Serial.println(F("Solar Power Monitor"));
  
  Blynk.begin(auth, ssid, pass);
  Blynk.virtualWrite(V5, 0);

  
  sensor_t sensor;
  dht.temperature().getSensor(&sensor);
  Serial.println(F("------------------------------------"));
  Serial.println(F("Temperature Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
  Serial.println(F("------------------------------------"));
  // Print humidity sensor details.
  dht.humidity().getSensor(&sensor);
  Serial.println(F("Humidity Sensor"));
  Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);
  Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);
  Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);
  Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("%"));
  Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("%"));
  Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("%"));
  Serial.println(F("------------------------------------"));
  
  // Set delay between sensor readings
  timer.setInterval(delayMS, timerEvent);

  timerEvent();
}

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

void timerEvent()
{
  
  // Get temperature event and print its value.
  sensors_event_t event;

  // Virtual pin 1 (V1) has temperature value
  dht.temperature().getEvent(&event);
  if (isnan(event.temperature)) {
    Serial.println(F("Error reading temperature!"));
    Blynk.virtualWrite(V1, "ERR");
  }
  else {
    Serial.print(F("Temperature: "));
    Serial.print(event.temperature);
    Serial.println(F("°C"));
    
    sprintf(data, "%.f", event.temperature);
    Blynk.virtualWrite(V1, data); // send data to blynk
  }
  
  // Get humidity event and print its value.
  // Virtual pin 2 (V2) has humidity value
  dht.humidity().getEvent(&event);
  if (isnan(event.relative_humidity)) {
    Serial.println(F("Error reading humidity!"));
    Blynk.virtualWrite(V2, "ERR");
  }
  else {
    Serial.print(F("Humidity: "));
    Serial.print(event.relative_humidity);
    Serial.println(F("%"));

    sprintf(data, "%.f", event.relative_humidity);
    Blynk.virtualWrite(V2, data); // send data to blynk
  }

  float vtot = 0.0;
  int loops = 10; // number of samples

  // loop multiple times and get average reading
  for (int i=0; i < loops; i++) {
    vtot = vtot + analogRead(Voltage_sensor);
  }
  value = vtot/loops;

  // voltage calculation
  vout = (value * 3.3) / 1024.0; // 3.3V
  vin = vout / (R2/(R1+R2));
  
  vin = vin - correctionfactor; 
 
  Serial.print("Voltage: "); 
  Serial.print(vin, 4);
  Serial.println("V");

  // Virtual pin 0 (V0) has voltage value
  sprintf(data, "%.1f", vin);
  Blynk.virtualWrite(V0, data); // send voltage value to blynk


  if (vin < off_voltage && digitalRead(inverter) == LOW) { digitalWrite(inverter, HIGH); Serial.println("TURNING RELAY OFF"); } if (vin > on_voltage && digitalRead(inverter) == HIGH) {
    digitalWrite(inverter, LOW); 
    Serial.println("TURNING RELAY ON");
  }
 


  if (digitalRead(inverter) == LOW) {
    Blynk.virtualWrite(V5, 255);
    Serial.println("Inverter is ON");
  } else {
    Blynk.virtualWrite(V5, 0);
    Serial.println("Inverter is OFF");
  }

  Serial.println("------------------");
  Serial.println("");
}




Solar Panel Monitoring System Code Explanation:

You will need to add the following three libraries.

#include <DHT_U.h>

#include <SimpleTimer.h>

#include <BlynkSimpleEsp8266.h>

Then we will write the command for the dht sensor that which type of sensor we are using in our case we are using DHT11 which is connected to the digital pin 2

#define DHTPIN 2

#define DHTTYPE    DHT11    

DHT_Unifieddht(DHTPIN, DHTTYPE);

Now we will set the voltage on which the inverter will be on and off. It can be set according to the requirements.

floaton_voltage = 12.0;

floatoff_voltage = 11.5;

Then to update the frequency we will write the command

uint32_tdelayMS = 1000;

int pinValue1; // inverter virtual pin

This command is used to read the voltage of the sensor

intVoltage_sensor = A0; // voltage sensor

This pin is connected with the relay module will turn on and off the inverter.

int inverter = D2; // relay

Now to calibrate the voltage value we write the command

// voltage sensor

floatcorrectionfactor = 0; // adjust this for calibration

floatvout = 0.0;

float vin = 0.0;

Now to make the voltage divider for the voltage sensor we are using R1 and R2

float R1 = 30000;  //  

float R2 = 7500; // 

int value = 0;

Now we will insert the authorization token which we will get from the email when we create the blynk application

// Blynk token you received via email

charauth[] = "YOUR_BLYNK_AUTH_TOKEN";

Now insert the Wi-Fi name and password

// Your WiFi credentials

charssid[] = "electronic_clinic";

char pass[] = "123456";




Now in the setup function we will define that which pin will be used as input and which will be used as output.

Serial.begin(9600);

pinMode(Voltage_sensor, INPUT);

pinMode(inverter, OUTPUT);

digitalWrite(inverter, HIGH);

Then we will write the commands to show the current temperature and voltage value on the serial monitor and on the Blynk application.

dht.begin();

Serial.println(F("Solar Power Monitor"));

Blynk.begin(auth, ssid, pass);

Blynk.virtualWrite(V5, 0);

sensor_t sensor;

dht.temperature().getSensor(&sensor);

Serial.println(F("------------------------------------"));

Serial.println(F("Temperature Sensor"));

Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);

Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);

Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);

Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("°C"));

Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("°C"));

Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("°C"));

Serial.println(F("------------------------------------"));

  // Print humidity sensor details.

dht.humidity().getSensor(&sensor);

Serial.println(F("Humidity Sensor"));

Serial.print  (F("Sensor Type: ")); Serial.println(sensor.name);

Serial.print  (F("Driver Ver:  ")); Serial.println(sensor.version);

Serial.print  (F("Unique ID:   ")); Serial.println(sensor.sensor_id);

Serial.print  (F("Max Value:   ")); Serial.print(sensor.max_value); Serial.println(F("%"));

Serial.print  (F("Min Value:   ")); Serial.print(sensor.min_value); Serial.println(F("%"));

Serial.print  (F("Resolution:  ")); Serial.print(sensor.resolution); Serial.println(F("%"));

Serial.println(F("------------------------------------"));

  // Set delay between sensor readings

timer.setInterval(delayMS, timerEvent);

timerEvent();

}

void loop() {

Blynk.run();

timer.run();

}

voidtimerEvent()

{




  // Get temperature event and print its value.

sensors_event_t event;




  // Virtual pin 1 (V1) has temperature value

dht.temperature().getEvent(&event);

if (isnan(event.temperature)) {

Serial.println(F("Error reading temperature!"));

Blynk.virtualWrite(V1, "ERR");

  }

else {

Serial.print(F("Temperature: "));

Serial.print(event.temperature);

Serial.println(F("°C"));




sprintf(data, "%.f", event.temperature);

Blynk.virtualWrite(V1, data); // send data to blynk

  }




  // Get humidity event and print its value.

  // Virtual pin 2 (V2) has humidity value

dht.humidity().getEvent(&event);

if (isnan(event.relative_humidity)) {

Serial.println(F("Error reading humidity!"));

Blynk.virtualWrite(V2, "ERR");

  }

else {

Serial.print(F("Humidity: "));

Serial.print(event.relative_humidity);

Serial.println(F("%"));




sprintf(data, "%.f", event.relative_humidity);

Blynk.virtualWrite(V2, data); // send data to blynk

  }




Now we will read the pin value multiple times and get the average to reduce the noise.

floatvtot = 0.0;

int loops = 10; // number of samples




  // loop multiple times and get average reading

for (int i=0; i < loops; i++) {

vtot = vtot + analogRead(Voltage_sensor);

  }

value = vtot/loops;

Now calculate the voltage using the voltage divider equation

// voltage calculation

vout = (value * 3.3) / 1024.0; // 3.3V

vin = vout / (R2/(R1+R2));




vin = vin - correctionfactor;




Serial.print("Voltage: ");

Serial.print(vin, 4);

Serial.println("V");

Now send the calculated data to the blynk application

// Virtual pin 0 (V0) has voltage value

sprintf(data, "%.1f", vin);

Blynk.virtualWrite(V0, data); // send voltage value to blynk

Now to check the voltage and the status of the inverter to turn on and off the inverter we will write the command.

if (vin <off_voltage&&digitalRead(inverter) == LOW) {

digitalWrite(inverter, HIGH);

Serial.println("TURNING RELAY OFF");

  }




if (vin >on_voltage&&digitalRead(inverter) == HIGH) {

digitalWrite(inverter, LOW);

Serial.println("TURNING RELAY ON");

  }










if (digitalRead(inverter) == LOW) {

Blynk.virtualWrite(V5, 255);

Serial.println("Inverter is ON");

  } else {

Blynk.virtualWrite(V5, 0);

Serial.println("Inverter is OFF");

  }




Serial.println("------------------");

Serial.println("");

}

After uploading the code to the Nodemcu ESP8266 when you run the Blynk application, make sure you are connected to the WiFi and you have internet package, you will get the humidity, voltage, and temperature of the solar panel and also get the live graph.

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button