Hi,

I have a 20 amp ACS712 current sensor hooked up and working per the recommended sketch as shown below. The serial monitors first displays 3.63 Amps RMS then stabilizes to 0.00 Amps RMS with no load. When I apply a load it displays an accurate reading (0.5 Amps RMS for my portable heater).

Thats all great. However, I can’t figure out how to obtain a digital output (to drive a relay) when a load is applied, and to have the relay stay on for an additional 10 seconds when the load is turned off.

Any help in this programing be much appreciated:

/*

Measuring AC Current Using ACS712

*/

const int sensorIn = A0;

int mVperAmp = 100; // 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(){

Voltage = getVPP();

VRMS = (Voltage/2.0) *0.707;

AmpsRMS = (VRMS * 1000)/mVperAmp;

Serial.print(AmpsRMS);

Serial.println(" Amps RMS");

}

float getVPP()

{

float result;

int readValue; //value read from the sensor

int maxValue = 0; // store max value here

int minValue = 1024; // 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 maximum sensor value*/

minValue = readValue;

}

}

// Subtract min from max

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

return result;

}