Simple AC detect circuit

Go To Last Post
31 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simple AC detection circuit (on/off) to interface with an AVR pin. I have very limited board space so I'm looking for something that minimizes component sizes (trying to avoid circuits that include a transformer and rectification, etc.).

My current method is similar to this

http://ruggedcircuits.com/html/circuit__26.html

Ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Better way is to insert the LED inside a diode bridge or in the very least include an inverse parallel diode in circuit with the LED input

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, that is a better idea. Apparently some bridge rectifiers are smaller than I thought (eg, MB6S from Fairchild).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Better but not cheaper...
Use the same like you mention and increase R2 and you can even use an 1/8W, I use the D1 after the opto, because of reverse voltage of the LED and discharges, and put some capacitor on the collector...

Regards,

Bruno Muswieck

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Not so keen on the 20k @ 220V advice on that link.

oddbudman

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

When I needed to do that (for 24V AC, though) I used a bridge rectifier and opto-coupler.

Leon Heller G1HSM

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Back on this today after being pulled off for other things. Anyway, just a quick sketch to make sure I'm moving the right direction...

I don't want to include C1 because the physical size of the capacitor is larger than desired. C2 is easier sizewise to include.

Concerning R1, it needs to be chosen to allow enough current to flow into the opto-coupler at both ends of the 90-260VDC range but also power sized for V^2/R. If I go with a 1W resistor (reasonable), I can choose a value somewhere in the 15K-20K range with the appropriate selection of opto.

Comments (or do I have the whole thought wrong! yikes!)?

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whether or not that will function for your needs depends on the detection criterion. Do you have to test for simple on/off? Or, above 90V, below 90V? The issue is that an opto-isolator does not have a well defined threshold.

Forget about the ground connection on the input side of the opto. It will get you into major trouble.

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have a heater that is getting AC power. It is supplied with (normally) 120 or 240VAC (depends on site). All I want to know is if the AC power to the heater is on. My only other thing to worry about is that the AC power might be on for only a few seconds at a time.

I understand not connecting the ground on the input side (really no reason to do so). Thinking now about the 'not well defined threshold on the opto-coupler' comment - I now understand the concern. Hmmmm...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Consider this... Maybe put C1 across the opto diode. Use a single diode for rectification, not a bridge. That will significantly reduce the power in R1.If you can handle the software, put the o/p (R2) into an interrupt and use that in conjunction with a watchdog....Or spend some time periodically looking at R2 to make sure it goes low.
20mA into the opto could be reduced chosing a better opto. AFAIR, you can get devices that will run at 1-2 mA.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The concern is that the on/off switching point will vary from opto to opto and pretty strongly with temperature. Detecting presence of absence of power should be no problem, but detecting whether it is 120V or 240V would add some "challenge".

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Adding a couple components like an 86 Volt zener, and a high voltage current regulator (depletion mode fet and resistor) may help set a lower threshold. Then again it will be a bit farther from the simple requirement.

It all starts with a mental vision.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A super-simple (3 component) solution I've used with great success:

A 68K resistor, in series with a 1N4005 diode, connected to the LED input of a H11L1 optical isolator. Output of the opto goes to the AVR input pin. The LED "diode" must be biased in the same "direction" as the 1N4005, i.e. diode cathode to LED anode. Other side of opto LED returns back to the AC neutral line.

The input will be oscillating 1-0-1-... at a 50/60HZ (depending on your country) rate, but it's easy to write "debouncing" software to detect continuous pulsing and give you an "AC present" flag for your software.

Be sure to enable the internal pullup on the AVR, as the H11L1 has an open collector output.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't think the OP will have too much trouble sorting the 110/240 issue.
H11L1s are good at just over 1mA i/p current to operate.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Bawker, as mentioned earlier, you need a diode across the led so that the led is not reverse biased due to leakage across the in4005. Leds usually dislike much over 5v of reverse bias.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Going on Bawker's comments (and those from earlier since it seems I'll also test the first option), we are talking about a circuit like the following.

When the AC signal is positive, current flows through the diode and LED turning on the output. Current is at max 3.5 mA (even though H11L1 has a max input detector current of 5.0mA) and resistor of 68K value should be a 1W resistor.

When the AC signal is negative, the vertical diode in the picture allows current to flow back through the 68K resistor without damaging the LED.

The diode reverse voltage should be well over 260V to be safe.

I have none of these components around but should have all including the bridge diode if I want to go that route by Monday.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engrpetero,
Yes... that is the exact circuit I use for AC detection (I forgot about the reverse-bias prevention diode when I made my post, but it's in my hardware... It's been several years since I've needed an AC detect in a project, and it's easy to forget the little details! :wink:).
The way it works out, at 220V you get the 3.5-ish mA, which amounts to approx. 0.7 Watts power dissipation across the resistor - assuming it's DC, which it isn't. Since it's AC, the actual power dissipation will be less... but I use a 1W just to be on the safe side. At 110V, the current drops to just over 1.6 mA, which is the threshold turn-on current of the H11L1. I have that circuit running in over 200 boards out "in the field", most of which have been out there for over 5 years. I know it's a reliable and functional circuit, despite its simplicity.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks, Bawker, and all the others that contributed to this thread. I learned several things. I sincerely appreciate the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engrpetero wrote:
Thanks, Bawker, and all the others that contributed to this thread. I learned several things. I sincerely appreciate the help.

