OpenEnergyMonitor Community

EmonLib / ESP32 How to calibrate?


I am using my Arduino development tools to use emonlib on an ESP32 development board. I got everything compiling and running but my serial output is not putting out stable and correct values. So I guess I need to calibrate but after several days I haven;t managed to get it working.

I am using an SCT-013-010 sensor. This sensor has a build in burden and puts out 0-1V for 0-10A.

I am using 2x 10k Ohm resistor devider between +3v3 and gnd. One side of the sct to the middle of this devider and the other pin to ESP input pin GPIO-36.

My question:

  • How to get the correct value for Cal in: emon1.current(CurrentSensePin, Cal);

  • Is 1480 good enough for my setup? double Irms = emon1.calcIrms(1480); I notice no stable value with a stable load…

I am not measuring the voltage.

I just want to measure my power usage and put it out on serial. no more then that. Well, next step will be sending an email when power passes a border, hence the ESP32. But basically my question is just Arduino / EmonLib.

I havent found many example with the SCT-013-010. So probably others may find this a helpfull question as well. Thank you!

I haven’t worked with the SCT-013-010, or the ESP. But
I have built an Arduino with other clamp-on CT’s.
My experience has been at the lower end of the scale,
less than 1.5 amps, the accuracy was like +/- 50%.
I would suggest try measuring at 5 or even 10 amps.

Few people use the low current c.t’s, but there’s no specific reason to think it should be any different to the “shop standard” SCT-013-000 except that the burden is internal.

1.  The current calibration constant for your 10 A c.t. is 10.0
2.  “1480” is no longer the optimal value. You want the closest number that is the number of samples to a whole number of mains cycles. The sampling rates, measured with a standard emonTx V3.4 (and the emonPi is the same processor) are:
calcIrms( ) - approx 5588 current samples per second.
calcVI( ) - approx 2535 pairs of voltage & current samples per second.
Sampling rate of emonLib
for more details.

I’ve no idea how good (or otherwise) the ADC on the ESP32 is, but the one in the ESP8266 is not really usable for our purposes, as it takes far too long to make a reading, hence there are not enough samples in each mains cycle to get a sensible reading.
I’ve read that it is capable of 6000 samples / second, but whether that is using the same method to access the ADC that emonLib uses, I do not know.

If you are interested in measuring currents significantly lower than 10 A, you can of course multiply the current by passing more turns through the c.t, then change the calibration accordingly: 5 for 2 turns, 3.33 for 3, etc.

I think the ESP32 ADC is not compatible with emonlib or it is just very bad at all. It seems to have functions to set the attenuation and voltage range. This makes the 2 resistors not ending up in the middle. But even after studying ESP32, I still dont understand the values read. I made my own lowest/highest detector over 50000 samples and calculated RMS from there but the values are just very noicy and come not close to what I expect. On my scope I do understand the readings and can manually calculate the power (using a 100W light bulb). So I will probably move to a normal Arduino as a test now.

EmonLib was designed and developed for the Arduino platform and the Atmel 328P.

Is the title of this thread correct? It seems that your problem is not calibration, but with correctly designing the input conditioning components and converting emonLib to work with the ESP32. Is that correct?

It is very obvious to me that changes will be necessary for a different processor with a different architecture, so my first question is, having quickly looked at some of the documentation for the ESP32, how have you changed emonLib to cater for the different commands that the different processor requires, and the different procedures required by the ADCs?

That makes no sense to me, can you explain what you mean?
Looking here, it would appear that (a) noise is a problem that Espressif acknowledges, and (b) that the input must be biased to a level of 1 V for optimal operation, not 1.65 V as you appear to have it.

Hello Hasse,

Would you mind to share how you interfaced the ESP32 ADC to EmonLibCM ?
I amstudying how I could get this to work, but if the work has already be done that would be great.

I understand that the ESP32’s ADC is not the best, but at the moment I have started my project and this is mainly for learning purpose. In the future I might go back to the ATMEGA.


I ended up with using an external ADC. Worked flawlessly and at once.

Sorry I lack a bit of knowledge on this topic. The only ADC I used was the MCP3008 for rapsberrypi.

In your case I understand that you used ESP32 + ADC. And so the sensors are connected to the ADC and the ADC sends the Digital value of the sensor to the ESP32. From what I know, the ADC sends the infor,ation to the MCU via 1 pin only. Then how have you modified the Emonlib to take all these changes ?

Thank you

I think I used an ADS1115 /1015 ADC from AliE. It connects over SPI to the ESP. I used Arduino programming interface and there is a good library for this ADC. So you will get it working with just a few lines of code.

But after I finished the project, I replaced it with a Sonoff POW module that I loaded with the Tasmota firmware to talk to my MQTT server that collects all the data. That was eventually what I wanted to achieve.