1
\$\begingroup\$

I bought a couple of phototransistors. They all have one lead shorter than the other. I assume that, like normal diodes, this means that the longer lead goes to V+ and the short end goes to GND.

I set the phototransistor up like so:

Pull Down Circuit

I put the output line into my interrupt pin on my microcontroller. When I shine a bright light on the phototransistor, the microcontroller doesn't interrupt.

BUT!!

When I put the same output into my ADC my microcontroller says it reads 5V with the light shining on the phototransistor. It also reads 0.8V when the phototransistor is covered.

Why would a multimeter and ADC read the output as Low/High but it won't trigger an interrupt on my microcontroller. (I know the problem isn't the code because I can take a straight wire from 3.3V to the interrupt pin and it will interrupt.)

EDIT

The logic level is 5V. I put the output pin to a green LED which then goes to ground. When I shine the light on the phototransistor, the green LED lights up. So I'm confident I have enough current.

I want it to trigger when light shines on it and pulls the pin high.

SOLUTION

I had two problems here that combined into a really annoying problem. The first problem was the one stated above. The other problem was that there wasn't enough current flow. I solved both problems by stacking four phototransistors in parallel in a pullup configurations and reversing the leads.

Thanks to Nedd for the suggestion to switch from pulldown to pullup. That made them much more sensitive. I also realized I had my phototransistors pointing the wrong direction.

For this reason I've marked Nedd's answer as the most correct.

I know my solution is not ideal. It's pretty hackish, which is why I didn't answer my own question and mark it as correct. In the future I will probably opt for a different solution, such as the TI OPT-101.

\$\endgroup\$
  • \$\begingroup\$ 0.8v is on the borderline of what is typically considered a reliable zero, so try using a smaller resistor. It is also possible that an edge-triggered interrupt (you failed to specify the type) may need a true edge, and not a gradual transition, so you might try using a comparator. Some microcontrollers such as the ATmega series have an optionally enabled built in comparator on certain pin(s) for triggering an interrupt (or automatic timer start/stop/capture) on an analog condition. \$\endgroup\$ – Chris Stratton Nov 21 '15 at 3:17
  • \$\begingroup\$ Strangely enough I found a weird solution. I pulled the output line into the gate of a transistor that carries 3V3 to the interrupt pin. When I shine the light on phototransistor it biases this other transistor and triggers the interrupt. So, while it works, it seems like the phototransistor is pretty crappy. \$\endgroup\$ – toshiomagic Nov 21 '15 at 4:23
  • 1
    \$\begingroup\$ Its because the phototransistor was raised right and is too polite to interrupt the microcontroller. \$\endgroup\$ – kingchris Nov 21 '15 at 5:10
  • \$\begingroup\$ I am also concerned about "When I shine the light it goes to 5V" and "When I take a line from the 3V3", while apparently it hasn't damaged your controller yet, you can't just blonk 5V onto any pin of a 3V3 device and expect it to survive. Other than that, seriously, just half your Re, the value of which is not specified, would have possibly helped. \$\endgroup\$ – Asmyldof Nov 21 '15 at 7:57
  • \$\begingroup\$ Oh, sorry, I did use a resistor to protect the pin :) \$\endgroup\$ – toshiomagic Nov 21 '15 at 14:53
0
\$\begingroup\$

The residual 0.8v shows that the photo transistor has current leakage even when dark. Using a lower value Re may help. Better yet, reverse the positions of the resistor and photo transistor, then detect a low going signal when shining the light, (a higher value resistor could be used in this case)..

\$\endgroup\$
  • \$\begingroup\$ I want my device to sleep when there is no light. Won't the pullup configuration drain more current than the pull down configuration? \$\endgroup\$ – toshiomagic Nov 21 '15 at 14:52
  • \$\begingroup\$ It will draw the same amount of current, all other things being equal. If you want low power consumption, power it from a port pin rather than the supply voltage and put the micro to sleep between measurements. Wake up and make a quick test (should settle within some tens of microseconds maximum) then go back to sleep for a while. \$\endgroup\$ – Spehro Pefhany Nov 22 '15 at 1:54
1
\$\begingroup\$

Short answer, the 0.8v is probably not low enough to count as "low" logic level. The specification for this (Vil) is explained in the microcontroller datasheet.

As an easy solution, add a schmitt-trigger input device, such as a 7414 gate between the phototransistor and interrupt input. This will ensure the microcontroller sees only Vdd or Vss, and it provides some hysteresis.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.