Author Topic: Transistors/mosfets to replace manual switches?  (Read 822 times)

0 Members and 1 Guest are viewing this topic.

Offline multiplyduckTopic starter

  • Newbie
  • Posts: 3
  • Country: dk
Transistors/mosfets to replace manual switches?
« on: June 25, 2021, 06:48:55 pm »
I am trying to build some logic into an old-style game controller.
The controller normally works simply by a series of manual switches letting its respective pin be grounded or in open circuit.



What I aim to do is replace the manual switches with output from an arduino. However, I realize I cannot just connect each signal pin to an arduino digital pin, so my first thought was using transistors or mosfets. I read that transistors might introduce a significant voltage drop, so perhaps small mosfets, such as BS170, would make sense? Am I thinking along the right lines?

If I had to use relays I wouldn't really be in doubt on how to hook it up since they basically just open or close the circuit like switches, but it isn't obvious to me how I would connect mosfets to act in the same way. Looking at examples of how to use mosfets, I suppose I would connect the gate to an arduino output pin (with a 10K resister to ground in between?), but the other pins? The mosfet examples I find are mainly concerned about driving a load (LED, etc), whereas what I want to do is connect something to ground.

Maybe I am needlessly confusing myself? Or maybe mosfets are not obvious way to go?
 

Offline Peabody

  • Super Contributor
  • ***
  • Posts: 2141
  • Country: us
Re: Transistors/mosfets to replace manual switches?
« Reply #1 on: June 25, 2021, 07:16:23 pm »
The BS170 is the right kind of mosfet (N-channel) for a low-side switch, and might work just fine.  But do you know how much current flows to ground when one of the manual switches is closed?
 
The following users thanked this post: multiplyduck

Online SmokedComponent

  • Regular Contributor
  • *
  • Posts: 60
  • Country: si
  • Emitting smoke
Re: Transistors/mosfets to replace manual switches?
« Reply #2 on: June 25, 2021, 07:30:38 pm »
Since both the Arduino and the game controller are powered from the same 5V rail, you could just skip the transistors altogether and directly use outputs of the MCU in (almost) open-drain mode - by switching the IO pins between input and output mode (default low) instead of leaving them in output mode and switching between high/low.
Just check that the current flowing into ground from the controller's buttons isn't to high (it shouldn't be, they're probably using few K pull-ups)
« Last Edit: June 25, 2021, 07:32:15 pm by SmokedComponent »
 
The following users thanked this post: Manul, multiplyduck

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1158
  • Country: lt
Re: Transistors/mosfets to replace manual switches?
« Reply #3 on: June 25, 2021, 07:31:36 pm »
However, I realize I cannot just connect each signal pin to an arduino digital pin, so my first thought was using transistors or mosfets.

You can directly connect to Arduino if both circuits are working at same logic level. I assume you use Arduino UNO which is 5V. What is voltage at game controller buttons?

P.S. There will be a problem if you use physical buttons at the same time as Arduino control (assuming direct connection). This can be soved by software (emulate open drain by changing pin between input and output LOW), or hardware (emulate open drain by using series diode, or just add current limitting resistor).
 
The following users thanked this post: multiplyduck

Offline multiplyduckTopic starter

  • Newbie
  • Posts: 3
  • Country: dk
Re: Transistors/mosfets to replace manual switches?
« Reply #4 on: June 26, 2021, 12:31:44 pm »
Thank you everyone for your replies!

Oh, so I CAN just connect to an arduino pin directly. Clever trick with switching the pins between input and output low. Would anything happen if I accidentally set a pin as output high?

All of you ask about either voltage or current: I measure just below 5V on the controller switches, but I am not able to measure any current flowing through when I bridge a switch with my multimeter in amp mode.
 

Offline Faringdon

  • Super Contributor
  • ***
  • !
  • Posts: 2124
  • Country: gb
Re: Transistors/mosfets to replace manual switches?
« Reply #5 on: June 26, 2021, 01:11:36 pm »
Quote
Would anything happen if I accidentally set a pin as output high?
Then you get current through the pin of 5V/ [pin resistance]...which wont be good, so put in a limiting resistor if you want.

Remember that when you set a  arduino pin to output, you are just making it the output of the internal transistor, which either turns the pin on to gnd, for low, .....to power for high, and to nothign for "High z".
'Perfection' is the enemy of 'perfectly satisfactory'
 
The following users thanked this post: multiplyduck

Offline Manul

  • Super Contributor
  • ***
  • Posts: 1158
  • Country: lt
Re: Transistors/mosfets to replace manual switches?
« Reply #6 on: June 26, 2021, 01:23:46 pm »
Would anything happen if I accidentally set a pin as output high?

If you do not use physical switches (for example, you remove them), then in this case it is not a problem and in fact you can just set Arduino pin HIGH and LOW.

BUT, there is yet another case to consider. Is both Arduino and game controller powered from same 5V source? If yes, then good. If no, then there is potential problem. You need to prevent one device feeding another through logic lines, if one is unpowered.
 
The following users thanked this post: multiplyduck

Offline multiplyduckTopic starter

  • Newbie
  • Posts: 3
  • Country: dk
Re: Transistors/mosfets to replace manual switches?
« Reply #7 on: June 26, 2021, 04:17:00 pm »
If you do not use physical switches (for example, you remove them), then in this case it is not a problem and in fact you can just set Arduino pin HIGH and LOW.

BUT, there is yet another case to consider. Is both Arduino and game controller powered from same 5V source? If yes, then good. If no, then there is potential problem. You need to prevent one device feeding another through logic lines, if one is unpowered.

I will be removing the physical switches (or rather, rewiring them to some input pins on the arduino, but that's another story).

So, the game controller itself by default is as simple as it gets; it consists of the manual switches alone, nothing else. The controller's connector, however, does provide a 5V rail (which by default is unused) which I plan to hook the arduino up to. I can't imagine this 5V rail being powered by a different source than the buttons, all of them coming from the same game console. Is there a way I can test that?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf