Switching a divided voltage with transistor or MOSFET

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
2
down vote

favorite
1












I have a problem that I cannot solve and need help.



I have an analogue input on a microcontroller and I want to have multiple switches which the micro can see and act on depending on which switch was pressed.
I have 5V that the circuit works on. So I am trying to get different voltages from 0-5 into the analog input of the micro.



The catch however is that I want to control it with a p type transistor or MOSFET so that the user can just short something to ground to activate the divided voltage. I've sat here for days trying to figure this out using MOSFETs and transistors but nothing I do works! The divided values are never correct!



I've been playing with BC327's and BS250 MOSFETs to try and make something work, but everything I try fails.



I realize I need help, so I'm throwing this out there on the chance someone can help me!



This is something I tried and failed.



Another failure.



Another failure.










share|improve this question























  • What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
    – The Photon
    Aug 31 at 1:12










  • I have 5v to work with and I've used BC327 P channel, BS250 P channel
    – Dean Hill
    Aug 31 at 1:20






  • 2




    BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
    – The Photon
    Aug 31 at 1:25










  • The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
    – Dean Hill
    Aug 31 at 1:32






  • 1




    Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
    – Avid Pro Tool
    Aug 31 at 1:48
















up vote
2
down vote

favorite
1












I have a problem that I cannot solve and need help.



I have an analogue input on a microcontroller and I want to have multiple switches which the micro can see and act on depending on which switch was pressed.
I have 5V that the circuit works on. So I am trying to get different voltages from 0-5 into the analog input of the micro.



The catch however is that I want to control it with a p type transistor or MOSFET so that the user can just short something to ground to activate the divided voltage. I've sat here for days trying to figure this out using MOSFETs and transistors but nothing I do works! The divided values are never correct!



I've been playing with BC327's and BS250 MOSFETs to try and make something work, but everything I try fails.



I realize I need help, so I'm throwing this out there on the chance someone can help me!



This is something I tried and failed.



Another failure.



Another failure.










share|improve this question























  • What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
    – The Photon
    Aug 31 at 1:12










  • I have 5v to work with and I've used BC327 P channel, BS250 P channel
    – Dean Hill
    Aug 31 at 1:20






  • 2




    BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
    – The Photon
    Aug 31 at 1:25










  • The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
    – Dean Hill
    Aug 31 at 1:32






  • 1




    Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
    – Avid Pro Tool
    Aug 31 at 1:48












up vote
2
down vote

favorite
1









up vote
2
down vote

favorite
1






1





I have a problem that I cannot solve and need help.



I have an analogue input on a microcontroller and I want to have multiple switches which the micro can see and act on depending on which switch was pressed.
I have 5V that the circuit works on. So I am trying to get different voltages from 0-5 into the analog input of the micro.



The catch however is that I want to control it with a p type transistor or MOSFET so that the user can just short something to ground to activate the divided voltage. I've sat here for days trying to figure this out using MOSFETs and transistors but nothing I do works! The divided values are never correct!



I've been playing with BC327's and BS250 MOSFETs to try and make something work, but everything I try fails.



I realize I need help, so I'm throwing this out there on the chance someone can help me!



This is something I tried and failed.



Another failure.



Another failure.










share|improve this question















I have a problem that I cannot solve and need help.



I have an analogue input on a microcontroller and I want to have multiple switches which the micro can see and act on depending on which switch was pressed.
I have 5V that the circuit works on. So I am trying to get different voltages from 0-5 into the analog input of the micro.



The catch however is that I want to control it with a p type transistor or MOSFET so that the user can just short something to ground to activate the divided voltage. I've sat here for days trying to figure this out using MOSFETs and transistors but nothing I do works! The divided values are never correct!



I've been playing with BC327's and BS250 MOSFETs to try and make something work, but everything I try fails.



I realize I need help, so I'm throwing this out there on the chance someone can help me!



This is something I tried and failed.



Another failure.



Another failure.







microcontroller transistors mosfet






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Aug 31 at 3:25









Michael Karas

41.6k34397




41.6k34397










asked Aug 31 at 1:09









Dean Hill

113




113











  • What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
    – The Photon
    Aug 31 at 1:12










  • I have 5v to work with and I've used BC327 P channel, BS250 P channel
    – Dean Hill
    Aug 31 at 1:20






  • 2




    BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
    – The Photon
    Aug 31 at 1:25










  • The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
    – Dean Hill
    Aug 31 at 1:32






  • 1




    Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
    – Avid Pro Tool
    Aug 31 at 1:48
















  • What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
    – The Photon
    Aug 31 at 1:12










  • I have 5v to work with and I've used BC327 P channel, BS250 P channel
    – Dean Hill
    Aug 31 at 1:20






  • 2




    BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
    – The Photon
    Aug 31 at 1:25










  • The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
    – Dean Hill
    Aug 31 at 1:32






  • 1




    Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
    – Avid Pro Tool
    Aug 31 at 1:48















What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
– The Photon
Aug 31 at 1:12




What MOSFET are you using (link to datasheet is best)? What supply voltage? (Please edit your question to include this information)
– The Photon
Aug 31 at 1:12












I have 5v to work with and I've used BC327 P channel, BS250 P channel
– Dean Hill
Aug 31 at 1:20




I have 5v to work with and I've used BC327 P channel, BS250 P channel
– Dean Hill
Aug 31 at 1:20




2




2




BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
– The Photon
Aug 31 at 1:25




BC327 is not a MOSFET it is a BJT. BS250 should work but has pretty high Rds(on) at -4.5 V --- what resistors are you using it with? At this point your best bet is share your whole circuit. Click on the schematic icon when editing your question to get to the built-in schematic editor.
– The Photon
Aug 31 at 1:25












The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
– Dean Hill
Aug 31 at 1:32




The first image shows what i tried with a mosfet... the second one was with a transistor... there were many many different attempts and I think there is something called transistor bias that I also tried and failed... I just cant seem to get the right voltages wehn I short the switch to negative
– Dean Hill
Aug 31 at 1:32




1




1




Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
– Avid Pro Tool
Aug 31 at 1:48




Why not just use a passive resistive divider and skip the transistor? You could have one resistor connected in series with the positive terminal of the battery/supply and a few different resistors hanging off connected to your buttons. Then depending on which button you press, a different voltage shows up where all the resistors meet.
– Avid Pro Tool
Aug 31 at 1:48










4 Answers
4






active

oldest

votes

















up vote
2
down vote













Your circuit won't work when the transistor base is sinking current to ground. Re-position your resistor and try again.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer




















  • how do I paste images?
    – Dean Hill
    Aug 31 at 6:28










  • i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
    – Dean Hill
    Aug 31 at 6:57










  • @DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
    – Avid Pro Tool
    Aug 31 at 7:56


















up vote
2
down vote













Below are two methods. The simulated voltage for the BJT circuit is 2.497V, for the MOSFET circuit 2.500V.



With 3 base/gate resistors increased from 10K to 100K (R7 to 10K), the values are 2.495 and 2.500V.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer






















  • my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
    – Dean Hill
    Aug 31 at 1:46










  • R4 value too high. Not me giving the -1. I just comment.
    – Jason Han
    Aug 31 at 1:50







  • 1




    Ha! If Spehro had a nickel for everyone he helped here he could retire :)
    – John D
    Aug 31 at 1:50






  • 1




    @JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
    – John D
    Aug 31 at 1:52







  • 1




    well thank you anyway you've saved me so much time
    – Dean Hill
    Aug 31 at 3:33

















up vote
2
down vote













There is no reason at all to use a transistor or MOSFET in a switch detection circuit like this. You can simply connect as follows:



enter image description here



This takes way less components and results in easy switch detection via the ADC reading. No switch pressed reads a nearly 5V value. S1 produces a voltage less than 2.5V, S2 produces a voltage of about 2.5V and S3 produces a voltage above 2.5V. Of course you are free to change the resistor values to suit your application. I just recommend keeping them in the Kohm range so that some input impedance at the ADC does not change the switched voltage dividers very much. Also keep in mind that when you detect each switch you need to check a range of the A/D readings for each to accommodate resistor tolerance and noise.



Edit: (in response to OPs query about long wires)



This should work fine with wiring to tact switches mounted on a circuit board. It can also work if the switches are wired remotely with wires but consider several things. First there can be noise on longer wires so make sure to select the resistors such that the voltage difference from switch to switch is much larger than the noise voltage. Also keep the impedance lower in Kohm range like I suggested. If you used Mohm range resistors the lines will be more susceptible to noise pickup.



With remotely mounted switches where wire may be very long or if there is concern with ESD then it would be advisable to not use this analog sorting for switch detection. Instead each switch should be dealt with in a digital manner. Digital treatment makes it more practical to:



  1. Provide ESD clamping on the signals at edge of circuit board.

  2. Buffer switch signals if necessary to protect sensitive MCU pins.

  3. Debounce switch signals with 1's and 0's instead of varying analogue values.

  4. Organize larger switch counts into a matrix to save GPIO pins.





share|improve this answer






















  • This is really clever, will it work if the user has long wires like if they add an external button ?
    – Dean Hill
    Aug 31 at 5:10










  • @DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
    – Avid Pro Tool
    Aug 31 at 7:53










  • The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
    – Dean Hill
    Sep 1 at 6:44

















up vote
0
down vote













Originally you said you wanted to use a PNP transistor and a few different buttons that short something to ground in order to produce an output of 0-5V to send into a single input of your microcontroller.



Here's one way to do that.





schematic





simulate this circuit – Schematic created using CircuitLab



[the values shown are just a rough example, you should play around with them and see what works best for your application]



If you push each button one at a time, the output will change according to the resistance connected. Adjusting your resistor values adjusts the output. (This won't always work if you're planning on hitting two buttons simultaneously though since that would put the resistors in parallel.)



Alternatively, you could put Ro on the collector and take your output there, but you won't be able to use as wide a range of resistor values at the base (not sure how many different values you need at the output), and in that case R1/R2/R3's value will vary inversely to the output. With the configuration shown, the output will increase with their resistance and the change will be slower (you can do a DC sweep to observe this).



Of course you could skip the transistor and Ro altogether and take your output directly from the resistive divider.






share|improve this answer




















  • This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
    – Dean Hill
    Aug 31 at 4:50











  • @DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
    – Avid Pro Tool
    Aug 31 at 5:12










  • @DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
    – Avid Pro Tool
    Aug 31 at 5:25










  • hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
    – Dean Hill
    Aug 31 at 5:52










  • The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
    – Dean Hill
    Aug 31 at 5:53










Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");

StackExchange.ifUsing("editor", function ()
return StackExchange.using("schematics", function ()
StackExchange.schematics.init();
);
, "cicuitlab");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "135"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f393624%2fswitching-a-divided-voltage-with-transistor-or-mosfet%23new-answer', 'question_page');

);

Post as a guest






























4 Answers
4






active

oldest

votes








4 Answers
4






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote













Your circuit won't work when the transistor base is sinking current to ground. Re-position your resistor and try again.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer




















  • how do I paste images?
    – Dean Hill
    Aug 31 at 6:28










  • i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
    – Dean Hill
    Aug 31 at 6:57










  • @DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
    – Avid Pro Tool
    Aug 31 at 7:56















up vote
2
down vote













Your circuit won't work when the transistor base is sinking current to ground. Re-position your resistor and try again.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer




















  • how do I paste images?
    – Dean Hill
    Aug 31 at 6:28










  • i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
    – Dean Hill
    Aug 31 at 6:57










  • @DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
    – Avid Pro Tool
    Aug 31 at 7:56













up vote
2
down vote










up vote
2
down vote









Your circuit won't work when the transistor base is sinking current to ground. Re-position your resistor and try again.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer












Your circuit won't work when the transistor base is sinking current to ground. Re-position your resistor and try again.





schematic





simulate this circuit – Schematic created using CircuitLab







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 31 at 1:48









Jason Han

1,527321




1,527321











  • how do I paste images?
    – Dean Hill
    Aug 31 at 6:28










  • i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
    – Dean Hill
    Aug 31 at 6:57










  • @DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
    – Avid Pro Tool
    Aug 31 at 7:56

















  • how do I paste images?
    – Dean Hill
    Aug 31 at 6:28










  • i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
    – Dean Hill
    Aug 31 at 6:57










  • @DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
    – Avid Pro Tool
    Aug 31 at 7:56
















how do I paste images?
– Dean Hill
Aug 31 at 6:28




how do I paste images?
– Dean Hill
Aug 31 at 6:28












i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
– Dean Hill
Aug 31 at 6:57




i cant get this circuit to work... no matter what i change the resistor divider to the voltage stays the sane
– Dean Hill
Aug 31 at 6:57












@DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
– Avid Pro Tool
Aug 31 at 7:56





@DeanHill if you do a DC sweep on this (sweeping R2 with the switch closed), you'll see that the output stays near 2.5V as you increase resistance until a certain point where it drops relatively quickly to 0. There's a small range of resistances between that will get you different values. This is what I mentioned in my answer about a slower change when you take your output from the emitter instead. That way you can use a wider range of resistances to control the output. Do a DC sweep in circuit lab, it will make it easier to see this effect.
– Avid Pro Tool
Aug 31 at 7:56













up vote
2
down vote













Below are two methods. The simulated voltage for the BJT circuit is 2.497V, for the MOSFET circuit 2.500V.



With 3 base/gate resistors increased from 10K to 100K (R7 to 10K), the values are 2.495 and 2.500V.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer






















  • my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
    – Dean Hill
    Aug 31 at 1:46










  • R4 value too high. Not me giving the -1. I just comment.
    – Jason Han
    Aug 31 at 1:50







  • 1




    Ha! If Spehro had a nickel for everyone he helped here he could retire :)
    – John D
    Aug 31 at 1:50






  • 1




    @JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
    – John D
    Aug 31 at 1:52







  • 1




    well thank you anyway you've saved me so much time
    – Dean Hill
    Aug 31 at 3:33














up vote
2
down vote













Below are two methods. The simulated voltage for the BJT circuit is 2.497V, for the MOSFET circuit 2.500V.



With 3 base/gate resistors increased from 10K to 100K (R7 to 10K), the values are 2.495 and 2.500V.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer






















  • my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
    – Dean Hill
    Aug 31 at 1:46










  • R4 value too high. Not me giving the -1. I just comment.
    – Jason Han
    Aug 31 at 1:50







  • 1




    Ha! If Spehro had a nickel for everyone he helped here he could retire :)
    – John D
    Aug 31 at 1:50






  • 1




    @JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
    – John D
    Aug 31 at 1:52







  • 1




    well thank you anyway you've saved me so much time
    – Dean Hill
    Aug 31 at 3:33












up vote
2
down vote










up vote
2
down vote









Below are two methods. The simulated voltage for the BJT circuit is 2.497V, for the MOSFET circuit 2.500V.



With 3 base/gate resistors increased from 10K to 100K (R7 to 10K), the values are 2.495 and 2.500V.





schematic





simulate this circuit – Schematic created using CircuitLab






share|improve this answer














Below are two methods. The simulated voltage for the BJT circuit is 2.497V, for the MOSFET circuit 2.500V.



With 3 base/gate resistors increased from 10K to 100K (R7 to 10K), the values are 2.495 and 2.500V.





schematic





simulate this circuit – Schematic created using CircuitLab







share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 31 at 2:50

























answered Aug 31 at 1:40









Spehro Pefhany

194k4139384




194k4139384











  • my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
    – Dean Hill
    Aug 31 at 1:46










  • R4 value too high. Not me giving the -1. I just comment.
    – Jason Han
    Aug 31 at 1:50







  • 1




    Ha! If Spehro had a nickel for everyone he helped here he could retire :)
    – John D
    Aug 31 at 1:50






  • 1




    @JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
    – John D
    Aug 31 at 1:52







  • 1




    well thank you anyway you've saved me so much time
    – Dean Hill
    Aug 31 at 3:33
















  • my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
    – Dean Hill
    Aug 31 at 1:46










  • R4 value too high. Not me giving the -1. I just comment.
    – Jason Han
    Aug 31 at 1:50







  • 1




    Ha! If Spehro had a nickel for everyone he helped here he could retire :)
    – John D
    Aug 31 at 1:50






  • 1




    @JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
    – John D
    Aug 31 at 1:52







  • 1




    well thank you anyway you've saved me so much time
    – Dean Hill
    Aug 31 at 3:33















