IoT based Solar Power Monitoring System with ESP32 over cloud

IoT based Solar Power Monitoring System with ESP32 over cloud IoT based Solar Power Monitoring System with ESP32 over cloud

In this article let’s learn how to Effortlessly Monitor Your Solar Power Generation system with Our ESP32 IoT based solar power monitoring system. ESP32 can be programmed to collect data from sensors which we connect to the solar panel, such as voltage, current, temperature, and sunlight intensity and transmit this data over the internet to a cloud server or a local server. This data can then be accessed and analyzed using a web interface or a mobile app, allowing you to monitor the performance of your solar panel in real-time.

There are several reasons to monitor the performance of your solar panels such as: To optimize energy production, To detect problems early, To reduce energy costs, To ensure safety and more. Solar energy is becoming increasingly popular around the world as a way to reduce reliance on fossil fuels and combat climate change. Many countries are investing in solar energy infrastructure and implementing policies to promote the adoption of solar energy.

Project Introduction:

In this project we will monitor voltage, current, temperature and sunlight intensity with help of sensors which send the data to ESP32 microcontroller. We display the data over Arduino IoT cloud server and also on 16X2 LCD display which is connected to the micro controller. Lets see which sensors we are using for what and their respective pinout diagram below.

Voltage:

For Measuring voltage we are using 0-25v DC voltage sensor. This sensor uses the voltage divider which reduces the voltage by 5 times using 2 resistors R1= 30000Ω and R2=7500Ω. As we all know Arduino ADC input voltage ranges from 0-5v but ESP32 has a maximum input of 3.3v only. So with the help of this voltage divider we can measure from 0-16v with ESP32.

  • 3.3vX5times=16.5v(MAX)

voltage detection sensor module pinout

For more detailed information read: Arduino Voltage Sensor which measures up to 25V DC.

Current:

For measuring current we are using ACS712 5A current sensor. This sensor uses hall effect principle to measure the current, there are 3 variants 5A, 20A and 30A choose according to your need. For this board lower capacity one’s give more accurate results than the higher variants. For this sensor we need to use the voltage divider to reduce the sensor output from 5v to 3.3v. So we use 2 resistors R1= 1kΩ and R2= 2kΩ.

ACS712 Current sensor module application circuit

For a detailed information read: interfacing ACS712 current sensor with ESP32.

Temperature:

To measure temperature we are using DS18B20 temperature sensor. This sensor has the capacity to measure temperature values between -55ºC to +125ºC. We need a 4.7kΩ resistor to connect to the signal from 5v supply. This sensor has very low power consumption of nearly 1mA. We can use waterproof or non water proof sensor according to the requirement.

DS18B20 temperature sensor pinout diagram

For more details read: Interfacing DS18B20 Temperature sensor with Arduino,ESP8266 and ESP32.

Sunlight intensity:

To measure sunlight intensity we are using BH1750 light intensity sensor which can measure Lux range with a high resolution from 1 to 65535lx. But direct sunlight intensity is higher than 100000lx, we can use filters to reduce the light and compensate the amount of it. But sometimes this sensor measures lux values more than 1 lakh. Here in our case we just need to know weither the light intensity is high or not.

BH1750 light intensity sensor pinout diagramFor more details read: Interfacing BH1750 Light intensity sensor with Arduino.

Bill of Materials:

Product NameQuantityamazon logoamazon logo india
ESP32 Microcontroller1https://amzn.to/3s0Sut6https://amzn.to/3Kw2np2
Voltage sensor 0-25v1https://amzn.to/3WHDBslhttps://amzn.to/3QeGHlk
ACS712 current sensor module1https://amzn.to/3v4ok8yhttps://amzn.to/3EaJ9Dz
DS18B20 Temperature sensor1https://amzn.to/3VIAtLyhttps://amzn.to/3WJhjql
BH1750 Ambient light intensity sensor1https://amzn.to/33C6aRThttps://amzn.to/3J0WRKw
LCD 16X2 module with or without I2C adapter1https://amzn.to/3BNSRuphttps://amzn.to/363ki7F
1k,2k and 4.7k ohm resistors1 eachhttps://amzn.to/3hBlqlqhttps://amzn.to/3sXBKmI
5V power supply (Micro USB or External).1https://amzn.to/3s1a8g3https://amzn.to/364yInH
Few Connecting Wireshttps://amzn.to/3H2BV4ehttps://amzn.to/3J0WVu2
You can buy the required components from the given best buy links. We choose the components according to value for money.

