Detecting AC signal - Page 1
Forum section: electronics / beginners

author: Xkonti
author_rank: Contributor
timestamp: June 30, 2014, 03:31:19 pm
content: Hello. I have a design like this:I dont know how to detect AC signal from switch. This switch isn't turning anything on. By signal I mean 0 (off) or 1 (on).I thought to use bridge rectifier and optoisolator but I'm afraid that connecting only this to 240V will cause loads of sparks and eternal darkness.Is there any simple way to get signal from 240V? It would be great if I can isolate switch input because uC will be powered by battery in future.

author: katzohki
author_rank: Frequent Contributor
timestamp: June 30, 2014, 04:25:38 pm
content: I feel obligated to say: be very careful here with live mains.It seems like you're really over-engineering a light switch here, but I assume you're just doing this to learn. There's a lot of ways to sense an active voltage on 240V AC. Current sense would work, if your switch had a load for one. Another approach would be to use the same type of AC->DC, DC->DC setup and send the 5v ("on") to a microcontroller input pin.

author: Xkonti
author_rank: Contributor
timestamp: June 30, 2014, 04:51:22 pm
content: I will be carefulSwitch has no load.I had same idea of converting it into 5V but it seems over-complicated. It greatly icreases size of contraption.It would be great if I can isolate this switch input from whole system because uC can be powered from battery in future.

author: retrolefty
author_rank: Super Contributor
timestamp: June 30, 2014, 04:56:49 pm
content: Quote from: Xkonti on June 30, 2014, 03:31:19 pmWhy not just use a 240VAC relay for that, with the micro reading the contacts to determine if the relay is activated or not?

author: Xkonti
author_rank: Contributor
timestamp: June 30, 2014, 05:00:40 pm
content: Quote from: retrolefty on June 30, 2014, 04:56:49 pmWell... It sounds like a solution

author: Christe4nM
author_rank: Unknown
timestamp: June 30, 2014, 06:21:46 pm
content: Another way could be a using a high resistance voltage divider to get the mains down enough to use an optocoupler. Could be just an LED with a light sensor put together in heat shrink tubing. The isolated side would see a varying DC only. So if you put a simple RC filter in maybe a Schmitt trigger and there is your digital high/low mains sense.Or use a DPDT switch instead (mains rated of course) of which the second set of poles is connected at low voltage dc level to a micro input. Keep creepage and clearance in mind though. Switching the mains is switching an input of the micro.

author: nsayer
author_rank: Regular Contributor
timestamp: June 30, 2014, 09:16:06 pm
content: If you want to be really safe, you might consider the MID400. It's an optoisolator chip designed to be connected to line voltage AC. On the secondary side, you get an open collector that's closed when AC is present.For 120 volts, you use a 22 k-ohm 1W flame-proof resistor on one leg. Internally, it's two LEDs in opposing parallel, so the LED lights on both half-cycles, and its' designed with slow switching so that you don't get pulses at zero-crossing.

author: kingofkya
author_rank: Regular Contributor
timestamp: June 30, 2014, 10:23:12 pm
content: Be careful you might want to start with less than 24v Ac first.Make sure to pay attention to your grounds when probing a mains connected circuit, easy to short things out with scope probes, and other test equipment.As far as detecting the switch I would say just get a 5-6v transformer and run it though a rectifier there are better ways but not as safe to be playing with.

author: Dinsdale
author_rank: Regular Contributor
timestamp: June 30, 2014, 11:52:16 pm
content: Why do you need the "?" block?You just want to know if there is 240V or not?The "AC->DC DC->DC" block gives you that information -- if the micro is running, you have 240V.The switch can just be on the micro using 5V logic.Unless you're doing it just to be doing it. Then, half-wave rectify it, divide that with some power resistors, integrate that, and fuse the whole thing. The switch should be on the 5V side.And, yes, please be careful.

author: nsayer
author_rank: Regular Contributor
timestamp: July 01, 2014, 02:37:54 am
content: IMHO AC lines should always be galvanically isolated from logic systems for safety. That means either using transformers, isolated power supplies (which in turn use transformers) or opto-isolators as a "moat."

author: XFDDesign
author_rank: Frequent Contributor
timestamp: July 01, 2014, 03:35:09 am
content: I think the first real question is, "What is your design goal?"What is it you're trying to achieve? Laying that out will give far better focus on how to get to the solution than forcing specific blocks. Learning exercise, or not.

author: Psi
author_rank: Super Contributor
timestamp: July 01, 2014, 03:38:27 am
content: A small solid state relay would probably be physically smaller than a 230V relayRelays with 230v coils tend to be quite large.

author: HackedFridgeMagnet
author_rank: Super Contributor
timestamp: July 01, 2014, 06:16:11 am
content: You can use a current transformer. It is isolated too. But it only tells you there is current flowing through the switch, it doesn't tell you if the switch is on but no load is attached.If the line is always loaded this will never happen. You could actually put a tiny load on just to make sure it is always loaded.A capacitive load would actually use very little power but draw detectable current.Another possibility (non isolated) is to measure the voltage difference between the switch wire and electrical ground, via a divider. You have to make sure you have the active side of the switch though.This mod is probably not legal in some countries.

author: nsayer
author_rank: Regular Contributor
timestamp: July 01, 2014, 04:46:57 pm
content: I went back and read the whole thread again. This system actually has a couple of building block needs that I used in my Hydra project.You want a microcontroller to be able to sense the presence of AC and control the application of AC. As I said before, the first of those can be done with the MID400. The second can be done with an opto-isolated triac. The triac you pick depends on the characteristics of the load. I've done opto-isolated triacs two ways - one with a BTA-20 for a moderately high powered load (8A in my case - I over-spec'd the triac for thermal reasons), and one with a much smaller surface mount triac for controlling a contactor coil (to switch very, very high powered loads - upwards of 30A).In both cases, the MOC3020 is an optoisolated triac driver. Effectively it means that your microcontroller lights an LED which proxies the load control.Again, with both the MOC3020 and the MID400, it means that your logic system is galvanically isolated from the AC lines - a critical safety feature, as I said before.Relays could do the same, but relays mean that your low voltage power supply must be capable of powering the relay coil, and the relay, being a mechanical thing is large, makes noise, arcs, etc.

