This circuit is designed to measure and monitor the voltage and current from two solar panels using an Arduino Nano, ADS1115 ADC, and ACS712 current sensors. The data is processed and displayed via the Arduino's serial monitor.
Arduino Nano
ADS1115
ACS712 Current Sensor 5A 20A 30A
Solar Panel
Resistor (47k Ohms)
Resistor (5k Ohms)
DC Buchse
#include <Adafruit_ADS1X15.h>
Adafruit_ADS1115 ads;
const float R1 = 47000.0; // First resistor value in voltage divider (ohms)
const float R2 = 5000.0; // Second resistor value in voltage divider (ohms)
const float CURRENT_SENSOR_SENSITIVITY = 0.1; // 0.1 for 20A Module
const float CURRENT_SENSOR_OFFSET = 2.5; // Offset voltage for current sensor (V)
const float VOLTAGE_DIVIDER_RATIO = (R1 + R2) / R2;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
ads.setGain(GAIN_TWOTHIRDS); // 2/3x gain +/- 6.144V 1 bit = 3mV 0.1875mV (default)
if (!ads.begin()) {
Serial.println("Failed to initialize ADS.");
while (1)
;
}
}
void loop() {
int16_t adc0 = ads.readADC_SingleEnded(0); // Old PV Voltage
int16_t adc1 = ads.readADC_SingleEnded(1); // New PV Voltage
int16_t adc2 = ads.readADC_SingleEnded(2); // Old PV Current
int16_t adc3 = ads.readADC_SingleEnded(3); // New PV Current
// Read voltage sensor values
float PV_V1 = ads.computeVolts(adc0) * VOLTAGE_DIVIDER_RATIO;
float PV_V2 = ads.computeVolts(adc1) * VOLTAGE_DIVIDER_RATIO;
// Read current sensor values
float PV_C1 = (ads.computeVolts(adc2) - CURRENT_SENSOR_OFFSET) / CURRENT_SENSOR_SENSITIVITY;
float PV_C2 = (ads.computeVolts(adc3) - CURRENT_SENSOR_OFFSET) / CURRENT_SENSOR_SENSITIVITY;
// Calculate power only if readings are valid
float PV_P1 = PV_V1 * PV_C1 ;
float PV_P2 = PV_V2 * PV_C2 ;
Serial.println("-----------------------------------------------------------");
Serial.print("AIN0: ");
Serial.print(adc0);
Serial.print("\t");
Serial.print("PV1 Voltage");
Serial.println(PV_V1);
Serial.print("AIN1: ");
Serial.print(adc1);
Serial.print("\t");
Serial.print("PV2 Voltage:");
Serial.println(PV_V2);
Serial.print("AIN2: ");
Serial.print(adc2);
Serial.print("\t");
Serial.print("PV1 Current:");
Serial.println(PV_C1);
Serial.print("AIN3: ");
Serial.print(adc3);
Serial.print("\t");
Serial.print("PV2 Current:");
Serial.println(PV_C2);
Serial.print("PV1 Power:");
Serial.println(PV_P1);
Serial.print("PV2 Power:");
Serial.println(PV_P2);
delay(1000);
}
This code initializes the ADS1115 ADC and reads voltage and current values from the connected sensors. It then calculates the power generated by each solar panel and prints the results to the serial monitor.