[Beginner] How to calculate a Base Resistor value?

Thread Starter

patrickstefanski

Joined Apr 15, 2017
49
Hi Everyone,
I have a project that is using a 5v Microcontroller (Sparkfun Pro Mini). It has the switch portion of a Rotary Encoder wired to pins 6 and 8. Pin 8 is INPUT_PULLUP and it's value is being read as a variable. Pin 6 is OUTPUT_LOW and is being used as the ground for this signal.

I want to use a second input on the same pins, however this input is coming from a 3.3v SAMD21 microcontroller. I tried just running a wire straight to pin 8 from the SAMD21, but it didn't work. I"m assuming the 3.3V arduino didn't have enough power to pull down the 5v signal from the Pro Micro.

So I thought a better Idea would be use a 2N2222 transistor from Pin 6 to Pin 8 and have the Base hooked up to an output from the SAMD21.

This worked in a quick bench test, but there was some strange delays and stuff and I realize its probably because I'm not doing right by the transistor.

So my question is: Do I need just a base resistor or more resistors? How do I calculate the base resistor? And I mean this from the perspective of an absolute beginner. I found formulas online but all the variables may has well been a foreign language. Rb is easy to translate, but hFe? I don't know what these mean or how to find those values. Is there some online textbooks I can read to understand this stuff a little better?
 

Attachments

jpanhalt

Joined Jan 18, 2008
11,087
What you need is called a "level shifter." There is a plethora of articles on it. Here is part of my biblio on it:

Microchip:
http://ww1.microchip.com/downloads/en/DeviceDoc/chapter 8.pdf
TI:
http://www.ti.com/lit/sg/scyb018f/scyb018f.pdf
Philips (secondary site):
http://www.adafruit.com/datasheets/an97055.pdf
Sparkfun board and schematic:
https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

Transition levels may also depend on how your input ports are configured (CMOS v. TTL).
 

crutschow

Joined Mar 14, 2008
34,285
You always need a base resistor for a BJT transistor to limit the base current.
The resistor should limit the base current to 10-20% of the collector current when the transistor is used as a switch.
 

Picbuster

Joined Dec 2, 2013
1,047
Hi Everyone,
I have a project that is using a 5v Microcontroller (Sparkfun Pro Mini). It has the switch portion of a Rotary Encoder wired to pins 6 and 8. Pin 8 is INPUT_PULLUP and it's value is being read as a variable. Pin 6 is OUTPUT_LOW and is being used as the ground for this signal.

I want to use a second input on the same pins, however this input is coming from a 3.3v SAMD21 microcontroller. I tried just running a wire straight to pin 8 from the SAMD21, but it didn't work. I"m assuming the 3.3V arduino didn't have enough power to pull down the 5v signal from the Pro Micro.

So I thought a better Idea would be use a 2N2222 transistor from Pin 6 to Pin 8 and have the Base hooked up to an output from the SAMD21.

This worked in a quick bench test, but there was some strange delays and stuff and I realize its probably because I'm not doing right by the transistor.

So my question is: Do I need just a base resistor or more resistors? How do I calculate the base resistor? And I mean this from the perspective of an absolute beginner. I found formulas online but all the variables may has well been a foreign language. Rb is easy to translate, but hFe? I don't know what these mean or how to find those values. Is there some online textbooks I can read to understand this stuff a little better?
A transistor is a current controlled device the gain is output collector current / base current
in the emitter are two currents the base and collector current.
In transistors data sheet are a number of spec's one of them is the max base current and one is the gain.
you have to calculate the collector current needed this allows you to calculate the base gain.
But if the base gain is higher than the spec's the transistor is useless for that purpose/
when well within the spec's the calculation is as follows

serial resistor = (max voltage at the resistor -.6V)/ calculated base current (in your case(3.3- 0.6)/ calculated base current)
example gain 80 10ma collector /80=0,125 r = 2.7/0.12 = 22.5K approx

As your circuit is binary you better take a (mos)fet (voltage driven) and the your serial resistor is low 100 Ohm.

Picbuster
 

Thread Starter

patrickstefanski

Joined Apr 15, 2017
49
A transistor is a current controlled device the gain is output collector current / base current
in the emitter are two currents the base and collector current.
In transistors data sheet are a number of spec's one of them is the max base current and one is the gain.
you have to calculate the collector current needed this allows you to calculate the base gain.
But if the base gain is higher than the spec's the transistor is useless for that purpose/
when well within the spec's the calculation is as follows

serial resistor = (max voltage at the resistor -.6V)/ calculated base current (in your case(3.3- 0.6)/ calculated base current)
example gain 80 10ma collector /80=0,125 r = 2.7/0.12 = 22.5K approx

As your circuit is binary you better take a (mos)fet (voltage driven) and the your serial resistor is low 100 Ohm.

Picbuster
Wow, thank you so much. This is really helpful. Yes I was thinking of using a logic level mosfet for this as well, but since I had the BJTs on hand I thought I'd give that a try.

Your calculations and explanations are very clear. Thank you very very very much.
 

ScottWang

Joined Aug 23, 2012
7,397
What kind of the rotary encoder, datasheet?
Are you should the rotary encoder is connected correct, the rotary encoder isn't connected in series the bjt?

Does the red color is a uC, which one? (arduino pro mini?)
 
Top