Need help hooking up an H11AA1 optocoupler to detect current in an AC circuit.

Thread Starter

Ed. M.

Joined Nov 8, 2017
41
Hi,

I have an AC circuit shown below. The six resistors in parallel are 6.25V, 0.15A #47 lamps which light up when the switch is closed.
Voltage is 17V AC.

Circuit.PNG

I want to detect when there's current flowing through the circuit. To that end, I'm trying to use an H11AA1 optocoupler (Pr1) hooked up as follows:
1 & 2 - AC (Pin 1 is attached to the 1000 Ohm resistor
3 - Nothing
4 - GND
5 - Output
6 - Nothing

The GND and Output pins I have hooked to an Arduino GND and INPUT pin. I'm then monitoring the input pin on the Arduino and it's always zero, regardless of whether or not the switch is closed. I've looked around the web for help, but haven't found anything.
  1. Do I have things hooked up correctly?
  2. Any ideas what I'm missing?
  3. Is my 1000 Ohm resistor "correct"? I think the input current max on the H11AA1 is 15mA so 1000 Ohm may not be enough.
  4. Do any of the circuit simulators (QUCS, PartSim) have an optocoupler in their library so I can verify this via simulation?
I really appreciate your time.
- Ed.
 

JohnInTX

Joined Jun 26, 2012
4,787
Do you have a pullup resistor on the opto's output collector?
Note that with AC, the H11AA1 output will be low for both half-cycles except for a short time during zero crossing. You can filter that out with a capacitor or in firmware.

1K is too small. Consider 10K or more to keep the LED current well under the 60ma absolute maximum rating. Your collector resistor should take into account the 20% CTR. 10K-22K should do it.
 

Attachments

Last edited:

Thread Starter

Ed. M.

Joined Nov 8, 2017
41
Thanks for your reply.

Do you have a pullup resistor on the opto's output collector?
Yes. I have a 10KOhm resistor on pin 5 tied to 5V on the Arduino.
Note that with AC, the H11AA1 output will be low for both half-cycles except for a short time during zero crossing. You can filter that out with a capacitor or in firmware.
I'm sorry I'm not following you. The internal LED should be lit during both half cycles and I should get DC voltage out regardless of the cycle. If this isn't correct, can you please clarify and let me know what type/size of capacitor to use and how to hook it up?
1K is too small. Consider 10K or more to keep the LED current well under the 60ma absolute maximum rating. Your collector resistor should take into account the 20% CTR. 10K-22K should do it.
I changed the resistor to 10K on the AC input (pin 1). That should give me 1.7mA on the input. Do I also need one for pin 2 since it's alternating input?
 

Reloadron

Joined Jan 15, 2015
7,501
Maybe I am missing something here but you show three #47 lamps in series and three more in parallel with the first three. A #47 lamp is a 6.3 Volt 150 mA (0.150 Amp) lamp when running at it's rated voltage of 6.3 volts. That would be 6.3 * 3 = 18.9 volts applied before the lamps draw their rated current but with 17 volts applied the total current will drop below 0.150 Amps per string or a total current 0.300 amps. If a single lamp in either string fails (opens) the current for the string will drop to zero.

You mention you want to detect current? As drawn that is not going to happen. Anytime the switch is closed the optocoupler which is Pr1 I assume will be on. I do not see anything to detect current in either string of three lamps? What am I missing in all of this?
I want to detect when there's current flowing through the circuit. To that end, I'm trying to use an H11AA1 optocoupler (Pr1) hooked up as follows:
As to an opto coupler there are opto couplers designed for use with AC current but I just do not see where as drawn you are detecting current in the circuit.


Ron
 

dendad

Joined Feb 20, 2016
4,451
The above should not have a "LIVE_230V" connection, but be connected to the 17VAC. That is a lot safer.
But Ed.M, do you want to detect current in your circuit? As it is, you are detecting when there is voltage. But not the lamp current. If the lamps blow, you are still getting a "good" reading.

EDIT: You beat me to the current question Reloadron ;)
 

Thread Starter

Ed. M.

Joined Nov 8, 2017
41
Thanks for the reply. I changes the input resistor (R1) to 10K and the output one (R8) to 1.2K and now I'm getting signal on the Arduino, although it's backwards from what I expected (1 if switch is open, 0 if closed).

Maybe I am missing something here but you show three #47 lamps in series and three more in parallel with the first three. A #47 lamp is a 6.3 Volt 150 mA (0.150 Amp) lamp when running at it's rated voltage of 6.3 volts. That would be 6.3 * 3 = 18.9 volts applied before the lamps draw their rated current but with 17 volts applied the total current will drop below 0.150 Amps per string or a total current 0.300 amps. If a single lamp in either string fails (opens) the current for the string will drop to zero.
Correct. If one of the three lamps in series blows the others will go out as well. That's just the way this machine I'm trying to interface with is designed (I can't change that). I said 17VAC but it's probably close to 18VAC so the lamps do get close to the desired brightness.

You mention you want to detect current? As drawn that is not going to happen. Anytime the switch is closed the optocoupler which is Pr1 I assume will be on. I do not see anything to detect current in either string of three lamps? What am I missing in all of this?


As to an opto coupler there are opto couplers designed for use with AC current but I just do not see where as drawn you are detecting current in the circuit.
Ron
Do I want to detect current or voltage? I hadn't thought of that (I'm still new to this). I basically want to test if the switch is closed or not. When the switch is open, I'd like the Arduino to get a LOW and closed to get a HIGH. If a lamp is burned out/dead, but the switch is closed, I still want that to be a HIGH. I had some other folks suggest the optocoupler approach would be best so that's what I bought.
 

