# Check if electrical current exists in high voltage

I'm thinking about a simple home automation project, containing a Rasberry Pi, a Sainsmart SPDT Relay, I would like to switch the state of a ordinary bulb (ON , OFF) using both the relay and the old switch, so here if I'm in a remote area away from the bulb, I cannot get the bulb state exactly, is there any low cost way to get if the current exist or not?

I have found this current sensor but it is not the solution, it is not cheap, compared to the relays.

• You don't need to know if the bulb is drawing current to switch its state. Connect the relay, lamp and existing switch as you would a set of switches in a hall or landing. Dec 18, 2013 at 23:20
• Your question is pretty vague. When you say "switch the state of the bulb" do you mean just turning it on or both turning it on and off? Why can't you just measure the voltage across the bulb instead of the current? What kind of bulb are you switching, what is the voltage and what is the current? Dec 18, 2013 at 23:25
• @JoeHass I've just edited my question, the bulb is 100W , the voltage is 220V AC. Dec 19, 2013 at 6:44
• Actually, @geogeek, if you hadn't posted that Sparkfun link, I'd have suggested the very sort of thing. It is the correct answer. Dec 19, 2013 at 6:51

Andy already showed you how to connect 2 switches to 1 load. But this isn't the best solution for a home automation system. Better is to have all inputs (switches and buttons) connected to the Raspberry Pi, and at the other end have the actuators (relays and dimmers, for instance). Separate inputs from outputs.
You mention more complicated wiring, but on the other hand all your inputs can be low-voltage.

As for the number of relays you can connect, there's no limit. Use cheap 74HC595 shift registers and daisy-chain as many as you need. You'll only need 3 lines to control the chain: data, clock and latch. You clock the successive states of the 1000 or so relays into the shift registers, and complete the action by applying the latch signal.

To detect current the current transformer you mention is one option, but there's also the Hall effect sensor, which detects the magnetic field caused by the current and is most often an IC. the Allegro ACS714 has an analog output, so that you not only can detect whether current is present, but also how high the current is. Costs much less than the current transformer.

• Thanks a lot you have provided both solutions, i will think about the solutions and compare them to get the more robust and cost effective. Dec 19, 2013 at 9:28

The only other way I can think of is using an photodiode/phototransistor which change properties based on light. They are usually less than a dollar at your local electronics store.

So if you mounted the sensor in such a way that the diode gets activated when the bulb turns on you can get its state from the photodiode. You will have to calibrate the sensor yourself but you might even be able to get a value of brightness instead of just on/off.

I would like to switch the state of a ordinary bulb (ON , OFF) using both the relay and the old switch

Here is an article from wiki about using a multiway switch. Here's a picture from the article: -

There are two switches shown - one is your old switch and one is your relay contact. No matter what the state of the lamp is, if the relay flips over, the lamp state will reverse. Ditto the old switch.

You don't need to know the state of the lamp to be able to switch the state.

• I'm sorry, i think i was not very clear in my question, i meant in the requirements of my project, the user needs to know the state of the bulb, in the case of he is away from the bulb, also to make sure that the bulb is switched off, because there's other guys who can switch its state, or they can forget it switched on at night. Dec 19, 2013 at 9:09

An alternative would be to disconnect the old switch from the mains wiring and wire it to an input pin on the Raspberry Pi.

The Pi then controls the lamp from the relay, on command from either the switch or the internets, and will always know both the state of the switch and the lamp.

• That's very good idea, but it needs some extra wiring, How many bulbs i could command using this approach with one Ras Pi ? Dec 19, 2013 at 9:22
• Infinity bulbs - if you use IO expanders such as MCP23017 you can control 16 things per chip, maybe 8 switches + 8 bulbs per chip, but you can address more than once chip (and if you get cunning you can expand almost indefinitely). I think one or two of the Pi IO boards already uses the 23017 so there is a driver already written. Dec 19, 2013 at 9:25