Input for you on the code:

The detector will output a logic "1" when the AC voltage is at the trough, or below the voltage necessary to turn on the detector. It will output a logic "0" at 20mSec. or 16.666mSec. intervals regularly (pulsing) if AC is present, depending on whether you're in a 50 or 60HZ country. The detector will output a non-fluctuating solid "1" if no AC is present.

What I do in my code is have an "ACPresentFlag" boolean variable, which is initialized to "Off" or "0" at the start of code, along with an ACCounter variable. In my timer routine (which is running at a 1mSec. interrupt, yours might be different... so compensate for the time difference), I look for a "0" on the detector input. If a "0" is seen, I set the ACPresentFlag to "On", then set my ACCounter variable at 22... it counts down and stops counting at zero. If it ever reaches zero, I clear the ACPresentFlag.

The main code then never needs to worry about the mechanical stuff going on "under the hood", it just looks at the ACPresentFlag variable to see if AC is present or absent.

Feel free to ask any further questions you might have.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Already part way through coding this behavior before seeing your post. I think I've got it from here. THanks!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Move the vertical diode to the right hand side of the horizontal diode and cut the disipation in 68k resistor in half.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Move the vertical diode to the right hand side of the horizontal diode and cut the disipation in 68k resistor in half.

Please explain in detail... this is above my pay grade.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Current on the negative cycle flows through the first diode ( the one drawn vertically) and current flows on the positive cycle through the diode in series with the opto. Moving the parallel diode to the opto side means the main current only flows on the positive cycle and a smaller leakage current only flows on the negative cycle.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

if you just need to detect if there is main supply or mains fail you could easy read/use the Ap Note:

http://www.atmel.com/dyn/resourc...

This Ap. Note is used for Zero Cross Detection, but it's the same circuitry for your needs.

Also note that in this case there is no isolation.

regards.

Michael.

User of:
IAR Embedded Workbench C/C++ Compiler
Altium Designer

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
Current on the negative cycle flows through the first diode ( the one drawn vertically) and current flows on the positive cycle through the diode in series with the opto. Moving the parallel diode to the opto side means the main current only flows on the positive cycle and a smaller leakage current only flows on the negative cycle.

I see it now... so obvious. :shock:

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

engrpetero wrote:
Going on Bawker's comments (and those from earlier since it seems I'll also test the first option), we are talking about a circuit like the following.

When the AC signal is positive, current flows through the diode and LED turning on the output. Current is at max 3.5 mA (even though H11L1 has a max input detector current of 5.0mA) and resistor of 68K value should be a 1W resistor.

When the AC signal is negative, the vertical diode in the picture allows current to flow back through the 68K resistor without damaging the LED.

The diode reverse voltage should be well over 260V to be safe.

I have none of these components around but should have all including the bridge diode if I want to go that route by Monday.

You don't need both of the 1N4005s - the horizontal one will prevent any reverse current flowing through the LED.

You can just short out the horizontal diode and the LED will only have a worst case of about 0.7V reverse bias.

Alternatively if you leave out the vertical one the dissipation on the resistor will be halved - there will be some minor leakage current through the diode which can be avoided by putting a small diode (e.g. 1N914) directly across the LED. This approach avoids any chance of reverse bias and halves the power dissipation in the resistor.

Even though the dissipation in the resistor may be low you should be careful with the voltage rating - I would not recommend less than 1/2 watt resistors for withstanding 120V AC.

If you need to reduce the dissipation further the resistor can be replaced with a capacitor in series with a resistor - the resistor is to limit the peak current when power is applied but the majority of the voltage is dropped across the capacitor without any heat generation. Use appropriate component ratings.

kevin

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

kevin,
NICE post... I'm learning a lot from this thread today!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

And the cap MUST be 'X rated' :)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I meant to post a follow up to this topic - sort of forgot about it.

By using a timer interrupt and the appropriate settings, I have a bracketed section in my main{} called 'DoOneSecondTasks' which obviously is used to do tasks at one second intervals.

I added a PCINT interrupt on the appropriate pin attached to this AC detect circuit. All I do in that ISR is count pin toggles (one for the ac detect low/high transition and one for the ac detect high/low transition). 50Hz AC waves should give about 100 toggles and 60Hz transitions should give about 120 toggles. I count the toggles using a variable called acInt;

Since all I care about is absence or presence of the AC, I just look at the acCtr every second. If it is greater than about 90, I decide the AC must be present. Then I reset the acCtr, of course. Anyway, works very well. Thanks again for the help.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

In the 'old days' I would use as small a 120vac relay as I could find and just use the relay contacts as I pleased.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

little expensive but this opto will ignore zero crossing every half cycle according its datasheet
It has a programmable capacitor input to adjust AC voltage sensing level and time delay

http://search.digikey.com/script...