So now i have a DC relay being controlled by a microcontroller that turns an AC device on/off using a control line from the microcontroller being fed into a transistor to provide the necessary current for the relay coil.

The relay output is connected to a AC mains plug(female) in which the AC device plugs in(male connector).

I would like to add a status led display with the following states

  1. red (device not plugged in)
  2. yellow (device plugged in + off state / not drawing any current)
  3. green (device plugged in + on state / drawing current)

Any ideas on how would i go detecting these 3 states from the microcontroller?

  • 1
    \$\begingroup\$ For the 3 you could use a small toroid with a coil around the AC wire, that gives you a field when current is flowing \$\endgroup\$ – clabacchio Mar 21 '12 at 7:36
  • \$\begingroup\$ hmm .. that could be used for 2 and 3 ... what about 1 ? \$\endgroup\$ – Ankit Mar 21 '12 at 9:15
  • \$\begingroup\$ I think the problem is, yes, distinguishing 1 and 2...but in that case you will have a voltage in the AC part of the circuit, that you can measure with the necessary isolation \$\endgroup\$ – clabacchio Mar 21 '12 at 9:29

If I understand how your circuit is made, I would do something like this:

enter image description here

You can use an optocoupler like in this example to detect when your circuit is connected to the AC mains (optocoupler provides the galvanic isolation to avoid damaging the uC), and the coil (or transformer, like in Steven's answer) to sense the flowing current.

  • \$\begingroup\$ As I understand it the plugged-in device is a standard appliance. In that case the relay and current detection can/should be moved to the socket side. The voltage detection on the plug side is the only way to detect a plugged in device that's switched off, but if the device is just any standard appliance OP probably can't/ doesn't want to tamper with the wiring. \$\endgroup\$ – stevenvh Mar 21 '12 at 10:34
  • \$\begingroup\$ @stevenvh Indeed I'm not sure about the real circuit and I'm trying to guess. But in the case I'm right, is my scheme correct? \$\endgroup\$ – clabacchio Mar 21 '12 at 10:37
  • \$\begingroup\$ If you can play with the appliance's wiring your schematic will work. Still, like I said it makes more sense to place the relay and current sense on the socket side. \$\endgroup\$ – stevenvh Mar 21 '12 at 10:42
  • \$\begingroup\$ @stevenvh Sorry I was starting to misunderstand the OP...so this device is to be put between the mains socket and the load's plug... \$\endgroup\$ – clabacchio Mar 21 '12 at 10:46
  • \$\begingroup\$ this seems to be the closest to what i was looking for. after looking at the suggestions provided here, i might just leave this for the second revision of my prototype \$\endgroup\$ – Ankit Mar 21 '12 at 19:48

In both case 1 and 2 there's no current, and there's no electronic way to distinguish between the two on the socket side. You would need an electromechanical way to detect the presence of the plug in the socket, read: a switch in the socket, though I'm not aware of sockets which have this feature.

To distinguish between 2 and 3 you could use a current transformer or a current sense resistor. The former has the advantage that you have a galvanic separation; you don't want your microcontroller in direct contact with the AC mains voltage. The current in the transformer's secondary winding will generate a voltage across a load resistor if there's current through the primary. The resistor's value will depend on the mains current you want to detect and the transformer's winding ratio.

  • \$\begingroup\$ I agree that it's impossible to tell whether a switched off device is plugged in. \$\endgroup\$ – Federico Russo Mar 21 '12 at 10:00
  • \$\begingroup\$ I don't agree with what you said regarding 1 and 2. It is certainly possible to electronically detect something being plugged in. Think about multimeters that use split jacks for this purpose. Another way would be to use optical detection. In any case, this is most likely going to have to be a custom solution. \$\endgroup\$ – Armandas Mar 21 '12 at 10:31
  • 1
    \$\begingroup\$ @Armandas - If the plugged in device is switched off it's not possible to detect its presence on the socket side electronically using a standard mains socket. I'm not sure I know what you mean by the DMM's split jacks. \$\endgroup\$ – stevenvh Mar 21 '12 at 13:16

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.