# Calculating resistor values for RPi circuit detecting AC current using H11AA1 and PNP transistor

I've got an electronic doorbell system (Aiphone IE-1AD) that sends a ~15Vac signal when the button is pushed.

I used this blog post on detecting a signal on a similar door bell using a moteino (arduino) to create this wiring schematic for the raspberry pi. Question 1: I think I need to make the circuit run using the 3.3v in my diagram rather than the 5v from the blog post - correct?

The moteino uses a 5v power for the circuit, but I think I need to change it to 3.3v. When the optocoupler (H11aa1) is closed (connected), I understand the input voltage to be then sent to the GPIO pin (either directly, or via the capacitor). Because the Pi GPIO pin expects a 3.3v (whereas the moteino could handle 5.5v), I want to be using 3.3v to run the circuit.

Question 2: if I'm using 3.3v, what resistor values?

I'm not sure how to go about figuring out the resistor values. The LED has a voltage drop of 2v and a runs well on about 10-15ma, but how do I handle the capacitor in parallel?

From this youtube at about 3 min in, it looks like the PNP has a .7v drop from B to E, but do I need a resistor between the optocoupler and B as the video would suggest?

Question 3: An extra resistor?

It looks like there's a pathway, when the optocoupler is closed and the transistor is allowing current from E to C, that directly connects the 3.3v source to the GPIO pin without a resistor on the route (via the transistor) - is that a problem? Wouldn't it cause too much current to the GPIO pin? What resistor and where would address it?

I'm as interested in the why behind the answer as I am in what to do make this work

## 1 Answer

The LED has a voltage drop of 2v and a runs well on about 10-15ma, but how do I handle the capacitor in parallel?

The capacitor won't have any effect on the LED current after the circuit has been "on" for a few microseconds, so you don't need to worry about it when calculating the resistor value.

do I need a resistor between the optocoupler and B as the video would suggest?

You don't need a resistor.

You don't need to limit current through the optocoupler --- it won't draw any more current than what's stimulated as photocurrent by its LED (driven by the 15 V AC)

You aren't using the signal at the optocoupler's 'C' pin as a logic signal, so you don't need it to pull to a low voltage when the opto is active.

A current path into the 'B' pin could speed up the operation of the phototransistor, but for this kind of application, you don't need nanosecond response times.

It looks like there's a pathway, when the optocoupler is closed and the transistor is allowing current from E to C, that directly connects the 3.3v source to the GPIO pin without a resistor on the route (via the transistor) - is that a problem? Wouldn't it cause too much current to the GPIO pin?

Assuming you have the GPIO configured as an input (and this should be the power-up default), it will have a high input impedance, and won't allow more than a few microamps to flow into it.

A few k-ohm resistor would likely not change the behavior any and would protect you from overcurrent in the event you accidentally program the GPIO as an output and the driven value conflicts with the value generated by this doorbell circuit.