ESP8266 - Random values. Need help


I’ve gathered components including an ESP8266 board, CT sensor and other bits.
I’ve followed the circuit diagrams and got the code running but the values coming from the sensor are way too high!

My setup uses a UEETEK SCT-013-000 CT sensor and a 33Ω burden resistor.
I’m running at 5V with my bias voltage hovering around 2.5V.

The values I’m getting on the analogue input is 600-700 when I’m actually only using 2 to 3Amps.

Anybody had a similar issue and know where I’ve gone wrong?

Which circuit diagrams did you follow?
What exactly do you mean by that?
What sketch are you using?

The circuit I have is:

My sketch is:

    int current = 0;
  int maxCurrent = 0;
  int minCurrent = 1000;
  for (int i=0 ; i<=200 ; i++)  //Monitors and logs the current input for 200 cycles to determine max and min current
    current = analogRead(A0);    //Reads current input
    if(current >= maxCurrent)
      maxCurrent = current;
    else if(current <= minCurrent)
      minCurrent = current;
  if (maxCurrent <= 517)
    maxCurrent = 516;
  double RMSCurrent = ((maxCurrent - 516)*0.707)/11.8337;    //Calculates RMS current based on maximum value
  int RMSPower = 220*RMSCurrent;    //Calculates RMS Power Assuming Voltage 220VAC, change to 110VAC accordingly
  if (RMSPower > peakPower)
    peakPower = RMSPower;

I’m afraid you’re totally wrong there. That circuit isn’t suitable for the ESP8266, only for something with an analogue input that works over the range 0 - 5 V. From the ESP8266 data sheet:

“The input voltage range is 0 to 1.0 V when TOUT is connected to external

Therefore, you need to set the midpoint voltage to 0.5 V, and you need to change the value of the burden resistor from 33 Ω to a value that gives you about 0.33 V rms (that’s about 1 V peak - peak) at the maximum current you want to measure.

I also have big reservations about the sketch.

Firstly, you need to mark up the code with three backticks on the line before and after. I’ve done that for you.

Secondly, because you’ve used the wrong assumptions, all your numbers are now wrong.

At maximum current (defined by your choice of burden resistor) you’ll have approx 0.5 V peak at the ADC input, so you need to recalculate based on that.

But what’s worse, there’s generally no relationship between the peak (or peak to peak) values of current and the rms value, because the current waveform is rarely a well-behaved sinusoid. Therefore your 0.707 will only apply then.
We get round that problem by properly calculating the rms (root mean square) value of the current directly from the measured values.
As far as I know, we don’t have a standard sketch for the ESP8266, but I think our standard library will work. So I suggest you start with this sketch:

The “111.1” in

emon1.current(1, 111.1);

depends on your c.t. and the value you choose for the burden resistor.
The number 1480 in

double Irms = emon1.calcIrms(1480);

is the number of sample to average over, and it should be a whole number of mains cycles for best accuracy. I have no idea (and it is not documented) what a suitable number would be for you. I would think start at a high number, and reduce it until the values start to become erratic, then go back a little way.

Thank you for the advice.
I’m going to start changing things based on what you’ve said and see where I get.

I’ll report back :blush:

If you care, at ALL, about accuracy, don’t use the ADC in the esp8266. It is not rated at any accuracy specification and will generally be wrong. It might give reasonably consistent results, but it is not suitable for measuring AC power consumption.


Sorry it’s been a while, been so busy with work.
I got this working using the 3.3v of the ESP8266 and following to a point: Making a $15 Current Scanner for Azure IOT Hub – Kevin Saye

I will look at adding an ADC as the values go up and down a little bit which I’m putting down to the accuracy of the ADC on the ESP8266.

However comparing it to an energy monitor I had lying around it’s consistent with the values that outputs.

So I’ve got it all linked up to a Golang service I’ve written and SQL database which is logging the readings every 2 seconds and I’m getting great data now :slight_smile:

Glad it is working for you. Sometimes just having an indication of how much is being used is all you need. If you only have a single sensor, its stability and resolution become more important than it’s absolute accuracy when you are trying to figure out everything that is making up your base load and how much each thing is using. While the difference between 10W and 20W is a very significant percentage difference, the cost of the electricity for either is not that great. But when you want to figure out if it is worth doing something about, it is pretty important to have accurate data. As an example my old measuring system indicated my dryer was using 11W when it wasn’t on. That costs me about $11/year. Should I buy a new dryer to save that electricity? Should I put in a switch to turn it off? Should I unplug it when it is not in use? Or should I do nothing?

I did the later. My new system indicates the dryer is drawing 4W when it is off. Since the dryer is almost 30 years old, it probably doesn’t make sense to do anything about it now, especially at this lower estimate for the savings possible.