MEASUREMENT OF AC CURRENT USING ACS712

/*
Measuring AC Current Using ACS712
*/
const int sensorIn = A0;
int mVperAmp = 185; // 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;
}


}


// AmpsRMS is the required current . needs to compare if its get higher
// Arduino Relay Control Code
 
#define relay A0
#define interval 1000
void setup() {
  pinMode(relay, OUTPUT);
}
void loop()
{
   digitalWrite(relay, HIGH);
   delay(interval);
   digitalWrite(relay, LOW);
   delay(interval);
}

First program code is to return a current value using acs712 sensor
second program code is to activate relay .
so i need the arduino the read the current value , once the read value is predominantly high than than previous current value , say 10% higher , arduino needs to activate the relay .
how is it possible to combine both the code ?

You will need to read the output of the AC712, something like volts = analogRead(ACS_PIN);

volts will be in bits 0-1024, then you will need to convert to volts (dividing by 1024/5)

then you can compute amps by applying conversions for the sensors sensitivity and output at 0 amps--all this is in the data sheet.

Then you know with the measured current is and can go from there.

i got the code , would you mind to combine it ?