Skip to content

RobTillaart/TRAFO

Repository files navigation

Arduino CI Arduino-lint JSON check GitHub issues

License: MIT GitHub release PlatformIO Registry

TRAFO

Arduino library for AC line voltage and frequency measurement.

Description

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.

Warning

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.

Related

Trigger for this library

Tested

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.

Interface

#include "TRAFO.h"

Constructor

  • 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

Measurements

  • 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.

Debugging

  • int32_t getADC() call the readADC given in constructor.
  • int32_t getZeroPoint() last determined zero point.

Future

Must

  • improve documentation
  • get hardware to test
  • calibration routine

Should

  • investigate performance

Could

  • create unit tests if possible
  • flag if detectFrequency is called for getRMS().

Wont

Support

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,

About

Arduino library for AC line voltage and frequency measurement.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages