Integrating an analog signal using Arduino Mega 2560
V1=analogRead(A0)*2/1023.0-1.0;


This will give you the voltage across R1 in units of 2.5&nbsp;V. I do
not know whether you care or not about the units but, if you want the
voltage in volts, then:


the voltage at the Arduino input is analogRead(A0) * (5.0/1024)
to get the voltage across R1, you have to subtract 2.5&nbsp;V
to get the voltage at the output of the transformer, you have to
multiply by 11.


This could be written as



float V = (analogRead(A0) * (5.0/1024) - 2.5) * 11;


but, in order to minimize the number of floating point operations, you
can simplify it to

float V = analogRead(A0) * (55.0/1024) - 27.5;


You could then integrate the voltage by running it through a function
like this:

static float integral(float x)
{
    static float y;                         // last filter output
    static uint32_t last_sample;            // last time sampled
    uint32_t now = micros();
    float dt = (now - last_sample) * 1e-6;  // step time in seconds
    last_sample = now;
    y += x * dt;
    return y;
}


Now, there is an issue with this approach: the average voltage at the
input of the Arduino is not going to be exactly 2.5&nbsp;V, because
your resistors R3 and R4 will not have identical resistance. Then the
output of the integral will slowly drift and eventually become
unreasonably large.

One way to mitigate this drift problem is to measure this average using
the same Arduino running the same program: disconnect the mains, see how
the output of the program drifts, and measure the drift rate. Then you
subtract the drift rate from the 27.5 in the code, and fine tune until
there is no drift at all. There is, however, the risk that some time
later it will drift again, due to components changing behavior as the
temperature changes.

A better option would probably be to not integrate, but instead use a
first-order low-pass filter. Such a filter behaves like an integrator
for any signal faster than its cutoff frequency but, unlike a simple
integrator, it has a finite gain at zero frequency. You can turn the
integrator into a low-pass filter simply by changing the line
y += x * dt; into

y += (x - y/tau) * dt;


where tau is the time constant of the filter.