Arduino library for AC line voltage and frequency measurement.
Experimental, work in progress
This library is to use a transformer (TRAFO) like the ZMPT101B to measure the AC line voltage.
The library was inspired by a discussion on the forum about using an external ADC for the ZMPT101B library. This library tries to generalize the concept so it can be used for different transformers and with both internal as external ADC's.
The library supports
- RMS of an 230 or 110 V AC.
- detect the frequency of the line.
Feedback as always is welcome.
The library is not tested with hardware yet.
Do not apply this product to safety protection devices or emergency stop equipment, and any other applications that may cause personal injury due to the product's failure.
- https://github.com/RobTillaart/ACS712 - current sensor AC and DC
- https://github.com/RobTillaart/INA226 - current and voltage sensor (one of many)
- https://github.com/RobTillaart/printHelpers - for scientific notation
Trigger for this library
TODO:
- Test on Arduino UNO et al with transformer.
- order hardware - e.g. ZMPT101B module.
Note: A minimal test with an UNO R3 (powered USB) with floating internal ADC touched by my finger gave a frequency of around 50 Hz which is our mains.
#include "TRAFO.h"- TRAFO()
- bool begin(int32_t (* readADC)(), uint32_t steps, float maxVoltage)
- readADC is a function to read an ADC returning an int32.
- steps = nr of ADC steps, typical power of two like 1024, 4096, etc.
- maxVoltage = conversion voltage for max value of ADC
- float detectFrequency(uint8_t times = 1) idem. Typical around 50.0 or 60.0. Sample multiple times to improve accuracy.
- void setMicrosAdjust(float factor = 1.0f) adjust the micros timing to improve the accuracy of the frequency
- float getRMS() idem. Typical around 230V or 110V. Only works if detectFrequency() is called before.
- int32_t getADC() call the readADC given in constructor.
- int32_t getZeroPoint() last determined zero point.
- improve documentation
- get hardware to test
- calibration routine
- investigate performance
- create unit tests if possible
- flag if detectFrequency is called for getRMS().
If you appreciate my libraries, you can support the development and maintenance. Improve the quality of the libraries by providing issues and Pull Requests, or donate through PayPal or GitHub sponsors.
Thank you,