Circuit Diagram:

Now connect all the required components as shown in the below schematic diagram to build an ESP32 based solar power monitoring system.

iot based solar power monitoring system using esp32 circuit diagram
Click to enlarge

As you can see from the above circuit diagram we connected 4 sensors, 1 LCD display with ESP32. You can use an external 5v power supply to give all the components a stable voltage without heating up our ESP32.

Read below to easily understand the circuit connections with out any confusion

Voltage sensor with ESP32:

Voltage sensor has 3 pins +, -, and S. + and – pins are connected to 5v and GND terminals of 5v power supply. S pin which is signal pin, connected to analog pin D27 of ESP32.

We need to connect the solar panel terminals in parallel with screw terminals of sensor to measure the voltage of it.

ACS712 current sensor with ESP32 :

ACS712 has 3 pins VCC, OUT and GND. VCC and GND pins are connected to 5v and GND terminals of 5v power supply. OUT of ACS712 is connected to D34 of ESP32 along with a voltage divider to reduce the voltage from 5v to 3.3v for ADC.

DS18B20 temperature sensor with ESP32:

Here we used a non waterproof version as we stick it to the solar panel. it has 3 pins VCC on the Right, Signal on the center and GND on the left. VCC and GND pins of DS18B20 are connected to 3.3V and GND pins of ESP32 respectively. Signal pin is connected to D15 of ESP32 along with a 4.7K ohm resistor to pull up the signal.

BH1750 light sensor with ESP32:

BH1750 sensor uses I2C communication so the data pins SDA and SCL are connected to D21 and D22 of ESP32 respectively. And powered with 5v power supply.

LCD display with ESP32:

LCD display also uses I2C communication so we are connecting SDA and SCL pins of LCD to the same D21 and D22 of ESP32. We can differentiate devices with the I2C address.

That’s it all for connection, its time to write the code and upload to ESP32.

Program Code to just display on LCD Display:

To get the data from the sensors to process them and output the required values we need to upload the program code to ESP32 using Arduino IDE. Our program need few libraries listed below, you can install them directly through the library manger of Arduino IDE or download from the below links and place them in Arduino libraries directory.

Required Libraries:

  • Download LiquidCrystal_I2C – Link
  • Download BH1750 Library: Link
  • Download Dallas Temperature Library: Link

Program Code:

Code to just display on LCD display. Download this code.

Output on LCD display:

After uploading the code through Arduino IDE you can see the sensor values on LCD display as shown in the below image.

solar power monitoring system on LCD display using ESP32

How to setup and code Arduino IoT Cloud for Solar power monitoring system:

Account setup:

Step1: Open Arduino IoT cloud using following Link : https://create.arduino.cc/iot

Step2: Signup for a new account or login if you already have an account by providing credentials.

Step3: Click on Create thing, to get a setup page to configure project name, board, variables, and network according to the below image.

iot based solar power monitoring system using esp32 arduino cloud dashboard

Device setup:

Click on select device button, and choose setup a 3rd party device as we are not using Arduino board. Now from the radio buttons choose ESP32. From the dropdown select ESP32 wrover module . Next click on continue to name the device and download or copy the Device ID and Secret Key PDF for further reference in the code as shown in the below screenshot.

Arduino IoT cloud web setting up device with secret key

Next go to sketch tab and paste the code given below.

Download complete code: here

File: IoT_based_Solar_Power_Monitoring_System_with_ESP32_jan04a.ino

/* IoT based Solar Power Monitoring System with ESP32 over cloud
  Author: https://www.circuitschools.com */

#include "thingProperties.h"
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <BH1750.h>
#include <LiquidCrystal_I2C.h>

// Define voltage sensor analog input
#define SIGNAL_PIN 27
float adc_voltage = 0.0;

float R1 = 30000.0;
float R2 = 7500.0;
float ref_voltage = 5;
int adc_value = 0;

//ACS712
const int sensorIn = 34;      // pin where the OUT pin from sensor is connected on Arduino
int mVperAmp = 185;           // this the 5A version of the ACS712 -use 100 for 20A Module and 66 for 30A Module
int Watt = 0;
double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

//DS18B20
#define ONE_WIRE_BUS 15
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

//BH1750
BH1750 lightMeter(0x23);