my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
– Dean Hill
Aug 31 at 1:46




my god... i was so close... I missed the resistor divider to the transistor..and the mosfet... i think I can just duplicate one of these many times for the different switches. Can I pay you for your help dude?
– Dean Hill
Aug 31 at 1:46












R4 value too high. Not me giving the -1. I just comment.
– Jason Han
Aug 31 at 1:50





R4 value too high. Not me giving the -1. I just comment.
– Jason Han
Aug 31 at 1:50





1




1




Ha! If Spehro had a nickel for everyone he helped here he could retire :)
– John D
Aug 31 at 1:50




Ha! If Spehro had a nickel for everyone he helped here he could retire :)
– John D
Aug 31 at 1:50




1




1




@JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
– John D
Aug 31 at 1:52





@JasonHan what makes you say that? There should be about 4.3V across R4 for .43mA base current minus the .7V/10K from R3, plenty to saturate Q1 with 200K load on the collector.
– John D
Aug 31 at 1:52





1




1




well thank you anyway you've saved me so much time
– Dean Hill
Aug 31 at 3:33




well thank you anyway you've saved me so much time
– Dean Hill
Aug 31 at 3:33










up vote
2
down vote













There is no reason at all to use a transistor or MOSFET in a switch detection circuit like this. You can simply connect as follows:



enter image description here



This takes way less components and results in easy switch detection via the ADC reading. No switch pressed reads a nearly 5V value. S1 produces a voltage less than 2.5V, S2 produces a voltage of about 2.5V and S3 produces a voltage above 2.5V. Of course you are free to change the resistor values to suit your application. I just recommend keeping them in the Kohm range so that some input impedance at the ADC does not change the switched voltage dividers very much. Also keep in mind that when you detect each switch you need to check a range of the A/D readings for each to accommodate resistor tolerance and noise.



Edit: (in response to OPs query about long wires)



This should work fine with wiring to tact switches mounted on a circuit board. It can also work if the switches are wired remotely with wires but consider several things. First there can be noise on longer wires so make sure to select the resistors such that the voltage difference from switch to switch is much larger than the noise voltage. Also keep the impedance lower in Kohm range like I suggested. If you used Mohm range resistors the lines will be more susceptible to noise pickup.



With remotely mounted switches where wire may be very long or if there is concern with ESD then it would be advisable to not use this analog sorting for switch detection. Instead each switch should be dealt with in a digital manner. Digital treatment makes it more practical to:



  1. Provide ESD clamping on the signals at edge of circuit board.

  2. Buffer switch signals if necessary to protect sensitive MCU pins.

  3. Debounce switch signals with 1's and 0's instead of varying analogue values.

  4. Organize larger switch counts into a matrix to save GPIO pins.





share|improve this answer






















  • This is really clever, will it work if the user has long wires like if they add an external button ?
    – Dean Hill
    Aug 31 at 5:10










  • @DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
    – Avid Pro Tool
    Aug 31 at 7:53










  • The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
    – Dean Hill
    Sep 1 at 6:44














up vote
2
down vote













There is no reason at all to use a transistor or MOSFET in a switch detection circuit like this. You can simply connect as follows:



enter image description here



This takes way less components and results in easy switch detection via the ADC reading. No switch pressed reads a nearly 5V value. S1 produces a voltage less than 2.5V, S2 produces a voltage of about 2.5V and S3 produces a voltage above 2.5V. Of course you are free to change the resistor values to suit your application. I just recommend keeping them in the Kohm range so that some input impedance at the ADC does not change the switched voltage dividers very much. Also keep in mind that when you detect each switch you need to check a range of the A/D readings for each to accommodate resistor tolerance and noise.



Edit: (in response to OPs query about long wires)



