You are on page 1of 5

#define SAMPLES 300 //Number of samples you want to take

everytime you loop


#define ACS_PinR A0 //ACS712 data pin analong input
#define ACS_PinY A1
#define ACS_PinB A2
#define out_pin 13

float High_peak_R,Low_peak_R; //Variables to measure


or calculate
float Amps_Peak_Peak_R, Amps_RMS_R;
float High_peak_Y,Low_peak_Y; //Variables to measure
or calculate
float Amps_Peak_Peak_Y, Amps_RMS_Y;
float High_peak_B,Low_peak_B; //Variables to measure
or calculate
float Amps_Peak_Peak_B, Amps_RMS_B;

void setup()
{
Serial.begin(9600);
pinMode(ACS_PinR,INPUT);
pinMode(ACS_PinY,INPUT);
pinMode(ACS_PinB,INPUT);
pinMode(13,OUTPUT);//Define pin mode
}

void loop()
{

read_Amps_R(); //Launch the


read_Amps function
Amps_RMS_R = Amps_Peak_Peak_R*0.3536*0.074; //Now we
have the peak to peak value normally the formula requires
only multiplying times 0.3536
//but since the
values will be very big you should multiply by 0.06, you can
first not use it,
read_Amps_Y(); //Launch
the read_Amps function
Amps_RMS_Y = Amps_Peak_Peak_Y*0.3536*0.
074; //do your
calculations and compare them to real values measured by an
Ammeter. eg: 0.06=Real value/Measured value

read_Amps_B(); //Launch
the read_Amps function
Amps_RMS_B = Amps_Peak_Peak_B*0.3536*0.074;

Serial.print("PHASE R =
");
Serial.print(Amps_RMS_R); //Here I show
the RMS value and the peak to peak value, you can print what
you want and add the "A" symbol...
Serial.print(" ");
Serial.print("PHASE Y = ");
Serial.print(Amps_RMS_Y);
Serial.print(" ");
;//Here I show the RMS value and the peak to peak value, you
can print what you want and add the "A" symbol...
Serial.print("PHASE B = ");
Serial.print(Amps_RMS_B);

Serial.println();
Serial.println();

delay(1000);

if(Amps_RMS_B>10.0){
pinMode(13,HIGH);}}

void read_Amps_R() //read_Amps function calculate


the difference between the high peak and low peak
{ //get peak to peak value
int cnt; //Counter
High_peak_R = 0; //We first assume that our high peak
is equal to 0 and low peak is 1024, yes inverted
Low_peak_R = 1024;

for(cnt=0 ; cnt<SAMPLES ; cnt++) //everytime a


sample (module value) is taken it will go through test
{
float ACS_Value_R = analogRead(ACS_PinR); //We read a
single value from the module

if(ACS_Value_R > High_peak_R) //If


that value is higher than the high peak (at first is 0)
{
High_peak_R = ACS_Value_R; //The
high peak will change from 0 to that value found
}

if(ACS_Value_R < Low_peak_R) //If that


value is lower than the low peak (at first is 1024)
{
Low_peak_R = ACS_Value_R; //The low
peak will change from 1024 to that value found
}
} //We keep
looping until we take all samples and at the end we will have
the high/low peaks values

Amps_Peak_Peak_R = High_peak_R - Low_peak_R;


//Calculate the difference
}

void read_Amps_Y() //read_Amps function calculate


the difference between the high peak and low peak
{ //get peak to peak value
int cnt; //Counter
High_peak_Y = 0; //We first assume that our high peak
is equal to 0 and low peak is 1024, yes inverted
Low_peak_Y = 1024;

for(cnt=0 ; cnt<SAMPLES ; cnt++) //everytime a


sample (module value) is taken it will go through test
{
float ACS_Value_Y = analogRead(ACS_PinY); //We read a
single value from the module

if(ACS_Value_Y > High_peak_Y) //If


that value is higher than the high peak (at first is 0)
{
High_peak_Y = ACS_Value_Y; //The
high peak will change from 0 to that value found
}

if(ACS_Value_Y < Low_peak_Y) //If that


value is lower than the low peak (at first is 1024)
{
Low_peak_Y = ACS_Value_Y; //The low
peak will change from 1024 to that value found
}
} //We keep
looping until we take all samples and at the end we will have
the high/low peaks values

Amps_Peak_Peak_Y = High_peak_Y - Low_peak_Y; //Calculate


the difference
}

void read_Amps_B() //read_Amps function calculate


the difference between the high peak and low peak
{ //get peak to peak value
int cnt; //Counter
High_peak_B = 0; //We first assume that our high peak
is equal to 0 and low peak is 1024, yes inverted
Low_peak_B = 1024;

for(cnt=0 ; cnt<SAMPLES ; cnt++) //everytime a


sample (module value) is taken it will go through test
{
float ACS_Value_B= analogRead(ACS_PinB); //We read a
single value from the module

if(ACS_Value_B > High_peak_B) //If


that value is higher than the high peak (at first is 0)
{
High_peak_B = ACS_Value_B; //The
high peak will change from 0 to that value found
}

if(ACS_Value_B < Low_peak_B) //If that


value is lower than the low peak (at first is 1024)
{
Low_peak_B = ACS_Value_B; //The low
peak will change from 1024 to that value found
}
} //We keep
looping until we take all samples and at the end we will have
the high/low peaks values

Amps_Peak_Peak_B = High_peak_B - Low_peak_B; //Calculate


the difference

You might also like