# How to determine whether electrial appliance is On or Off using ADC or Optocoupler

I want to sense the On/Off state of an electrical appliance (e.g. light bulb 100W) using a microcontroller ATmega16L. How do i go about doing this? My mains supply specs are 230V, 50Hz

• Need a lot more detail. What voltage does the appliance use? Is it mains? Why do you need to use an ADC for a binary choice? – Cybergibbons Jun 1 '12 at 6:58
• ok. here goes. I want to check if the appliance is On or Off using ADC. the appliance will be connected to 230VAC. What will I have to do to bring the voltage down to a value which can be sensed by the micro's ADC which is 2.54Vref. – David Norman Jun 1 '12 at 7:09

You're telling us too little. What's the "device", for instance?

Like Cybergibbons says, you don't need an ADC for detecting a logic level, because that's what you'll have: a high when it's switched on, a low when off (or vice versa).

I'll suppose it's a mains operated appliance. You can't connect directly with the device's power supply: this would make that all of your circuit is connected to the mains, and it would be no longer touch-safe. Touching any part of it could be lethal.

Use an optocoupler to isolate your circuit from the mains:

If there's enough voltage across the LEDs the transistor will be on, and the output pulled low. Only during the zero-crossing of the mains sine you'll get a positive peak. You can connect that to any GPIO pin of your microcontroller.
You'll have to use 2 resistors in series for R1 and R2 each, unless they're rated at 180V at least.

This will indicate that there's 230V AC on your appliance. If it has an on/off switch it won't tell you if it's on. In that case use a current transformer in series with the appliance, and terminate it with a resistor. The appliance's current will cause a voltage across the resistor, the resistor's value determines the voltage level.
You can't use this directly, because it's AC. You'll have to rectify it and make a peak detector using a diode and a capacitor.

Easier to use, but more expensive is the i-Snail_V. It's also based on a current transformer, but it gives a DC voltage out proportional to the measured current. The i-Snail-V-10 for instance gives 5V DC out at 10A. Since the voltage in this case is analog you would connect it to the ADC. You won't only know if the appliance is switched on, but also its current consumption. (That's a first indication for its power, but not precise.) Use a clamping zener diode on the output in case the voltage would rise higher than 5V.

• thanks Steven. For a test appliance I would use a light bulb 100W, 230VAC. I dont get the explanation you gave. I dont get the diagram. There are no labels – David Norman Jun 1 '12 at 7:29
• @David - Sorry about the labels. The two connections at the left go parallel to the bulb. The top one at the right is your microcontroller's V+, the bottom one is its ground, and the one with the pulse is your input. If there's no 230V present the LEDs of the optocoupler will be off, and the transistor will not conduct. Then the 2k pullup resistor defines the output as high. If the bulb is on the transistor will pull to output low. So the logic is inverted. Keep in mind that you'll have a positive peak 100 times a second @ 50Hz, so make sure to sample enough. – stevenvh Jun 1 '12 at 7:36
• oh i see what you mean. thanks a lot steven. you're the man – David Norman Jun 1 '12 at 7:40
• one question though. The resistors across the bulb will have to be high power resistors. Wouldn't the resistors dissipate a lot of heat which means a lot of power dissipation. Wouldn't there be an efficiency factor for the circuit?? – David Norman Jun 1 '12 at 7:50
• @sandun - your comment seems to be mutilated. There's "I know my ideas are" then empty lines and then "but the device that I describe is completely perfect". Then post it as an answer. It's probably a good idea. – stevenvh Jun 1 '12 at 10:41