This should work fine with wiring to tact switches mounted on a circuit board. It can also work if the switches are wired remotely with wires but consider several things. First there can be noise on longer wires so make sure to select the resistors such that the voltage difference from switch to switch is much larger than the noise voltage. Also keep the impedance lower in Kohm range like I suggested. If you used Mohm range resistors the lines will be more susceptible to noise pickup.



With remotely mounted switches where wire may be very long or if there is concern with ESD then it would be advisable to not use this analog sorting for switch detection. Instead each switch should be dealt with in a digital manner. Digital treatment makes it more practical to:



  1. Provide ESD clamping on the signals at edge of circuit board.

  2. Buffer switch signals if necessary to protect sensitive MCU pins.

  3. Debounce switch signals with 1's and 0's instead of varying analogue values.

  4. Organize larger switch counts into a matrix to save GPIO pins.





share|improve this answer






















  • This is really clever, will it work if the user has long wires like if they add an external button ?
    – Dean Hill
    Aug 31 at 5:10










  • @DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
    – Avid Pro Tool
    Aug 31 at 7:53










  • The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
    – Dean Hill
    Sep 1 at 6:44












up vote
2
down vote










up vote
2
down vote









There is no reason at all to use a transistor or MOSFET in a switch detection circuit like this. You can simply connect as follows:



enter image description here



This takes way less components and results in easy switch detection via the ADC reading. No switch pressed reads a nearly 5V value. S1 produces a voltage less than 2.5V, S2 produces a voltage of about 2.5V and S3 produces a voltage above 2.5V. Of course you are free to change the resistor values to suit your application. I just recommend keeping them in the Kohm range so that some input impedance at the ADC does not change the switched voltage dividers very much. Also keep in mind that when you detect each switch you need to check a range of the A/D readings for each to accommodate resistor tolerance and noise.



Edit: (in response to OPs query about long wires)



This should work fine with wiring to tact switches mounted on a circuit board. It can also work if the switches are wired remotely with wires but consider several things. First there can be noise on longer wires so make sure to select the resistors such that the voltage difference from switch to switch is much larger than the noise voltage. Also keep the impedance lower in Kohm range like I suggested. If you used Mohm range resistors the lines will be more susceptible to noise pickup.



With remotely mounted switches where wire may be very long or if there is concern with ESD then it would be advisable to not use this analog sorting for switch detection. Instead each switch should be dealt with in a digital manner. Digital treatment makes it more practical to:



  1. Provide ESD clamping on the signals at edge of circuit board.

  2. Buffer switch signals if necessary to protect sensitive MCU pins.

  3. Debounce switch signals with 1's and 0's instead of varying analogue values.

  4. Organize larger switch counts into a matrix to save GPIO pins.





share|improve this answer














There is no reason at all to use a transistor or MOSFET in a switch detection circuit like this. You can simply connect as follows:



enter image description here



This takes way less components and results in easy switch detection via the ADC reading. No switch pressed reads a nearly 5V value. S1 produces a voltage less than 2.5V, S2 produces a voltage of about 2.5V and S3 produces a voltage above 2.5V. Of course you are free to change the resistor values to suit your application. I just recommend keeping them in the Kohm range so that some input impedance at the ADC does not change the switched voltage dividers very much. Also keep in mind that when you detect each switch you need to check a range of the A/D readings for each to accommodate resistor tolerance and noise.



Edit: (in response to OPs query about long wires)



This should work fine with wiring to tact switches mounted on a circuit board. It can also work if the switches are wired remotely with wires but consider several things. First there can be noise on longer wires so make sure to select the resistors such that the voltage difference from switch to switch is much larger than the noise voltage. Also keep the impedance lower in Kohm range like I suggested. If you used Mohm range resistors the lines will be more susceptible to noise pickup.



With remotely mounted switches where wire may be very long or if there is concern with ESD then it would be advisable to not use this analog sorting for switch detection. Instead each switch should be dealt with in a digital manner. Digital treatment makes it more practical to:



  1. Provide ESD clamping on the signals at edge of circuit board.

  2. Buffer switch signals if necessary to protect sensitive MCU pins.

  3. Debounce switch signals with 1's and 0's instead of varying analogue values.

  4. Organize larger switch counts into a matrix to save GPIO pins.






share|improve this answer














share|improve this answer



share|improve this answer








edited Aug 31 at 9:30

























answered Aug 31 at 3:49









Michael Karas

41.6k34397




41.6k34397











  • This is really clever, will it work if the user has long wires like if they add an external button ?
    – Dean Hill
    Aug 31 at 5:10










  • @DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
    – Avid Pro Tool
    Aug 31 at 7:53










  • The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
    – Dean Hill
    Sep 1 at 6:44
















  • This is really clever, will it work if the user has long wires like if they add an external button ?
    – Dean Hill
    Aug 31 at 5:10










  • @DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
    – Avid Pro Tool
    Aug 31 at 7:53










  • The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
    – Dean Hill
    Sep 1 at 6:44















This is really clever, will it work if the user has long wires like if they add an external button ?
– Dean Hill
Aug 31 at 5:10




This is really clever, will it work if the user has long wires like if they add an external button ?
– Dean Hill
Aug 31 at 5:10












@DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
– Avid Pro Tool
Aug 31 at 7:53




@DeanHill this is basically the same as my schematic without the transistor as I mentioned. This should work fine and be much more straightforward.
– Avid Pro Tool
Aug 31 at 7:53












The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
– Dean Hill
Sep 1 at 6:44




The digital is what I was trying to acheive with the use of the mosfet or the transistor because i just dont know how people will mount these and im worried people will mount them far away
– Dean Hill
Sep 1 at 6:44










up vote
0
down vote













Originally you said you wanted to use a PNP transistor and a few different buttons that short something to ground in order to produce an output of 0-5V to send into a single input of your microcontroller.



Here's one way to do that.





schematic





simulate this circuit – Schematic created using CircuitLab



[the values shown are just a rough example, you should play around with them and see what works best for your application]



If you push each button one at a time, the output will change according to the resistance connected. Adjusting your resistor values adjusts the output. (This won't always work if you're planning on hitting two buttons simultaneously though since that would put the resistors in parallel.)



Alternatively, you could put Ro on the collector and take your output there, but you won't be able to use as wide a range of resistor values at the base (not sure how many different values you need at the output), and in that case R1/R2/R3's value will vary inversely to the output. With the configuration shown, the output will increase with their resistance and the change will be slower (you can do a DC sweep to observe this).



Of course you could skip the transistor and Ro altogether and take your output directly from the resistive divider.






share|improve this answer




















  • This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
    – Dean Hill
    Aug 31 at 4:50











  • @DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
    – Avid Pro Tool
    Aug 31 at 5:12










  • @DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
    – Avid Pro Tool
    Aug 31 at 5:25










  • hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
    – Dean Hill
    Aug 31 at 5:52










  • The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
    – Dean Hill
    Aug 31 at 5:53














up vote
0
down vote













Originally you said you wanted to use a PNP transistor and a few different buttons that short something to ground in order to produce an output of 0-5V to send into a single input of your microcontroller.



Here's one way to do that.





schematic





simulate this circuit – Schematic created using CircuitLab



[the values shown are just a rough example, you should play around with them and see what works best for your application]



If you push each button one at a time, the output will change according to the resistance connected. Adjusting your resistor values adjusts the output. (This won't always work if you're planning on hitting two buttons simultaneously though since that would put the resistors in parallel.)



Alternatively, you could put Ro on the collector and take your output there, but you won't be able to use as wide a range of resistor values at the base (not sure how many different values you need at the output), and in that case R1/R2/R3's value will vary inversely to the output. With the configuration shown, the output will increase with their resistance and the change will be slower (you can do a DC sweep to observe this).



Of course you could skip the transistor and Ro altogether and take your output directly from the resistive divider.






share|improve this answer




















  • This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
    – Dean Hill
    Aug 31 at 4:50











  • @DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
    – Avid Pro Tool
    Aug 31 at 5:12










  • @DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
    – Avid Pro Tool
    Aug 31 at 5:25










  • hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
    – Dean Hill
    Aug 31 at 5:52










  • The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
    – Dean Hill
    Aug 31 at 5:53












up vote
0
down vote










up vote
0
down vote