author: Xkonti
author_rank: Contributor
timestamp: July 01, 2014, 09:09:00 pm
content: Hmm... I see a lot of questions about why I want to do that.I'm making some kind of house network. Many small arduinos (Arduino Pro Mini) in many places making many things and comunicating to each other with 2.4GHz transmitters.This node will be bigger hub. But it nedds to control light. Problem is that light needs to be controlled by 2 switches on 2 levels.Switch on lower level will be sending wireless message to hub when its state change, but switch on upper level is strangely placed so I can't fit receiver and relay in it to switch lamp on/off and I can't place box near it because it would be visible. The good thing is that upper switch is currently connected to lamp. What I thought about is that this hub (placed under lamp) will be controlling lamp. Getting wireless state of lower switch and detecting upper switch which I will disconnect from lamp and connect to the system. Turning light on/off with relay is piece of cake.I'm not sure how to implement detecting AC Power from upper switch. As nsayer said, I can use MID400. I think this is good idea, but I am not well educated in electrical and electronical laws. I'm better programmerThis is how I see this hub system for now:I looked into MID400 datasheet and I didn't found anything about maximum AC Voltage (maybe I'm just blind). How can I calculate what resistors to put on AC input to MID400 to not burn anything? On way from upper switch to hub I have totally no load. Just 2 wires that were connected straight to lamp, providing it with power.I think I could search for alternative of MID400 just because of its availability in Poland. I don't want to pay enormous money for single element. I'm used to transport cost at about 0.50 - 1.50$ not 10$But I'm not sure what I'm looking for...

author: nsayer
author_rank: Regular Contributor
timestamp: July 01, 2014, 09:35:53 pm
content: The datasheet has an absolute maximum RMS current for the emitter of 25 mA, but it also lists an on-state current of 4 mA. From there, it's E=IR. Test circuit 2 has a 22 k-ohm resistor, which yields around 5 mA RMS current @ 120 VAC.I recommend 22 k-ohm 1W flame-proof resistors for 120 VAC or 47 k-ohm for 240 VAC hot-neutral (like Europe). For 240 as it's done here in the US, I use two 22 k-ohm resistors, one on each hot.

author: katzohki
author_rank: Frequent Contributor
timestamp: July 01, 2014, 09:42:29 pm
content: Here is how a 3-way switch is "typically" wired in a house:http://users.wfu.edu/matthews/courses/p230/switches/SwitchesTut.htmlFor the remote switch, I say use a 5 Volt power supply and directly switch that into an input pin on your Microcontroller. It would be BEST to use a switch that is not a standard housing voltage switch so that no one gets confused in the future and electrocutes themselves or starts a fire.Actually, that's a good point. If you leave this installed into your house wiring it could be dangerous for someone down the road, or invalidate your homeowner's insurance.

author: Xkonti
author_rank: Contributor
timestamp: July 01, 2014, 10:59:45 pm
content: Can I use ISOCOM H11L1X (PDF:http://www.hfo.pl/_allegro/H11L1X.PDF) instead of MID400? I have 240V ACkatzohki - I want to use microcontroller to automatically switch it off after some time and I want to be able to get data when which switch was used.

author: aroby
author_rank: Regular Contributor
timestamp: July 02, 2014, 12:34:31 am
content: Seems to me you'd be more successful and safer using some Zwave switchesAnthony

author: boz
author_rank: Regular Contributor
timestamp: July 02, 2014, 02:03:09 am
content: You can also use a Current Transformer like a SCT-013-005 on the live wire your then isolated from the dangerous stuff, they costs about $10 on ebay.Pop the transformer input into an op amp / rectifier to get a 5V or 3.3V output when mains is detected like thishttp://easyeda.com/9TDZWUSCYk

author: Xkonti
author_rank: Contributor
timestamp: July 02, 2014, 07:48:16 am
content: After very intense thinking I will use the easiest and cheapest solution which was proposed here several times:Small 1A USB Charger. Small, easy to use, safe, easy to disconnectIt's only 2,99PLN + 2,00PLN shipping (~$0,99 + $0,66 shipping).

author: septillion
author_rank: Newbie
timestamp: July 02, 2014, 09:25:37 am
content: Yep, I was about to suggest that but my EEVblog registration took ages. (Yes, it's finally my first post here.)Another way would be to switch 5V with the switch instead of mains. I used that in the livingroom here. The wallswitch just switches 5V.And about triacs, yeay, they are fun. But the require a bit more knowledge then a relais. (Heat, snubbing etc). If jou don't want to dim the light/output I would use a relais as well. You can buy cheap modules which already have the relais, diode, transistor and resisors in place and just need 5V, GND and an input.

author: nsayer
author_rank: Regular Contributor
timestamp: July 02, 2014, 03:35:10 pm
content: Quote from: septillion on July 02, 2014, 09:25:37 amI used to say the same thing about DC-DC converters. Thanks to Dave, I am beginning to become quite familiar with them and - dare I claim - adept.Dave hasn't (so far as I know) done a video on traics, but every datasheet I've seen has a ton of example circuits. There's almost a guarantee that anything you would want to do with one has an example circuit available from somewhere via google.Like so many things to do with electronics, they're both simple and complex, depending on how far down the rabbit hole you want to fall.Oh, and using a little USB power brick to detect AC... I can get behind that, providing the supply in question is safe. Lots of Wun Hung Lo power adapters out there have potentially very hazardous failure modes, and they're certainly not above fibbing about UL/CSa approval. The safest option after buying from a reputable vendor is, ironically, building it yourself so youknowit's been done properly.

author: Xkonti
author_rank: Contributor
timestamp: July 02, 2014, 07:32:10 pm
content: For now I think I have all the knowledge for this project. It is fairly easy. Nearly everything is just 5V and 3.3V logic: Switch input, TFT LCD, 2.4GHz Wireless Module, Encoder, Relay, sensors etc. Thanks for help and various interesting options. I certainly learned something from this

author: LukeW
author_rank: Frequent Contributor
timestamp: July 03, 2014, 03:38:24 am
content: Here's a simple, easy to understand, beginner-friendly suggestion that might do what you want: How about just using another 5V mains plugpack or SMPS connected to the "detect when this is switched on" 240VAC circuit, and connecting the 5V output to your uC? Obviously the power capacity does not have to be large, any old surplus phone charger or something with a tiny current output might be used.Sure, a current transformer or Hall sensor or shunt resistor might be smaller or cheaper - but more complicated, more involved, and potentially more dangerous for a beginner. No offence.Also, a current sensor will detectwhen a load that is drawing significant current is connected and the circuit is switched on, as opposed to detectingwhen the circuit is switched onwhich is actually a different problem specification.

author: mij59
author_rank: Frequent Contributor
timestamp: July 03, 2014, 03:52:13 am
content: Hi,Here is an other possibility, its a zero crossing detector made with generic parts.http://www.dextrel.net/diyzerocrosser.htmOr you could also replace the existing switch with a wireless one.

author: nsayer
author_rank: Regular Contributor
timestamp: July 05, 2014, 08:27:45 pm
content: I took a fresh look at the optoisolator category. I've discovered the LTV-824. It's a tenth the price and can serve the same purpose adequately. The only real gotcha is that it's not an intentionally slow transistor like in the MID-400, which means your controller would have to poll for a millisecond or so to insure it doesn't mistake a zero crossing for absence of voltage.

author: David_AVD
author_rank: Super Contributor
timestamp: July 05, 2014, 09:28:02 pm
content: Quote from: nsayer on July 05, 2014, 08:27:45 pmYou can also use the (pulsing) opto output to trigger an interrupt on the micro each AC half period. In the interrupt routine you set a variable to the small number. As part of a timer interrupt (say 10ms) you decrement the same variable (but only if > 0).Assuming 50Hz mains, you'd have the zero-cross interrupt (pre)setting the variable every 10ms (half cycle). If the pulses stop coming in, the timer interrupt will hit zero (after n * 10ms). At that point you trigger the "off" state.The "on" state can be triggered in the zero-cross interrupt after checking that you're not already in the "on" state.There's other ways to do it of course and you can refine it to give control over the AC detection and absence times.

author: mij59
author_rank: Frequent Contributor
timestamp: July 06, 2014, 03:06:44 am
content: Quote from: nsayer on July 05, 2014, 08:27:45 pmUse a pullup resistor and capacitor network with a time big time constant (1 second or so), use the output of the optocoupler to discharge the capacitor.The capacitor voltage will stay "low" as long as the ac signal is present.Use a comparotor to detect if the capacitor voltage is "high" or "low".

author: sunnyhighway
author_rank: Frequent Contributor
timestamp: July 06, 2014, 01:41:39 pm
content: You could build your own optoisolator using a neon signal light and an LDR or photodiode or phototransistor.

author: nsayer
author_rank: Regular Contributor
timestamp: July 08, 2014, 07:58:03 pm
content: Quote from: mij59 on July 06, 2014, 03:06:44 amSoftware is cheaper.It turns out that a little brainstorming has led us/me to a simple circuit that does a few things for the OpenEVSE II board set. The circuit is a pair of S1M diodes from each hot line (240 VAC here in North America is delivered with a center-tapped ground reference, so each hot line is 120 VAC to ground/neutral, and each is 240 volts away from the other - because it's 180 degrees out-of-phase), wired with the anode to the respective hot line and the cathodes tied together. The common cathode line goes into a series resistor, into the anode of the LED part of the opto and then to ground (and ground specifically - not neutral like you might expect).This circuit allows the controller to verify that a low impedance path to ground exists, and also for it to detect whether one or the other of the hot lines is actually a neutral line. The controller's own digital input pins will provide the thresholding (it doesn't have to be terribly accurate). If you don't see the line go low at least once within 10 ms or so, then that's a ground failure. If you watch it transition three times and time how long it spends low and how long it spends high, then if it's high longer (meaning the zero-crossing time plus a half-cycle), that means that one of the "hot" lines is a neutral. If it's low longer (meaning that the only high period will be near zero-crossing), that means that both of them are hot.The diodes insure that you can't get a false-negative on the ground failure test by cross-conducting from one hot to the other.

author: f5r5e5d
author_rank: Frequent Contributor
timestamp: July 08, 2014, 09:08:30 pm
content: people could rightly be annoyed if you put current into the safety gnddon't have the standards in front of me but I recall ~1 mA is a limit for leakage current in consumer line equipment - you need to run your opto led lower than thathere:http://www.chromausa.com/pdf/app-notes/AN%20-%20Leakage%20Current%20Part%20I%20-%2003252013.pdfthe 5 mA "permenantly attached power" means hard wired by an electrician from your equipment into a mains boxso you need to run with less than 0.5 mA with a 3 prong plug cord that goes to a regular gnded wall socket

author: nsayer
author_rank: Regular Contributor
timestamp: July 08, 2014, 10:27:14 pm
content: That's about how much we're talking about, except that it's (most likely) a 240 volt outlet, like a NEMA 6-50 or L6-30 rather than a 5-15.There's a chicken-and-egg problem at work. The spec requires us to test the safety ground to make sure it's present and effective. But you can't *do* that without tickling it.