//LCD display
LiquidCrystal_I2C lcd (0x27, 16, 2);

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  lcd. init ();
  lcd. backlight ();
  lcd. print ( "Solar monitor" );


  sensors.begin();//Dallas sensors
  Wire.begin(); //bh1750
  if (lightMeter.begin(BH1750::CONTINUOUS_HIGH_RES_MODE)) {
    Serial.println(F("BH1750 Advanced begin"));
  }
  else {
    Serial.println(F("Error initialising BH1750"));
  }

  delay(3000);
  lcd. clear();
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();

  //voltage sensor
  adc_value = analogRead(SIGNAL_PIN);
  adc_voltage  = (adc_value * ref_voltage) / 4096.0;
  in_voltage = adc_voltage / (R2 / (R1 + R2)) ;
  Serial.print("Input Voltage = ");
  Serial.print(in_voltage, 2);
  Serial.print(" V |");

  //acs712
  Voltage = getVPP();
  VRMS = (Voltage / 2.0) * 0.707; //root 2 is 0.707
  AmpsRMS = ((VRMS * 1000) / mVperAmp) - 0.3;
  Serial.print("Current = ");
  Serial.print(AmpsRMS, 2);
  Serial.print(" A |");

  //temp

  sensors.requestTemperatures();
  temp = sensors.getTempCByIndex(0);
  Serial.print("temperature = ");
  Serial.print(temp);
  Serial.print(" c |");

  //bh1750
  lux = lightMeter.readLightLevel();
  Serial.print("light = ");
  Serial.print(lux);
  Serial.println(" lx");

  //print on lcd
  lcd.setCursor (0, 0);
  lcd.print("V=");
  lcd.print(in_voltage, 2);
  lcd.print("v|");

  lcd.setCursor (8, 0);
  lcd.print("C=");
  lcd.print(AmpsRMS, 2);
  lcd.print("A");

  lcd.setCursor (0, 1);
  lcd.print("T=");
  lcd.print(temp, 1);
  lcd.print("c|");

  lcd.setCursor (8, 1);
  lcd.print("L=");
  lcd.print(lux);
}

float getVPP()
{
  float result;
  int readValue;                // value read from the sensor
  int maxValue = 0;             // store max value here
  int minValue = 4096;          // store min value here ESP32 ADC resolution

  uint32_t start_time = millis();
  while ((millis() - start_time) < 1000) //sample for 1 Sec
  {
    readValue = analogRead(sensorIn);
    // see if you have a new maxValue
    if (readValue > maxValue)
    {
      /*record the maximum sensor value*/
      maxValue = readValue;
    }
    if (readValue < minValue)
    {
      /*record the minimum sensor value*/
      minValue = readValue;
    }
  }

  // Subtract min from max
  result = ((maxValue - minValue) * 3.3) / 4096.0; //ESP32 ADC resolution 4096

  return result;
}

Next create 4 variables in_voltage, AmpsRMS, temp, lux, variable names should be same as the variables in the code as shown in the below image keep them read only as we are just reading the data from the sensors.

arduino iot cloud variable setup

Next link the device. Then click on network to add the WiFi SSID, password and secret key which you obtained while creating a device ESP32 Wrover.

Create a dashboard, and add 4 widgets for voltage, current, temperature, and light intensity as value, link them with created variables.

arduino iot cloud adding widgets in the dashboard

That’s it play with it to know more functions. For detailed setup check here: Getting started with Arduino IoT Cloud.

You can check the serial monitor of Arduino IoT and the sensors data will be displayed as the below screenshot.

solar power monitor with esp32 using arduino iot cloud serial monitor

Now the data is shown through the dashboard also, Open the previously created dashboard to view the data as shown in the below image. You can also download Arduino IoT Cloud Remote on your Android mobile to remotely monitor health data over internet.

solar power monitoring system dashboard on android iot cloud

Not only using Arduino IoT Cloud but you can also use other cloud platforms like ThingSpeak.

If you like this project please subscribe to our YouTube Channel “Circuit Schools to encourage us to publish more interesting projects. If you have any doubts write to us from below comment section.

3 comments
  1. thank you for your explanation! but I wanna ask, if I use this code/project I could not measure the voltage over 16V?

  2. Thank you very much for posting this kind of projects.
    This is very interesting to link the project with Arduino Iot cloud.

Leave a Reply

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