0% found this document useful (0 votes)
44 views2 pages

Master Piece

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views2 pages

Master Piece

Uploaded by

khalid
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

/*

Measuring AC Current Using ACS712


www.circuits4you.com
*/
const int sensorIn = A0;

int mVperAmp = 78; // use 100 for 20A Module and 66 for 30A Module

double Voltage = 0;
double VRMS = 0;
double AmpsRMS = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
int sensorValue = analogRead(A1);
float volt = sensorValue * (245.0 / 1024.0);

Voltage = getVPP();
VRMS = (Voltage/2.0) *0.707; //root 2 is 0.707
AmpsRMS = (VRMS * 1000)/mVperAmp;

float Power = volt * AmpsRMS;

Serial.print("AC Voltage = ");


Serial.print(volt);
Serial.println(" Volt");
Serial.print("\t AC Current = ");
Serial.print(AmpsRMS);
Serial.println(" Amps");
Serial.print("\t \t Power = ");
Serial.print(Power);
Serial.println(" Watt");

delay(2500);
}

float getVPP()
{
float result;
int readValue; //value read from the sensor
int maxValue = 0; // store max value here
int minValue = 1023; // store min value here

uint32_t start_time = millis();


while((millis()-start_time) < 1000) //sample for 1 Sec
{
readValue = analogRead(sensorIn);
// see if you have a new maxValue
if (readValue > maxValue)
{
/*record the maximum sensor value*/
maxValue = readValue;
}
if (readValue < minValue)
{
/*record the minimum sensor value*/
minValue = readValue;
}
}

// Subtract min from max


result = ((maxValue - minValue) * 5.0)/1023.0;

return result;
}

You might also like