This website uses 'cookies' to give you the best, most relevant experience. Using this website means you're happy with this.
read more
Accept & Close

DIY **&** Home Improvement

How to make a circuit for voltage and current measurement using **Arduino** and **ACS712**, **ADS1015**.
The **ADS1015** is a 12-bit **analog-to-digital converter**. Equipped with i2c bus and 4 channels A0-4. What is very
important is also have "Internal Low-Drift Voltage Reference", which significantly simplifies the construction
of precision measuring systems.
**ACS712** is the circuit for measuring the current using a hall effect. My version measures current from -30A to 30A.

int16_t adc0, adc1, adc2, adc3;
float avg0 = 0.0f;
float avg1 = 0.0f;
float avg2 = 0.0f;
float avg3 = 0.0f;
for(int i=0; i<NUMBR_OF_SAMPLES; i++){
adc0 = ads.readADC_SingleEnded(0);
adc1 = ads.readADC_SingleEnded(1);
adc2 = ads.readADC_SingleEnded(2);
adc3 = ads.readADC_SingleEnded(3);
avg0 += adc0;
avg1 += adc1;
avg2 += adc2;
avg3 += adc3;
delay( 10 );
}
avg0 = avg0/(float)(NUMBR_OF_SAMPLES);
avg1 = avg1/(float)(NUMBR_OF_SAMPLES);
avg2 = avg2/(float)(NUMBR_OF_SAMPLES);
avg3 = avg3/(float)(NUMBR_OF_SAMPLES);

To calculate the voltage at ADS1015 inputs, you need to multiply the average value of the measurement by 3mV( 3.0f/1000.0f ).Because at the AIN0 input I have a voltage divider, so I have to multiply it by 10.

Resistors are not perfect, that's why I multiply everything by 1.0805f.

float voltage0 = DIVISOR0 * (avg0 * 3.0f/1000.0f);
float voltage1 = DIVISOR1 * (avg1 * 3.0f/1000.0f);
float voltage2 = DIVISOR2 * (avg2 * 3.0f/1000.0f);

To accurately calculate the current I have to measure the ACS712 power supply voltage. In the test, the whole circuit is powered by USB, which is approximately 5V. In my case the voltage was 4.72V. This difference

is significant when measuring accurately.

float w = ( voltage2/5.0f ) * 0.066f;
float i_cur = ((voltage2 / 2.0f) - voltage1) / w;

To calculate power we multiply the voltage and current by itself.
float power = voltage0 * i_cur;

Download source code: Arduino-voltage-and-current.ino