So I have the basic setup ready with one relay that is controlling a 200W bulb. The Phase of this bulb is passed through a current sensor acs712. While running a simple analog read example sketch, I get output 511 from ADC, which is as expected. Then I subtracted this 511 from my measurement and observed the results while turning on/off the bulb.

int sensorValue;

void setup()
  Serial.begin(9600);  // sets the serial port to 9600

void loop()
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println((511-sensorValue), DEC);  // prints the value read
  delay(100);                        // wait 100ms for next reading

Here is the output graph;

enter image description here

While the bulb is off, the current remains 0, but when I turn on the bulb, the voltage fluctuates over positive and negative side. Why is the sensor showing this behavior ?, I am not using any additional capacitor for noise reduction. Do I need to ? but I guess this is not noise. Is it ?


You are seeing that because that is what the current is doing. It's called AC - Alternating Current. It's what the mains current is.

To work with AC you have to rapidly sample over a short period to get the maximum and minimum values. Subtract one from the other and that gives you the peak-to-peak current. You can then use that to calculate the RMS current which is what you are (most likely) interested in.

  • oh now I got that... Thank you so much :), got the code from henrysbench.capnfatz.com/henrys-bench/… and its working now – Anum Sheraz Jul 10 '16 at 19:01
  • I'm not sure if that is the case here. Since it's AC the current would also be negative half the time, and we are not seeing this here. The acs712 seems to be made for AC, though I couldn't understand enough of the datasheet to say anything useful. – Gerben Jul 10 '16 at 19:02
  • @Gerben It is negative, but around a 2.5V DC offset. That's the 511 reading Anum mentions. – Majenko Jul 10 '16 at 19:04
  • Ahhh. Silly me. (-: – Gerben Jul 10 '16 at 19:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.