# basic: selecting a resistor

Discussion in 'Electronic Basics' started by Costas Vlachos, Feb 8, 2004.

1. ### Costas VlachosGuest

From your description it looks like this is some sort of active keyboard
which requires a power supply and directly provides row/column signals which
you can read using the uC. If that's the case, then it looks like it needs
pull-down resistors to work. 4.7k or 10k should be fine. Don't use megaohm
resistors as they may not be able to pull the pins to ground hard enough.

Also, since you're posting to s.e.b, I have to ask: Are you sure the
keyboard works in the way you describe? Normally in matrix keyboards you
*send* signals to the columns (or rows) and *read* the rows (or columns) to
determine the key pressed. You don't directly read all 7 pins.

cheers,
Costas

2. ### GarethGuest

This is to be expected.
You are correct that a lower value resistor will use more current, but
only when a key is pressed; leakage from the pin of the microcontroller
will be very small even if you soldered the pin directly to ground. To
calculate the current use Ohm's law:

V = I*R

V = Voltage in Volts, I = current in Amps, R = resistance in Ohms

When a key is pressed you have 5V across the resistor, so:

I = 5/4700

I ~= 1mA

This current will flow in each of the resistors which have 5V across
them, which is two (one for the row, one for the column), so while a key
is pressed you will be using 2mA. You could reduce this by increasing
the resistor value, but you make the resistor to high your device will
more susceptible to noise or interference. I think a couple of Mohms
would be too high.

It is difficult to say exactly what is too high, but think you should
consider the following:

1) Current only flows in the resistor when a key is pressed, so consider
how long and how often a key is likely to be pressed. For example, if a
key is only likely to be pressed four times for 0.25 seconds in every
hour, the average current in the resistors will be 4*0.25/(60*60) =
1/3600 of the current calculated above. This may be insignificant.

2) How is this device powered? If power consumption is not a problem
then don't worry about 1mA through the resistors.

Gareth.

--

3. ### gooseGuest

Hello all

I have a microntroller connected to a keypad. It only
reliably works when I use a resistor to ground on each
pin on the uC that connects to the pins on the keypad.

1. 3 pins are connected to each column.
2. 4 pins are connected to each row.
3. 1 pin seems to be bridged to everything.

 &  above is expected for a matrix keypad.
 supplys power (+5v).

I supply +5v to the power pin of the keypad, and
read the other 7 pins. when any key is pressed,
a pin for the column and a pin for the row goes
high.

each pin is wired as follows:

|
|
R1
|
|
gnd

my question is what resistor should I choose for R1?

As I understand it, the smaller the resistance, the
greater the leakage current, no? I initially intended
to use 4,7k resistors (which is what I tested with),
but I now suspect that I should choose a larger
resistor (a coupe of mega ohms?).

tia

goose

4. ### vicGuest

What you need to know to calculate the maximum resistor value is the
leakage current of your uC pin. Let's say the maximum specified leakage
current is 1uA, and the logic low level limit is 1V :
Rmax = 1V/1uA = 1Mohm
By safety you should always multiply the limit values by 2, so I would
say 250kohm would be sufficient for this example.

Adapt these values to those specified in the datasheet of your
microcontroller.

As I understand your case, the current through the resistor gets high
only when a key is pressed, so there wouldn't be much losses on average
anyways.
vic

5. ### gooseGuest

Thanks to all the people who replied
(Costas, Gareth and Vic). Your replies
are immensely(sp?) usefull. To answer a
few questions:
2. the current through the resistor
does indeed only flow when a key
is pressed (two pins go high).

once again, thanks for your help bye
goose

6. ### Guest

Aren't most microcontrollers better at sinking. Did you set up the
port flags correctly. Did you code a de-bounce algorithm. If you set
the port flags up wrong you will have high impedance which might cause
this problem. Just if you could post the microcontroller you are
using and keypad brand and model number. Anyways just a thought, just
don't wish to shoot ideas into your head that will send you down it
the wrong direction.  