OpenEnergyMonitor Community

Arduino Nano & EmonLib: Measure current with and without USB power

Tags: #<Tag:0x00007f1be3151cf0>

Hi everyone.

I’m trying to build a simple power monitor based on Arduino Nano v3 (cheap chinese clone) and a custom circuit with 230 to 9V transformer on the voltage side and Talema AC1025 CT on the current side.

The difficulty is that when I power up my system from USB port of my PC it’s working almost OK. Almost means that without any load the current is not equal to zero (0.01 to 0.05A). So I decided to power up the system with a 12V 2A power supply. I connected VIN and GND inputs of my Nano to the supply and 5V and second GND pins to the measuring circuit. Now Arduino board is still working great. BUT! The current is ALWAYS equal to zero! Regardless to the load. And the voltage is fine (217.0 to 223.5V as usual in my city :grinning:).

I measured the output voltage on the current circuit when powered from USB andthe load is present, the voltage floats proportionally above the 2.5V according to load power (and the current). When the system is powered autonomously it always stays at 2.5V. Without any changes.

About my current transformer. It’s a Talema AC1025, the 25A max transformer. According to manufacturer’s recommendations the burden resistor is 100 ohms.

The schematic:

Why the current is not being measured with external power supply? Any help is appreciated. Thanks in advance.

First, the non-zero current (10 - 50 mA) is probably noise being picked up from somewhere, most likely from the digital part of the processor or via the power supply.

Second, is the 5 V supply out to the analogue front end present when you are powering your Nano from 12 V? If not, there’s your answer.

Third, if the d.c. average voltage at the two analogue inputs A0 and A1 changes according to the current you’re measuring and mains voltage, then something is wrong. Those two points should stay at 2.5 V d.c always, but with up to about 1 V rms of a.c. superimposed on the quiescent d.c. voltage. See the diagrams in Resources > Building Blocks > CT sensors - Interfacing with an Arduino and Resources > Building Blocks > Measuring AC Voltage with an AC to AC power adapter

Note that with your 100 Ω burden, you can only measure to about 16 A before you overload the Arduino input. Decrease the value of your burden resistor if you want to measure up to 25 A. (You overload a current transformer when you increase the value of the burden resistor.)

Thank you for your reply Robert!

When I power my Nano with 12V DC the voltage on the 5V pin is 5.00V.

Today I connected my Nano board through the DC-DC converter with output of 5.00V. The measuring circuits are powered from the same source. And still no luck: current measures are always zero and working great (almost) when powered with USB.

Voltage on A0 (pin that is connected to CT part) is 2.48V. When powered with USB the A0 pin has 2.34V (but 5V pin is also not actually 5V, it’s 4.70V).

Speaking about my CT: as I said it’s not a SCT that is “standard” to use with EmonTx. It’s an AC1025 from Talema. Here is the datasheet: Following this doc I used 100ohm burden resistor. I didn’t find any info about the turns number in AC1025 but it said that the turns ratio is 1:1000.

So I still cannot understand what happens when I connect the current measure part to the external 5V. Like there are different volts in USB and DC power supply :smile:

1 Like

The maths for the CT is simple: The ratio is 1000:1, or more properly 25 A : 25 mA (CT ratios should always be given as currents - a 1000:1 CT would measure 1 kA with a secondary current of 1 A). Yours is rated to 25 A, so it will have a 25 mA max secondary current, and you need a maximum of 1.6 V rms (a little less than 5 V peak-peak) across the burden resistor. The 100 Ω that the data sheet states is the maximum value for satisfactory operation, not the value you need for a 5 V Arduino. You will actually get better performance (lower errors) with a lower value burden.

There is something very silly happening.

The voltage input and the current input work in exactly the same way. Therefore both should behave similarly.

What is the actual voltage of the 12 V supply when it is powering everything?
Do both A0 and A1 measure ~2.5 V at the input pin in both cases - USB 5 V supply and the 12 V supply?
Are all the GND points connected together?
Does the voltage input work with both USB 5 V supply and the 12 V supply?

Yes, voltage input is working fine in both cases.

It’s 12V. As I said before now I have connected a LM2596-based DC-DC converter to lower the voltage to 5.00V and now my Arduino is powered with 5V via the 5V pin and GND. The measuring circuits are connected to the same converter.

On external supply:

  • A0 (current) is 2.49V,
  • A1 (voltage) is 2.43V.

On USB power:

  • A0 is 2.34V,
  • A1 is 2.28V.

And I’m (almost) sure that internal Arduino voltage is not 5V when it is fed by USB.

Yes, all the GND pins are connected to one node on the DC-DC converter.

And yes, there is something very silly happening. But what exactly?..

Just measured AC voltage on the current part outputs (between A0 and GND) with a small iron as the load (~500W).

When the system is on external power source it’s 0.16V AC.
When it’s running on USB it’s also 0.16V AC.

But current values on Arduino still acts like a dead. :grinning:

That should be OK. emonLib should be able to handle those differences.
I don’t see how it can be a fault in your analogue front end. Are you able to try any of the other analogue inputs?

Can you attach your sketch (complete) to a post?

The sketch (also uses EtherCard to send data via Ethernet with ENC28J60):

#include <EtherCard.h>
#include <EmonLib.h>

// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x50,0x69,0x2D,0x30,0x31 };
static byte myip[] = { 192,168,0,10 };

