I sometimes do electronics projects as a hobby and as far as I know if you want to switch something in a circuit electronically, transistors are the way to go. And I have used them successfully before to control high current loads such as LEDs or DC motors with a micro-controller.
But what I'm trying to do now is to turn a TTL serial connection on and off. As if I was physically disconnecting the
TX wire from my micro-controller's
RX pin. And I have realized that every tutorial I've ever read about using transistors as switches (this one for example) assume that you are using the transistor to turn a load on or off.
My though process behind this is: A transistor connects the Collector to the Emitter when it is saturated, so when I "turn on" the transistor,
TX should get connected to
RX. And it actually works!
When nothing is connected to the base my micro doesn't receive anything. When I connect 5V to the base the micro starts receiving serial data. I'm outputting this data to a serial console and it's valid, non-gibberish data.
But having learnt from previous experiences, after achieving this I started searching the Internet to see if this is the proper way to do it. But I couldn't find anything about how to switch a signal/data line on and off. As I mentioned, they are all about switching loads using
PNP transistors to connect to
What I want is something that acts exactly like a physical switch, that I can put anywhere in the middle of my wire and connect/disconnect it. Which my circuit seems to be achieving.
So am I doing it right or am I just getting lucky?
I have a feeling that I'm just getting lucky.