Can you supply AC voltage to a digital input pin?

jremington:
The relevant issue is the LED forward current of 100 mA max. You need a current limiting resistor in series with the input.

1K, 1/2W should work for 6-20VAC.

Please pardon my ignorance, but when you say 1K, 1/2W which datasheet specifications are you referring to?

Use a one thousand Ohm, one half Watt power rated resistor in series with the input LEDs on the H11AA1 AC optocoupler, in order to limit the input current to less than 100 mA root mean square, as per H11AA1 data sheet specifications.

edhalsim,
Thank you for answering my questions. I think you have perfectly good answers now from other people, so I will leave you with those.

I really don't understand this.

I didn't think you would... it needs a diagram to explain properly. Perhaps later if I am in the mood.

jremington:
Use a one thousand Ohm, one half Watt power rated resistor in series with the input LEDs on the H11AA1 AC optocoupler, in order to limit the input current to less than 100 mA root mean square, as per H11AA1 data sheet specifications.

Here's my confusion. The circuit without the AC optocoupler will have 280mA running through it (see attached). If I insert the H11AA1 along with a 1KOhm resister, that will drop the current to the point that the six 6V .15A lamps in the circuit won't light. Where should I put the resistor? Thanks.

PerryBebbington:
edhalsim,
I really don't understand this. I didn't think you would... it needs a diagram to explain properly. Perhaps later if I am in the mood.

Does that explain it better? I think you thought you could ground both the AC and the DC side of a bridge rectifier, you can't. One side can be grounded, the other side must not be.

Where should I put the resistor?

If you wish to detect whether the lamps are powered, the optocoupler (with input resistor) should be in parallel with the lamps, not in series.

opto.png

opto.png

jremington:
If you wish to detect whether the lamps are powered, the optocoupler (with input resistor) should be in parallel with the lamps, not in series.

opto.png

I hooked it as you described above parallel to the lights. I have the pins on the H11AA1 hooked up as follows:
1 & 2 - AC input
3 - Nothing
4 (E) - GND on the Arduino
5 (C) - Input pin 12 on the Arduino
6 - Nothing

I'm still getting nothing on the input pin whether there's current going through the lamps or not.

  1. Do I need to add a 10K pull-up resistor to pin 5 and connect it to 5V? I've seen other examples that do this (doesn't seem to make any difference though).
  2. Is there a way to determine if I'm getting any voltage passed through the chip, like maybe trying to measure voltage across pins 4 & 5?

Thanks again for your help I really appreciated your patience.

edhalsim:
I'm still getting nothing on the input pin whether there's current going through the lamps or not.

Do I need to add a 10K pull-up resistor to pin 5 and connect it to 5V?

Must use pull up with an opto coupler, but no external resistors are needed.
The Mega has internal pull up. You must enable that in setup, with pinMode.

pinMode(optoPin, INPUT_PULLUP);

Remember that you have to bridge the missing half of the sinewave in software.
Leo..

Remember that you have to bridge the missing half of the sinewave in software.

Leo, edhalsim,
I've looked at the data sheet for the H11AA1 and see it has 2 LEDs connected in inverse parallel, so, you don't need the external diode you have shown in your schematic and you should see both half cycles at the input to the Arduino. However, I would still expect there to be a brief period between each half cycle when the input was high*, you will have to cover this in software.

*Have you realised that input low means lights on?

Oops, I only saw the 4N26 below the part.
Yes, diode is not needed for an AC opto coupler.
Easier to bridge zero-crossings (shorter) in software too.
A hardware solution, with cap from pin to ground, might be easier.
Leo..