DIY Solar Panel Monitoring System – V2.0
Table of Contents
Toggle
As solar photovoltaic (PV) systems become increasingly popular as a clean and renewable source of energy, it’s crucial to ensure that these systems are performing efficiently and effectively. A solar Panel Monitoring System helps to identify potential issues, optimize energy production, and extend the lifespan of your investment. In this blog post, we’ll introduce you to a simple yet powerful DIY solar PV monitoring system that enables you to track essential performance parameters, such as voltage, current, temperature, power, and energy.
The DIY monitoring system is built around the XIAO ESP32 MCU, a versatile and cost-effective microcontroller that forms the core of the system. To measure the electrical parameters, we’ll use the ACS758 current sensor for accurate current readings and a voltage divider circuit for voltage measurements. Additionally, we’ll incorporate the DS18B20 temperature sensor to monitor the temperature of the solar panels or other system components. Optionally, you can also add an OLED display to visualize the data in real-time.
This project not only offers a cost-effective solution for monitoring your solar PV system but also provides a fantastic learning experience for those interested in electronics, solar energy, and programming. By building your own monitoring system, you gain a deeper understanding of your solar PV system’s workings, and you can customize it to suit your specific needs.
In the following sections, we’ll provide a list of the required components, detailed instructions on setting up the circuit, and the Arduino code to get your DIY solar PV monitoring system up and running. So, let’s dive into the world of solar PV monitoring and make the most out of the clean energy harnessed by your solar panels.
You may check out my previous post on DIY Solar Panel Monitoring System – V1.0
Why do We Need a Solar Panel Monitoring System?
1. It gives clear information about various solar parameters, extracted energy, fault detection, historical analysis of the solar plant, and associated energy loss.
2. You can easily measure your solar production and the saving on your monthly electricity bill.
3. You can track all the important parameters of the solar PV system in real-time from your smartphone.
In this post, I will show you I have made a simple Solar Monitoring System by using an ESP32 development board and ACS723 current sensor.
Specification:
1. Voltage Range: 0- 50V
2. Current Range: 0 -50A
3. Temperature Range: -55°C to +125°C
Bill Of Material ( BOM )
Components Used:
SL No.
|
Components
|
Quantity
|
Buying Link
|
1
|
XIAO ESP32C3
|
1
|
|
2
|
ADS1115 Module
|
1
|
|
3
|
ACS758 Module
|
1
|
|
4
|
XL7015 Buck Converter
|
1
|
|
5
|
OLED Display
|
1
|
|
6
|
Resistor ( 100K , 10K, 4.7K, 2K , 1K )
|
1
|
|
7
|
0.1 uF Capacitor
|
1
|
|
8
|
Screw Terminal 2P – 9.52mm
|
2
|
|
9
|
Screw Terminal 3P- 3.5mm
|
1
|
Tools Used:
SL No
|
Tools
|
Buying Link
|
1
|
Soldering Iron
|
|
2
|
Nipper
|
|
3
|
Wire Stripper
|
|
4
|
3D Printer
|
How It works?
XIAO ESP32 MCU: The microcontroller serves as the central processing unit, gathering data from sensors, performing calculations, and controlling the OLED display.
ACS758 Current Sensor: The ACS758 measures the current flowing through the solar panel by converting the magnetic field generated by the current into a proportional output voltage. The XIAO ESP32 MCU reads this voltage and converts it into the actual current value.
Voltage Divider: The voltage divider, composed of two resistors in series, is connected to the solar panel’s positive terminal and GND. The junction between the two resistors provides a scaled-down voltage, which the XIAO ESP32 MCU reads and converts back to the actual voltage value. This method allows the circuit to measure voltages higher than the MCU’s maximum analog input voltage.
DS18B20 Temperature Sensor: This digital temperature sensor measures the temperature of the solar panel or other system components. It communicates with the XIAO ESP32 MCU using the OneWire protocol, providing accurate temperature readings that can help identify performance issues related to temperature variations.
OLED Display: The OLED display is used to visualize the collected data in real time. It communicates with the XIAO ESP32 MCU using the I2C protocol, allowing you to easily display voltage, current, temperature, power, and energy readings.
Schematic Diagram
Setting Up the Circuit
- XIAO ESP32 MCU: This versatile microcontroller will serve as the brain of our monitoring system, processing and analyzing the data from our sensors, and connecting to Blynk.
- ACS 758 Current Sensor: Connect the Vcc and GND pins of the ACS 758 to the 5V and GND pins on the XIAO ESP32, respectively. Connect the output (OUT) pin of the ACS 758 to an analog input pin (e.g., A0) on the XIAO ESP32.
- Voltage Divider: Set up a voltage divider using two resistors in series. For measuring up to 50V, you can use a 450kΩ resistor and a 50kΩ resistor. Connect one end of the series to the solar panel’s positive terminal and the other end to GND. Then, connect the junction of the two resistors to an analog input pin (e.g., A1) on the XIAO ESP32.
- DS18B20 Temperature Sensor: Connect the Vcc, GND, and data pins to the 3.3V, GND, and a digital input pin (e.g., D2) on the XIAO ESP32, respectively. Remember to add a 4.7K Ohm resistor between the Vcc and data pins for proper functioning.
- OLED Display (optional): Connect the Vcc, GND, SCL, and SDA pins of the OLED display to the corresponding pins on the XIAO ESP32. If you’re using a display that supports I2C communication, it typically involves connecting the Vcc to 3.3V, GND to GND, SCL to the SCL pin (e.g., D22), and SDA to the SDA pin (e.g., D21) on the XIAO ESP32.
Measuring Voltage
The solar panel voltage is sensed by a voltage divider network consisting of two resistors R1=100k and R2=10k. The output from the voltage divider is connected to ADC1115 pin A0. The output from the voltage divider is smoothed out by using a ceramic capacitor C1.
Voltage Measurement :
For a voltage divider circuit
Vout = R2/(R1+R2) x Vin
Vin = (R1+R2)/R2 x Vout
The ads.readADC_SingleEnded(0) function reads the raw analog data
Calculation :
We’re going to read the output value with one of the analog inputs of Arduino and its analogRead() function. That function outputs a value between 0 and 4095 that is 3.3/4095 for each increment
Vin = Raw Voltage *(R1+R2)/R2 ; R1=100k and R2=10k
You can use solar panels with higher voltage by selecting the appropriate resistors R1 and R2.
To select the voltage divider resistance values, you can use this online calculator.
Measuring Current
For the current measurement, I used a Hall Effect current sensor ACS 758 -50B. The output from the current sensor is connected to a voltage divider network consisting of resistors R3 and R4. There are other variants of the ACS758 Sensor based on the range of its current sensing. The ACS758 sensor reads the current value and converts it into a relevant voltage value, The value that links the two measurements is Sensitivity. The output sensitivity can be obtained from the ACS758-Datasheet. As per the datasheet, the sensitivity is 40mV / A
Calculation:
analog read value = analogRead(Pin);
ADCVoltage = ads.readADC_SingleEnded(1);
Then multiply the default gain of ADC1115 ( (0.1875/1000) and then multiply the voltage divider factor ( R3+R4)/R3
Current in amp = ( ADCVoltage – Offset Voltage ) / sensitivity
As per data sheets offset voltage is Vcc/2 ( 2.5V ) and sensitivity is 40 mV/A
Measuring Temperature
I have used an external DS18B20 probe for measuring the ambient temperature. It uses a one-wire protocol to communicate with the microcontroller. One-wire devices need a pull-up resistor connected to their signal line to be properly read by your board. Here, I have used a 4.7K resistor ( R5 ) as a pull-up resistor.
It can be hooked up to the PCB through the 3-pin screw terminal.
To interface with the DS18B20 temperature sensor, you need to install the One Wire library and the Dallas Temperature library. You can read this article for more details on the DS18B20 sensor.
The connection is as follows:
Red Wire -> Vcc
Yellow Wire -> DATA
Black Wire -> GND
All the above are clearly labeled on the PCB for avoiding any confusion.
Interfacing OLED Display
To display the solar panel parameters locally, I have used a 0.96″ OLED display. It has a 128 x 64 resolution and uses an I2C bus to communicate with the ESP32. Two pins SCL (GPIO22), SDA (GPIO21) in ESP32 are used for communication.
I am using the Adafruit_SSD1306 library to display the parameters.
The connections should be as follows:
ESP32 – ->OLED
3.3V —>VCC
GND –>GND
GPIO21—-> SDA
GPIO22—-> SCL
You can also connect an I2C LCD Display in place of the OLED display. However, you have to modify the code accordingly.
PCB Design
I have drawn the schematic by using EasyEDA online software and then designed a custom PCB for this project. The PCB is designed for mounting the different modules instead of using a lot of components.
You can download the Gerber files from PCBWay
You may also try Seeed Studio Fusion Aglie Manufacturing Service from 0.1 – ∞
PCB Assembly
For Soldering, you will need a decent Soldering Iron, Solder, Nipper, and a multimeter. It is good practice to solder the components according to their height. Solder the lesser height components first.
You can follow the following steps to solder the components :
1. Push the component legs through their holes, and turn the PCB on its back.
2. Hold the tip of the soldering iron to the junction of the pad and the leg of the component.
3. Feed the solder into the joint so that it flows all around the lead and covers the pad.
Once it has flowed all around, move the tip away.
3D printed Enclosure
To give a nice commercial product look, I have designed an enclosure for this project by using Autodesk Fusion 360. The dimensions of all the components and PCB mounting holes are measured by a vernier caliper then the same were considered during the design.
The enclosure has two parts: 1. Main Body 2. Top Lid The
The main body is basically designed to keep the PCB board. The top lid is to cover up the main body opening and mounting the OLED display.
I used my Ender 3S1 Pro printer and 1.75 mm silver and pink PLA filament to print the parts. It took me about 6 hours to print the main body and around 2 hours to print the top lid.
My settings are:
Print Speed: 60 mm/s
Layer height: 0.2mm ( 0.3 also works well)
Fill Density: 20%
Extruder Temperature: 205 deg C
Bed Temp: 60 deg C
Download the STL files from Thingiverse
Software and Libraries
To use the XIAO ESP32 board with the Arduino library, you’ll have to use the Arduino IDE with ESP32 board support. If you haven’t already done that yet, you can easily install ESP32 Board support to your Arduino IDE by following this tutorial by Sparkfun.
Install the Libraries:
Before uploading the code install the following libraries :
2. Blynk
4. One Wire
Interfacing With Blynk 2.0 App
In the earlier version, I used the old Blynk app which is now obsolete. In this project, we will use the new Blynk 2.0 app to monitor all the parameters remotely. First, you need to create a Blynk project and set up a dashboard in the mobile or web application. Here’s how you can set up the dashboard:
Web Dashboard:
Visit blynk.cloud and create a Blynk account on the Blynk website. Or you can simply sign in using the registered Email ID.
Click on +New Template.
Now you have to give a name to your Hardware ( Solar PV Monitoring V2). Choose the Hardware type as ESP32 and the connection type as WiFi. You can also write a shot of the description in the description box. Then click on Done. Now the template is created successfully.
The next step is to add a new data stream. For this project, I have used 6 data streams for voltage, current, power, energy, temperature, and savings. And assigned virtual pins from V0 to V5 for all the variables.
You have to also give the unit of measurement and minimum, maximum value for it. In our case, the voltage is assigned to virtual pin V0, the data type is Double, the unit is Volt, the minimum is 0 and the maximum is solar panel maximum voltage. You can also select the specific color of your choice.
Similarly, create for all 6 variables.
Now we have to add a new device here.
Select the device from a template that you created earlier.
After giving a name to the device, click on Create. A device authentication token ( 3 lines in a black box at the top right corner) will be generated now. Copy this token as this will be used in our code.
Now go to the Web Dashboard.
In the Web Dashboard, drag and drop 4 widgets Gauge, two labels, and one chart on the dashboard. Then click on the gear icon to set the parameters as shown below. Then save it and repeat the same process for setting up all 7 widgets.
Now you have successfully set up your Blynk Dashboard.
Mobile Dashboard:
Arduino Code
Before uploading the code be sure, you have installed all the libraries from the links given before. Then copy the below code and upload it to the XIAO ESP32 board.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
#define BLYNK_TEMPLATE_ID "TMPL3V-0wJfRH" #define BLYNK_TEMPLATE_NAME "Solar PV Energy Meter V2" #define BLYNK_AUTH_TOKEN "YOUR AUTH TOKEN" #define BLYNK_PRINT Serial #include <Wire.h> #include <Adafruit_SSD1306.h> #include <Adafruit_ADS1X15.h> #include <BlynkSimpleEsp32.h> #include <OneWire.h> #include <DallasTemperature.h> // Pin definitions const int oneWirePin = D3; // OneWire pin for DS18B20 // OLED display Adafruit_SSD1306 display(128, 64, &Wire); // ADS1115 Adafruit_ADS1115 ads; // DS18B20 temperature sensor OneWire oneWire(oneWirePin); DallasTemperature sensors(&oneWire); float voltage =0; float current =0; float power =0; unsigned long previousMillis = 0; float energy = 0; float temperature =0; float saving =0; // cost saving const float EnergyCost = 6.5; // Voltage divider resistor values const float R1 = 100; // 100K const float R2 = 10; // 10K const float R3 = 1; // 1K const float R4 = 2; // 2K // ACS758 zero-current output voltage ( Offset Voltage) float OffsetVoltage = 2.5; // ACS758 current sensor sensitivity const float sensitivity = 40; // in mV/A //========================= Variables for wifi server setup ============================= const char* ssid = "XXXXXXX"; const char* password = "XXXXX"; const char* blynkAuth = BLYNK_AUTH_TOKEN; void setup() { Serial.begin(115200); // Initialize the Wi-Fi and Blynk connections WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected to Wi-Fi"); Blynk.begin(blynkAuth, ssid, password); // Initialize the OLED display display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); display.display(); // Initialize the ADS1115 ads.begin(); // Initialize the DS18B20 temperature sensor sensors.begin(); } void loop() { // Read the raw voltage values from the ADS1115 int16_t voltageRaw = ads.readADC_SingleEnded(0); int16_t currentRaw = ads.readADC_SingleEnded(1); // Calculate the voltage values in Volts float voltageVolts = voltageRaw * (0.1875/1000) ; // 0.1875mV is default Gain float voltage = voltageVolts * ((R1 + R2) / R2); // Calculate the actual voltage by using the voltage dividers // Calculate the current values in Amps float currentVolts = currentRaw * ((R3 + R4) / R4)* (0.1875/1000); // 0.1875mV is default Gain current = (currentVolts - OffsetVoltage )/(sensitivity / 1000.0) ; // convert voltage into current // Calculate the power output (P = V * I) power = voltage * current; // Calculate energy by integrating power over time unsigned long currentMillis = millis(); energy += power * (currentMillis - previousMillis) / 3600000; // Energy in Wh saving = EnergyCost * ( energy /1000 ); previousMillis = currentMillis; // Read the temperature from the DS18B20 sensor sensors.requestTemperatures(); temperature = sensors.getTempCByIndex(0); // temperature in Celsius //temperature = sensors.getTempFByIndex(0); // temperature in Fahrenheit //Display the values on the OLED screen display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(10, 10); display.print(voltage,2); display.println(" V"); display.setCursor(70, 10); display.print(current,2); display.println(" A"); display.setTextSize(2); display.setCursor(10,25); display.print(power,2); display.println(" W"); display.setCursor(10,45); display.print(energy,2); display.println(" Wh"); // display.print("T: "); // display.print(temperature); // display.println(" C"); display.display(); // ================= Display Data on Blynk App ================================================ // Send the data to Blynk Blynk.run(); Blynk.virtualWrite(V0, voltage); Blynk.virtualWrite(V1, current); Blynk.virtualWrite(V2, power); Blynk.virtualWrite(V3, energy/1000); Blynk.virtualWrite(V4, temperature); Blynk.virtualWrite(V5, saving); // Print the values on the Serial Monitor Serial.print(" Voltage: "); Serial.print(voltage); Serial.print("V"); Serial.print(" Current: "); Serial.print(current); Serial.print("A"); Serial.print(" Power: "); Serial.print(power); Serial.print("W"); Serial.print(" Energy: "); Serial.print(energy,2); Serial.print("Wh"); Serial.print(" Savings: "); Serial.print("Rs."); Serial.print(saving,2); Serial.print(" Temp: "); Serial.print(temperature); Serial.println("C"); delay(100); } |
Field Testing
Now our device is ready for real field testing. The connection shall be as follows:
1. Connect the negative terminal of the load to the negative terminal of the output screw terminal and then the positive terminal to the output positive terminal. Here I have connected the out terminal to my inverter solar input terminal.
2. Connect the Solar panel’s negative terminal to the negative terminal of the Input screw terminal and positive to the input positive terminal.
The Input and Output screw terminals can be used for wire sizes from 26 – 10AWG.
Note: Be sure you are connecting to the right polarity, otherwise you will see the magic smoke. The circuit doesn’t have reverse polarity protection.
After all the connections, you will see your solar panel parameters displayed on the OLED display. You can check it from your smartphone by opening the Blynk App.