using ADC in arduino for ammeter

Posts: 22
Joined: Mon Feb 13, 2017 5:22 pm

using ADC in arduino for ammeter

Postby theskaz » Fri Jun 02, 2017 5:12 pm

Hello again,

I have a D-1085 ( 50Amp model) from CHZ Labs: ... dlqZML.pdf

It is connected to Pin 34 on an ESP32 Thing from sparkfun. It is also wired backwards (from IP- to IP+). So, with no load, it should be sitting at 2.5v and at full 50Amps it should be at 0v.

here is my function:

Code: Select all

void updateAmps() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousAmpSampleMillis >= interval)
    previousAmpSampleMillis = currentMillis;
    double oldAmpValue = amps;
    rawAmpValue = analogRead(AMMETER_PIN);
    voltage = (rawAmpValue / 1023.0) * 5.00;
    amps = ((voltage - acsOffset) / mVperAmp);
    if (oldAmpValue != amps)
      char buf[3];
      char command[20] = {0};
      itoa(amps, buf, 10);
and here are the referenced global variables:

Code: Select all

#define AMMETER_PIN 34
int mVperAmp = 40;
double acsOffset = 2.5;
int rawAmpValue = 0;
double voltage = 0;
double amps = 0;
long previousAmpSampleMillis = 0;
long interval = 1000;
my issue is that it is always 0. if i dont convert to int, it is around 0.28 (which may actually be accurate) and can get up to 0.41 (pulling 48.5+ Amps (240v)). I have seen around where the ADC isnt very accurate, is that my issue? or my math?

I would show an example output printing the rawampvalue and voltage, but i physically broke my esp32 so I can't hook my usb cable to it anymore.

Who is online

Users browsing this forum: No registered users and 7 guests