Example Code for Arduino-AC Current Measurement

Last revision 2025/12/08

This tutorial is going to test AC current. The result of AC current is its effective value, i.e. the same as an Ammeter reading.

Wiring Diagram

SEN0098_current_sensor.png

DANGER: This diagram can also be applied to AC current connection. But notice that the module should be cascaded on one electric wire ( +/- ). But if you connect it to two electric wires in parallel, you will short the circuit , which is dangerous.

Sample Code

float reading = 0;
float currentValue = 0;

void setup(){
  Serial.begin(115200);
}
void loop() {
  reading = analogRead(*); //Raw data reading
  currentValue = (reading - 510) * 5 / 1024 / 0.04 - 0.34;
  Serial.println(currentValue);
  delay(2);
}

Result

I tested with a lamp @220V~, and got the result shown below:
Result_of_AC_current.png

Since AC current here is a Sine wave, you want to focus on the amplitude of your waveform. You can read the extreme data which are the maxmum value 0.27 and the minimum value -0.34, and use the maxmum absolute value one as the ( Effective) AC current. In this case its .34

Was this article helpful?

TOP