I am creating a circuit for an automotive application which will take 3 buttons from the stalk as 3 inputs. Now I have measured these buttons and they are active low and output a constant 12v (ish) when not pressed.

I am using an STM32F4 MCU to read the button presses and I realise that I need to drop the voltage of the buttons to 5V max prior to the digital IO pins of the MCU. After looking online I came across the idea of using an opto-isolator and because of PCB constraints I wish to use one which comes ready made in a SOIC package with 3/4 channels.

Now I see there are many available and so far I have determined I will use a transistor based one as it is a good middle ground and I don't need to deal with fast switching.

But I am confused as to how to choose one exactly as there are so many available. My requirements are:

  1. relatively low cost (up to £2)
  2. SOIC package
  3. triple/quad channel
  4. suitable for automotive voltages, 12V (possibly fluctuating a bit)

I am considering using the Toshiba TLP290-4 opto-isolator, which has a min CTR of 50%.

So by following the advice here: https://electronics.stackexchange.com/a/43502/148565

And considering the schematic (Just the forward voltage scenario, if I am not mistaken, this opto-isolator can handle reverse also):


simulate this circuit – Schematic created using CircuitLab

I calculate that given a 10mA input current through R1 and D1, and the given 1.2V typical drop across D1 according to the datasheet, then R1 = VR1 / I = 1.08kΩ, so 1.2kΩ should do.

Then given the minimum CTR of 50%, at a 10mA input current, the output current would be 5mA. Therefore, assuming the 3.3V dropped across R2, R2 = VR2 / I = 330Ω.

So the question is, are my calculations correct and will the proposed circuit be safe for use under these conditions?

And as an aside, how would I go about inverting the output in terms of the switching, Do I just tie R2 to GND instead of 3.3V?

  • 1
    \$\begingroup\$ As it stands, you're asking a "shopping" question, which isn't allowed. If you edit your question to just ask about parameters to look for instead, then it will be ok. \$\endgroup\$
    – DoxyLover
    Commented May 8, 2017 at 19:53
  • 1
    \$\begingroup\$ You need to bear in mind that 12V in an automotive environment is nearer to 14V under normal running, and may spike much higher. That applies to driving the opto diode as well as supplying your 3.3V regulator. \$\endgroup\$
    – Finbarr
    Commented May 8, 2017 at 20:42
  • \$\begingroup\$ As for inverting the output, why not just do it in your software? \$\endgroup\$
    – Finbarr
    Commented May 8, 2017 at 20:43
  • \$\begingroup\$ Thanks, well actually I measured 12v at the stalk switches with the engine running and so I wonder whether the voltage is already regulated somewhere in the circuit from the switches. But yes, I realise that if not the voltage can spike up to 15v when the alternator is running etc. As for the inversion, I can do it in software, (and I probably will) but I just wanted to confirm how to do it in hardware for my own knowledge really... \$\endgroup\$ Commented May 8, 2017 at 21:45
  • 1
    \$\begingroup\$ @JamesElder If for instance the driver switches to a low gear at high speed by mistake, the alternator running at 10000+ rpm will output much more that 15V. Do you want your device to survive common driving mistakes? \$\endgroup\$ Commented May 10, 2017 at 10:41

1 Answer 1


You need to start from the load you're trying to drive, then work backwards to what you need to take from the source, then adjust your results for the min/max limits of any of your components.

You don't specify your particular STM32F4 microcontroller (MCU), nor the maximum current you can take from your 12 V.

The load on your circuit is the input leakage current of an I/O pin when configured as an input. You need to find this in your MCU data sheet. A typical figure for these devices is +/- 1 uA. Your inputs need 0.7 x Vdd to Vdd to detect a logic high and GND to 0.3 x Vdd to detect logic low, again typical figures and being 0..1 V for a good low and 2.3..3.3 V for a good high.

You must also allow for the leakage current down the photo-transistor in your TLP290-4 opto-isolator when it's off, which you will find in the datasheet to be 0.1 uA max.

So your pull-up resistor can afford to drop 1 V across itself with 1.1 uA flowing through it and still be detected as logic high. That's about 909 K but with no margin for error and little resilience to noise.

Your Infra-Red LED (IRLED) has a transfer ratio of 50 % worst-case. Your datasheet also specifies the IRLED current, IF, with figures from 100 uA up in the graphs and example figures of 1 mA up in the tables for output saturated, with the max being 50 mA. In a noisy environment such as a car, you should draw a good-sized current from your signal source to be confident it is not triggered by noise. You had accepted 10 mA. Let's use 5 mA. This will drive the IRLED strongly but not hard. Transient overvoltages on your detection input can be almost 10x the normal 12 V before it'll get anywhere near the 50 mA max. so it's a well-protected input circuit.

So the IRLED series resistor is: (12 - 1.2) / 0.005 = 2160 (use 2K2)

With 5 mA through the IRLED, the photo-transistor Ice(max) can be taken as 2.5 mA. So the acceptable current range through the pull-up resistor is 1.1 uA to 2500 uA.

A 10 K resistor draws: (3.3 - 0.4) / 10000 = 290 uA

This is a good choice: a strong pull-up but still only 10%-odd of the maximum.

You can therefore also use the programmable internal pull-up resistors in your MCU, which the datasheet will tell you are equivalent to 30..50 K or 7..14 K.

In your calculations, you found the IRLED current stated as 10 mA in one place, worked out the current transfer ratio then tried to draw the maximum current you could from the output, rather than the current you need.

The other thing you need to observe is that the maximum reverse voltage that the IRLED in an opto-isolator can take is very often tiny by diode standards, something like -2..3 V being common. You would therefore need a diode connected across the IRLED that conducts when the IRLED is reverse-biased to protect it. The TLP290-4 has these built in so there is no need for an external diode.


simulate this circuit – Schematic created using CircuitLab

So: use R1 = 2K2 for 5 mA IRLED current and R2 = 10K and you'll be fine with your microcontroller input pins.

You can invert the active state of the signal in your software for free, as well as get the pull-up resistors in your software for free.

  • \$\begingroup\$ Is there a reason you are suggesting 5mA IRLED current rather than 10mA? The datasheet suggests 10mA current through the diode in their test conditions, which gives rise to a 1.2V typical drop across the diode. I'm also intrigued as to how you came about the value of 10K for R2? \$\endgroup\$ Commented May 8, 2017 at 21:28
  • \$\begingroup\$ This is a great answer and I follow it fully. After consulting the datasheet of my STM32F413ZH MCU, I can confirm the leakage current is +/-1uA and the pull up resistor range is 30-50K. Also the maximum current I can draw is very large as it is only drawn when the engine is on so there are no worries there. Thanks! \$\endgroup\$ Commented May 9, 2017 at 9:13
  • \$\begingroup\$ You're welcome @JamesElder and good luck with it :-) \$\endgroup\$
    – TonyM
    Commented May 12, 2017 at 6:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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