Author Topic: Detecting AC signal  (Read 15516 times)

0 Members and 1 Guest are viewing this topic.

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Detecting AC signal
« on: June 30, 2014, 03:31:19 pm »
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.
« Last Edit: June 30, 2014, 04:52:49 pm by Xkonti »
 

Offline katzohki

  • Frequent Contributor
  • **
  • Posts: 378
  • Country: us
    • My Blog
Re: Detecting AC signal
« Reply #1 on: June 30, 2014, 04:25:38 pm »
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.
 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #2 on: June 30, 2014, 04:51:22 pm »
I will be careful ;)
Switch 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.
 

Offline retrolefty

  • Super Contributor
  • ***
  • Posts: 1648
  • Country: us
  • measurement changes behavior
Re: Detecting AC signal
« Reply #3 on: June 30, 2014, 04:56:49 pm »
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.

Why not just use a 240VAC relay for that, with the micro reading the contacts to determine if the relay is activated or not?

 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #4 on: June 30, 2014, 05:00:40 pm »
Why not just use a 240VAC relay for that, with the micro reading the contacts to determine if the relay is activated or not?
Well... It sounds like a solution :D
 

Offline Christe4nM

  • Supporter
  • ****
  • Posts: 252
  • Country: nl
Re: Detecting AC signal
« Reply #5 on: June 30, 2014, 06:21:46 pm »
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.
 

Offline nsayer

  • Regular Contributor
  • *
  • Posts: 133
  • Country: us
    • Geppetto Elecronics
Re: Detecting AC signal
« Reply #6 on: June 30, 2014, 09:16:06 pm »
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.
Buy my stuff!! It's not at all terrible!! http://tindie.geppettoelectronics.com/
 

Offline kingofkya

  • Regular Contributor
  • *
  • Posts: 143
  • Country: us
Re: Detecting AC signal
« Reply #7 on: June 30, 2014, 10:23:12 pm »
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.
 

Offline Dinsdale

  • Regular Contributor
  • *
  • Posts: 77
  • Country: us
    • pretzelogic
Re: Detecting AC signal
« Reply #8 on: June 30, 2014, 11:52:16 pm »
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.
This can't be happening.
 

Offline nsayer

  • Regular Contributor
  • *
  • Posts: 133
  • Country: us
    • Geppetto Elecronics
Re: Detecting AC signal
« Reply #9 on: July 01, 2014, 02:37:54 am »
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."
Buy my stuff!! It's not at all terrible!! http://tindie.geppettoelectronics.com/
 

Offline XFDDesign

  • Frequent Contributor
  • **
  • Posts: 442
  • Country: us
Re: Detecting AC signal
« Reply #10 on: July 01, 2014, 03:35:09 am »
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. :)
 

Offline Psi

  • Super Contributor
  • ***
  • Posts: 9889
  • Country: nz
Re: Detecting AC signal
« Reply #11 on: July 01, 2014, 03:38:27 am »
A small solid state relay would probably be physically smaller than a 230V relay

Relays with 230v coils tend to be quite large.
Greek letter 'Psi' (not Pounds per Square Inch)
 

Offline HackedFridgeMagnet

  • Super Contributor
  • ***
  • Posts: 2028
  • Country: au
Re: Detecting AC signal
« Reply #12 on: July 01, 2014, 06:16:11 am »
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.

 

Offline nsayer

  • Regular Contributor
  • *
  • Posts: 133
  • Country: us
    • Geppetto Elecronics
Re: Detecting AC signal
« Reply #13 on: July 01, 2014, 04:46:57 pm »
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.
Buy my stuff!! It's not at all terrible!! http://tindie.geppettoelectronics.com/
 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #14 on: July 01, 2014, 09:09:00 pm »
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 programmer ;) This 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...  :-\
 

Offline nsayer

  • Regular Contributor
  • *
  • Posts: 133
  • Country: us
    • Geppetto Elecronics
Re: Detecting AC signal
« Reply #15 on: July 01, 2014, 09:35:53 pm »
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.
Buy my stuff!! It's not at all terrible!! http://tindie.geppettoelectronics.com/
 

Offline katzohki

  • Frequent Contributor
  • **
  • Posts: 378
  • Country: us
    • My Blog
Re: Detecting AC signal
« Reply #16 on: July 01, 2014, 09:42:29 pm »
Here is how a 3-way switch is "typically" wired in a house:
http://users.wfu.edu/matthews/courses/p230/switches/SwitchesTut.html

For 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.
 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #17 on: July 01, 2014, 10:59:45 pm »
Can I use ISOCOM H11L1X (PDF: http://www.hfo.pl/_allegro/H11L1X.PDF) instead of MID400? I have 240V AC ;)
katzohki - 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.
« Last Edit: July 01, 2014, 11:48:54 pm by Xkonti »
 

Offline aroby

  • Regular Contributor
  • *
  • Posts: 214
  • Country: us
Re: Detecting AC signal
« Reply #18 on: July 02, 2014, 12:34:31 am »
Seems to me you'd be more successful and safer using some Zwave switches

Anthony
 

Offline boz

  • Regular Contributor
  • *
  • Posts: 75
  • Country: nz
    • Roving Dynamics Ltd
Re: Detecting AC signal
« Reply #19 on: July 02, 2014, 02:03:09 am »
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 this http://easyeda.com/9TDZWUSCYk
Fearless diver and computer genius
 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #20 on: July 02, 2014, 07:48:16 am »
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 disconnect ;)
It's only 2,99PLN + 2,00PLN shipping (~$0,99 + $0,66 shipping).
 

Offline septillion

  • Newbie
  • Posts: 2
Re: Detecting AC signal
« Reply #21 on: July 02, 2014, 09:25:37 am »
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.
 

Offline nsayer

  • Regular Contributor
  • *
  • Posts: 133
  • Country: us
    • Geppetto Elecronics
Re: Detecting AC signal
« Reply #22 on: July 02, 2014, 03:35:10 pm »
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.

I 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 you know it's been done properly.
« Last Edit: July 02, 2014, 03:39:50 pm by nsayer »
Buy my stuff!! It's not at all terrible!! http://tindie.geppettoelectronics.com/
 

Offline XkontiTopic starter

  • Contributor
  • Posts: 14
  • Country: pl
Re: Detecting AC signal
« Reply #23 on: July 02, 2014, 07:32:10 pm »
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 ;)
 

Offline LukeW

  • Frequent Contributor
  • **
  • Posts: 686
Re: Detecting AC signal
« Reply #24 on: July 03, 2014, 03:38:24 am »
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 detect when a load that is drawing significant current is connected and the circuit is switched on, as opposed to detecting when the circuit is switched on which is actually a different problem specification.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf