How To Measure Ac Voltage Using Ampt101b
How To Measure Ac Voltage Using Ampt101b
How To Measure Ac Voltage Using Ampt101b
#include<math.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
void loop()
/* 1- AC Voltage Measurement */
if(micros() >= voltageLastSample + 1000 )
/* every 0.2 milli second taking 1 reading */
{
voltageSampleRead = (analogRead(VoltageAnalogInputPin)- 512)+
voltageOffset1; /* read the sample value including
offset value*/
voltageSampleSum = voltageSampleSum + sq(voltageSampleRead) ;
/* accumulate total analog values for each sample readings*/
voltageSampleCount = voltageSampleCount + 1;
/* to move on to the next following count */
voltageLastSample = micros() ;
/* to reset the time again so that next cycle can start again*/
}
if(voltageSampleCount == 1000)
/* after 4000 count or 800 milli seconds (0.8 second), do the calculation and
display value*/
{
voltageMean = voltageSampleSum/voltageSampleCount;
/* calculate average value of all sample readings taken*/
RMSVoltageMean = (sqrt(voltageMean))*1.5;
// The value X 1.5 means the ratio towards the module amplification.
adjustRMSVoltageMean = RMSVoltageMean + voltageOffset2;
/* square root of the average value including offset value */
/* square root of the average value*/