byte Ethernet::buffer[500];
BufferFiller bfill;

EnergyMonitor emon1;
double Irms;
double Vrms;
double Pwr;
static char vrms_char[10];
static char irms_char[10];
static char pwr_char[10];

void setup() 
  if(ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) Serial.println(F("Failed to access Ethernet controller"));

  emon1.voltage(1, 241.0, 1.72);  // Voltage: input pin, calibration, phase_shift
  emon1.current(0, 10);           // Current: input pin, calibration.

static word homePage()
  emon1.calcVI(20, 500); // Calculate all. No.of half wavelengths (crossings), time-out
  Vrms = emon1.Vrms;
  Irms = emon1.Irms;
  Pwr = Vrms * Irms;

  dtostrf(Vrms, 20, 10, vrms_char);
  String vrms_str(vrms_char);
  dtostrf(Irms, 20, 10, irms_char);
  String irms_str(irms_char);
  dtostrf(Pwr, 20, 10, pwr_char);
  String pwr_str(pwr_char);
  bfill = ether.tcpOffset();
    "HTTP/1.0 200 OK\r\n"
    "Content-Type: text/html\r\n"
    "Pragma: no-cache\r\n"
    "<meta http-equiv='refresh' content='2'/>"
    "<title>PowerSensor AW1</title>"
    "<h1>$S, $S, $S</h1>"), irms_str.c_str(), vrms_str.c_str(), pwr_str.c_str());
  return bfill.position();

void loop()
  word len = ether.packetReceive();
  word pos = ether.packetLoop(len);
  if(pos)  // check if valid tcp data is received
    ether.httpServerReply(homePage()); // send web page data

About Ethernet hardware part: it is fed by the same 12V supply (it can supply current up to 2A i.e. up to 24W of power so it must be enough for both measuring circuit and Ethernet controller) through the separate LM2596 DC-DC converter set to 3.3V DC. The ground nodes of main scheme and Ethernet controller are separated.

Just tried A6 for the current and A7 for the voltage. But nothing changes.

What do you mean by this? That does not seem right to me. How are the two related? Or is there an opto-coupler between the Arduino and the Ethernet parts?

The problem is that ENC28J60 consumes (relatively) lot of power (something around 500mA) and 3.3V of voltage. So it cannot be connected to Nano 3V3 output. I use external supply (12V -> 3.30V) to power it. And there are no common power connections between Nano and Ethernet shield, only digital pins to interface with last one.

Could it be the source of the problem? Is it worth to join all the grounds (3.3 and 5V) together? :smile_cat: Or my username is «not compatible» with this project?

The «system» looks like this:

But the digital pins need a reference - there is no such thing as absolute voltage, it is only by convention that we regard the general mass of the earth as 0 V, or GND (more properly COMMON or 0 V) as our reference when measuring voltages on a particular circuit board. Unless you tie all the GND/COMMON points together, there’s nothing to say what the signal voltages are, for example +5 V on one could be [think of a number] -87 V with respect to the common rail on the other.

I cannot read the pin designations on that photo, so it does not help.

Recently checked the connections with the multimeter and found that all the ground nodes in scheme are tied together so the problem is not there I think. Could it be the Nano inner problem with analog reference voltage? I.e. on USB it works fine because the AREF value is set in other way than in «autonomous mode». But if so why the voltage detection is working perfectly?

There is one more problem (with Ethernet module stability) but for now I need to solve the first (and the main) one…

I can’t help thinking that there’s something very silly that you and/or I have overlooked. Is there something special about AI0 which means it gets “stolen” when you are using the 12 V power supply? Can you try another input - say AI2 - for the current? (Don’t choose 6 or 7 - I’ve read they could be special.)

Forget emonLib etc, and go back to basics. Try writing a very simple sketch to read the raw values from AI0, AI1, AI2 (try them all!) , and print to serial output every second or two. (I assume you have a programmer and can monitor that directly, not going via Ethernet etc.) You should see around 512 from each with the input bias circuit connected but with no voltage and current inputs connected, and apparently random values when you connect the transformers. Or you could “pull” the midpoint with a low value (say 1 kΩ) pot connected across the 5 V supply, wiper to the analogue input, and check that the inputs read 0 (0 V) to 1023 (5 V) or thereabouts.


There are no so stupid and silly things here but me. :disappointed:

The problem was NOT in the scheme and NOT in my Nano.

Changed this

dtostrf(Irms, 20, 10, irms_char);

to this

dtostrf(Irms, 10, 5, irms_char);

and now I have normal (but yet uncalibrated) values. So the problem was in value conversion and not in the hardware part at all…

That’s about the bottom line! Anyway, we got there in the end, and it’s good to know that everything is now OK.
[N.B. It wouldn’t be the first time I’ve been caught by something like that. My favourite is to edit one sketch and load a different version of the same name, and wonder why what I’ve changed has no effect. :anguished: ]

Oh, one more question, please: what about my CTs? I used 100 ohm burden resistor according to the datasheet and there is a diagram thet shows that the voltage on full load (25A) with 100 ohm burden will be 2.5V.

Look at my first answer (2nd post) in this thread.

Hi dumbasprog,

I am trying to build a nano sketch to send data to a local server emoncms, with ethercard library. Can you publish the complete sketch please? in your sketch I can’t see the json string. Thanks.