Originally you said you wanted to use a PNP transistor and a few different buttons that short something to ground in order to produce an output of 0-5V to send into a single input of your microcontroller.



Here's one way to do that.





schematic





simulate this circuit – Schematic created using CircuitLab



[the values shown are just a rough example, you should play around with them and see what works best for your application]



If you push each button one at a time, the output will change according to the resistance connected. Adjusting your resistor values adjusts the output. (This won't always work if you're planning on hitting two buttons simultaneously though since that would put the resistors in parallel.)



Alternatively, you could put Ro on the collector and take your output there, but you won't be able to use as wide a range of resistor values at the base (not sure how many different values you need at the output), and in that case R1/R2/R3's value will vary inversely to the output. With the configuration shown, the output will increase with their resistance and the change will be slower (you can do a DC sweep to observe this).



Of course you could skip the transistor and Ro altogether and take your output directly from the resistive divider.






share|improve this answer












Originally you said you wanted to use a PNP transistor and a few different buttons that short something to ground in order to produce an output of 0-5V to send into a single input of your microcontroller.



Here's one way to do that.





schematic





simulate this circuit – Schematic created using CircuitLab



[the values shown are just a rough example, you should play around with them and see what works best for your application]



If you push each button one at a time, the output will change according to the resistance connected. Adjusting your resistor values adjusts the output. (This won't always work if you're planning on hitting two buttons simultaneously though since that would put the resistors in parallel.)



Alternatively, you could put Ro on the collector and take your output there, but you won't be able to use as wide a range of resistor values at the base (not sure how many different values you need at the output), and in that case R1/R2/R3's value will vary inversely to the output. With the configuration shown, the output will increase with their resistance and the change will be slower (you can do a DC sweep to observe this).



Of course you could skip the transistor and Ro altogether and take your output directly from the resistive divider.







share|improve this answer












share|improve this answer



share|improve this answer










answered Aug 31 at 3:12









Avid Pro Tool

1669




1669











  • This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
    – Dean Hill
    Aug 31 at 4:50











  • @DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
    – Avid Pro Tool
    Aug 31 at 5:12










  • @DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
    – Avid Pro Tool
    Aug 31 at 5:25










  • hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
    – Dean Hill
    Aug 31 at 5:52










  • The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
    – Dean Hill
    Aug 31 at 5:53
















  • This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
    – Dean Hill
    Aug 31 at 4:50











  • @DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
    – Avid Pro Tool
    Aug 31 at 5:12










  • @DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
    – Avid Pro Tool
    Aug 31 at 5:25










  • hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
    – Dean Hill
    Aug 31 at 5:52










  • The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
    – Dean Hill
    Aug 31 at 5:53















This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
– Dean Hill
Aug 31 at 4:50





This is incredible! its perfect, this is what i was trying to turn Spehro's circuit into! Thank you so much!
– Dean Hill
Aug 31 at 4:50













@DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
– Avid Pro Tool
Aug 31 at 5:12




@DeanHill no problem, glad I could help. If you wouldn't mind voting for my question or marking it correct, I would appreciate that.
– Avid Pro Tool
Aug 31 at 5:12












@DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
– Avid Pro Tool
Aug 31 at 5:25




@DeanHill and don't overthink this either. You don't really need the transistor there at all, a resistive divider would probably do just fine and be much more simple/efficient. Michael Karas mentioned this method above. I only included the BJT because you said you wanted to use one, it's barely doing anything here. Why do you want to add a transistor into the mix at all?
– Avid Pro Tool
Aug 31 at 5:25












hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
– Dean Hill
Aug 31 at 5:52




hmm.. when i simulate this, it doesn't work.. no matter which switch you press its the same value?
– Dean Hill
Aug 31 at 5:52












The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
– Dean Hill
Aug 31 at 5:53




The reason I want the transistor there is because Im worried when people touch it if they arent weaaring a ground strap with shocks... i didnt want it to damage the micro
– Dean Hill
Aug 31 at 5:53

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f393624%2fswitching-a-divided-voltage-with-transistor-or-mosfet%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

How to combine Bézier curves to a surface?

Mutual Information Always Non-negative

Why am i infinitely getting the same tweet with the Twitter Search API?