First of all: I read through some of the suggested topics (i.e. connecting a 5V relay to an ESP), but to my (limited) understanding, this seems not to be the problem I'm trying to solve. If it is, please accept my apologies.
What I'm trying to do: I want to emulate an Atari-style joystick (which runs on 5V) with an ESP32 (3.3V). To do that, the direction pins of the joystick port need to be connected to the GND pin.
First I was thinking of using optocouplers because they provide galvanic isolation. However, since the ESP will be powered by the joystick port's 5V pin eventually, this might not be really necessary. So I thought about using transistors and supply the base of the transistor with the current from one of the ESP's GPIO. Collector and emitter would then be connected to GND and the respective direction pin of the joystick port.
Would that work as well and as reliable/fast as an optocoupler? I read about leakage current that can occur on transistors even if the GPIO connected to the transistor's base is off? And could I use BC547 (NPN) transistors for that purpose, as I have lots of them laying around here? Or would a different type be better? And last question: In some of the examples using a transistor as a switch, I saw that GND would be connected to the collector and the load to the emitter. I thought that current flows from the collector to the emitter via the base, so I would have expected GND to be connected to the collector?
Thanks in advance for any suggestions/explanations!