Electronic – Can a transistor be used to switch two loads with different voltages

transistors

For example I have a microcontroller running at 3.3v.

I want one GPIO pin to switch a 12v relay and a 5v load. Do I need to use multiple transistors? Or would something like this work?

schematic

simulate this circuit – Schematic created using CircuitLab

Best Answer

Yes, this will work if you change it slightly. Put a resistor and a diode (i.e. 1N4148) in series with the LED so it doesn't die from too much current or reverse voltage. Also put a free-wheeling diode across the relay to protect the transistor from voltage spikes.

schematic

simulate this circuit – Schematic created using CircuitLab

If your 5V load isn't a LED, you need at least the diode (D4) in series with it but not the resistor.