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.
Table of Contents
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)
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Ω.
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.
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.
For more details read: Interfacing BH1750 Light intensity sensor with Arduino.
Bill of Materials:
Product Name | Quantity | ||
---|---|---|---|
ESP32 Microcontroller | 1 | https://amzn.to/3s0Sut6 | https://amzn.to/3Kw2np2 |
Voltage sensor 0-25v | 1 | https://amzn.to/3WHDBsl | https://amzn.to/3QeGHlk |
ACS712 current sensor module | 1 | https://amzn.to/3v4ok8y | https://amzn.to/3EaJ9Dz |
DS18B20 Temperature sensor | 1 | https://amzn.to/3VIAtLy | https://amzn.to/3WJhjql |
BH1750 Ambient light intensity sensor | 1 | https://amzn.to/33C6aRT | https://amzn.to/3J0WRKw |
LCD 16X2 module with or without I2C adapter | 1 | https://amzn.to/3BNSRup | https://amzn.to/363ki7F |
1k,2k and 4.7k ohm resistors | 1 each | https://amzn.to/3hBlqlq | https://amzn.to/3sXBKmI |
5V power supply (Micro USB or External). | 1 | https://amzn.to/3s1a8g3 | https://amzn.to/364yInH |
Few Connecting Wires | https://amzn.to/3H2BV4e | https://amzn.to/3J0WVu2 |
Circuit Diagram:
Now connect all the required components as shown in the below schematic diagram to build an ESP32 based solar power monitoring system.
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.
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.
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.
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.
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.
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.
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.
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.
thank you for your explanation! but I wanna ask, if I use this code/project I could not measure the voltage over 16V?
Thank you very much for posting this kind of projects.
This is very interesting to link the project with Arduino Iot cloud.
the temperature reading is constantly -127