Quantcast
Channel: Sensors - Arduino Forum
Viewing all articles
Browse latest Browse all 1069

Issue using ACS712 20A and voltage divider with ADS1115

$
0
0

Hello and good day everyone,

I'm hoping you can help me with a problem I'm having with my Arduino project. I am currently working on a project to read the voltage and current of two 400W solar panels (Vmax 40V and Imax10.4A), one old and the other new, to compare their performance. For this, I used two voltage divider circuits (R1=47,000 and R2=5,000), two ACS712 20A current sensors, an ADS1115 digital-to-analog converter with the GAIN_TWOTHIRDS setting, and an Arduino Nano. The reason why I'm not using Arduino's analog input directly is because I have another sensor working with an internal 1.1V reference, still not included in the code and wiring diagram.

When I run the code, I can get the measurements on the serial monitor. I don't know what's causing this problem. I think the issue lies within the code . I've looked online for some answers, but nothing seems to work.

#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 
  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);
}

Do you have any suggestions on how to fix this code?

reading on serial monitor


Project wiring(app.cirkitdesigner.com)

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 1069

Trending Articles