110V detection

I'm trying to find an solution that is easy to implement for my problem.

I'm using arduinos to control 5V/10A relays to switch on and off lights, plugs and heaters.
For the lights, the relay has all the 3 wires connected, so you can use it with the wall switch too.

I would like to detect via the arduino if the light is on or off, because the arduino knows the state of the relay, but not the state of the wall switch, and to call a light on or light off command would require to detect if the light is on or off.

I tried at first with a current sensor: ACS714. I don't want to measure the amount of current but just to tell if the current is on or off.
My problem is that since I use LED lights, they seem to have a too much low current consumption: 5W, 45mA, so between power on and power off, I see no difference in my readings. I calculate the average current in a 50ms delay.

My code is the following:

boolean isLightOn(int analogPin) {
  int count = 0;
  float currentSum = 0.0;
  int counter = 50;
  while (count < counter) {
    currentSum += abs(analogRead(analogPin)-510);
    count++;
    delay(1);
  }
  return (abs((currentSum/counter)) > 3);
}

Does anyone have an idea on my problem ?
Is my assumption correct ?
Is there another option to detect if the power is on or off ?

Use an optocoupler to see power is there or not.
It will not tell you anything about the consumption, but you will know the state of the switch.
As it will probably be an AC power supply, the result of the optocoupler will be a "flashing" signal.
That can be used.
Big advantage of such optocoupler is that it is galvanic isolated and so safe to use.

It might be simpler to use a NE2H (W 100K series current limiting resistor) across the wires going to the load and an LDR to sense when the light is "On". You will need to shield the LDR from incident light and heat shrink tubing does well for this. Alternately the LDR / neon light combination could be potted in an opaque potting material. The reasoning for the neon lights that fast, high energy transients will destroy semiconductor light emitters (Led's) quickly... I made that mistake many years ago when I made a sensor circuit to determine when any of 10 relays were energized from another mechanical controller by measuring the relay coil voltage... needless to say the opto-isolators were destroyed in the field as soon as the system was powered up and activated... I might add that I had tranzorbs across the relay coils and a zener clamp across the LED's.. were useless in fixing the problem... Being the engineer on that project... It was my duty to find and fix the issues. and the neon light/LDR combination was the answer that worked every time in the field. I might add that some of the relay coils were grounded and some were connected to 120/240 Vac and grounded to activate, which precluded the use of a very wide return point which would have greatly facilitated filtering or clipping the transients... This was for a center pivot irrigation controller that had to report all conditions, water flow, position, number of rotations , variable for the individual crop being grown and to control the "End Fire sprinkler valve that irrigated the corners of a quarter section plot of land..

Doc

babelouest:
I'm trying to find an solution that is easy to implement for my problem.

I'm using arduinos to control 5V/10A relays to switch on and off lights, plugs and heaters.
For the lights, the relay has all the 3 wires connected, so you can use it with the wall switch too.

I would like to detect via the arduino if the light is on or off, because the arduino knows the state of the relay, but not the state of the wall switch, and to call a light on or light off command would require to detect if the light is on or off.

I tried at first with a current sensor: ACS714. I don't want to measure the amount of current but just to tell if the current is on or off.
My problem is that since I use LED lights, they seem to have a too much low current consumption: 5W, 45mA, so between power on and power off, I see no difference in my readings. I calculate the average current in a 50ms delay.

My code is the following:

boolean isLightOn(int analogPin) {

int count = 0;
  float currentSum = 0.0;
  int counter = 50;
  while (count < counter) {
    currentSum += abs(analogRead(analogPin)-510);
    count++;
    delay(1);
  }
  return (abs((currentSum/counter)) > 3);
}




Does anyone have an idea on my problem ?
Is my assumption correct ?
Is there another option to detect if the power is on or off ?

My first thought is an opamp, as a comparitor so you get back a high/low signal using a pot to fine tune.

I agree with Docedison. Simple, cheap, safe, tough. Don't forget that an NE2H requires a current limiting resistor, too. 33K is usually used for 120Vac. For 240Vac, 100k is about right.

I lay it flat on the photocell, placed so the leads of the neon bulb are 90 degrees from where the leads of the photocell come off and "flat" so the space between the electrodes faces the photocell. So it doesn't shade itself.