dendad

Joined Feb 20, 2016
4,451
The sense of the input to the Arduino should not matter as it is just a software change to invert it.
But you could connect the Arduino input to ground via a 1K resistor, and hook the opto output... Collector to +5V, Emitter to Arduino input.
 

Reloadron

Joined Jan 15, 2015
7,501
OK, so the object is just knowing if the switch is open or closed so you really only want to know if a voltage is present. Yeah, any number of opto couplers will work. Here is what is going on and why things seem backwards. The optocoupler has a NPN open collector output as can be seen in the data sheet. You apply an input through a resistor to limit the current to pins 1&2 which turns the opto on.The internal transistor turns on. This places the collector at about ground potential or zero volts. When the switch is open or off the transistor in the opto turns off and your pull up resistor on pin 5 the open collector output will pull pin 5 high.

Since you mentioned you are running this signal into an Arduino you work the code accordingly. That is one option and simple to do. Another option is to take the pin 5 out and drive a simple transistor acting as a switch. What that does is invert the output of the optocoupler. Either way will work. I would just modify the Arduino code. If you post that code about anyone here can show you the changes.

Ron
 

Reloadron

Joined Jan 15, 2015
7,501
The sense of the input to the Arduino should not matter as it is just a software change to invert it.
But you could connect the Arduino input to ground via a 1K resistor, and hook the opto output... Collector to +5V, Emitter to Arduino input.
This time you beat me to it. :)

Ron
 

JohnInTX

Joined Jun 26, 2012
4,787
1K is too small. Consider 10K or more to keep the LED current well under the 60ma absolute maximum rating. Your collector resistor should take into account the 20% CTR. 10K-22K should do it.
I whiffed that. I was thinking 120VAC input. For 17VAC, the 1K for the LED input is fine. Sorry.


The other posters are spot on. It doesn't matter what the logic level is for ON/OFF, just adjust the software accordingly.
The opto is a good solution as it separates the AC levels from the Arduino.
@Dodgydave in #4 is the circuit I had in mind when I goofed up. That circuit will detect the voltage across the loads at PR1 and indicate when the switch is closed, just use the 17 VAC though.
 

Phil-S

Joined Dec 4, 2015
238
Try the HCPL3760 (Allegro and others) instead. Has everything built into DIP-8 package.
Just requires external resistors to set thresholds and hysteresis, plus a capacitor for filtering.
The chip of my choice
 

eetech00

Joined Jun 8, 2013
3,856
(Hopefully last) Question: Do I need a 1K input resistor on BOTH pins 1 and 2 since I have an AC input or just pin 1? Why?
Hi

Sometimes, when used with mains voltage levels, the resistor value is divided in half and then two separate resistors are used, one in each side of the input LED diode, so that lower wattage resistors can be used.

eT
 

Thread Starter

Ed. M.

Joined Nov 8, 2017
41
I'm seeing some odd behavior. I have 17VAC on the input pins with a 1.2KOhm resistor on input 2, but I'm not seeing any DC voltage on pins 4 & 5. I have pin 5 going in to my Arduino with the pin configured as INPUT_PULLUP, but I'm not seeing it change state either. Any ideas what I may be doing wrong? Thanks.
 

dendad

Joined Feb 20, 2016
4,451
The Opto LED is probably on most of the time with 17VAC input, so turning the output transistor on.
There will maybe just a short time when the transistor is off, so the voltage will be close to zero, and if you have a capacitor on the output, it will measure even less.
If you disconnect the 17VAC, does the Arduino input go high?
Do you have an oscilloscope to look at the output?
 

Thread Starter

Ed. M.

Joined Nov 8, 2017
41
The Opto LED is probably on most of the time with 17VAC input, so turning the output transistor on.
There will maybe just a short time when the transistor is off, so the voltage will be close to zero, and if you have a capacitor on the output, it will measure even less.
If you disconnect the 17VAC, does the Arduino input go high?
Do you have an oscilloscope to look at the output?
Yes, the Arduino input always shows high, whether there's power or not (it never goes to zero).
No, I don't have an oscilloscope.
I don't have a capacitor on the output; I'm connecting pin 5 of the chip directly to my Arduino input and pin 4 to the Arduino ground.
 

dendad

Joined Feb 20, 2016
4,451
It sounds like the opto is dead.
The Arduino input should be low most of the time.
Disconnect the Arduino and add an LED with a series 470R resistor to 5V and see if you can light the LED. This is just in case the Arduino is playing up.
Test each part one at a time.
 

eetech00

Joined Jun 8, 2013
3,856
Yes, the Arduino input always shows high, whether there's power or not (it never goes to zero).
No, I don't have an oscilloscope.
I don't have a capacitor on the output; I'm connecting pin 5 of the chip directly to my Arduino input and pin 4 to the Arduino ground.
Hi

Connect the opto like shown in post #4. The cap smooths the output so it will appear a continuos input voltage to the ardruino. The ardruino input should be connected to the junction of the PU resistor and collector of the BJT. When AC is flowing at the input, the BJT is turned on and the output will be low.

eT
 
Top