First Time Using Pull-Up / Pull-Down Resistors, Did I Do It Right?

Thread Starter

Max Holdcroft

Joined May 12, 2024
38
1722168315042.png

Hey all,
Basically the title. I have a push button connected to a pin on a microcontroller that I want to be able to detect the pushing of. I've connected this to a pull-up resistor. I'm running the microcontroller off 2.8v input, and the resistor is 4.7K ohms. This is my first time using these, and I just wanted to check I did it right.
Thanks in advance!
Max :)
 

MisterBill2

Joined Jan 23, 2018
27,164
That value of resistor and the circuit appears to be correct. This is based on the guess that the impedance of the digital input is much greater, which I would expect it to be.
 

dl324

Joined Mar 30, 2015
18,219
This is my first time using these, and I just wanted to check I did it right.
It's sort of right. Many values can be used and 4.7k seems on the low side to me. 10k would be more common. Does the microcontroller have pull up/down capabilities? If it does, you don't need an external pull-up.

You're probably going to have problems with switch bounce.

Regarding your schematic. You have drawn the resistor sideways. The vast majority of electronics professionals prefer components to be drawn vertically. By drawing the resistor sideways, you were forced to make wire bends for power and ground that would have been unnecessary if you drew the resistor more conventionally. You did use the preferred orientation for power and ground.

There are times when we'd draw a resistor horizontally. This isn't one of them.

The actual part number of the switch isn't meaningful. Could you imagine how cluttered a schematic would be if you used several of those switches. A schematic is used to convey circuit functionality. A BOM is used to specify certain part numbers.

The resistor value should be on the schematic.
 

WBahn

Joined Mar 31, 2012
32,703
I agree - that should be fine. You can probably use a much larger value of resistor, even 100 kΩ. Higher values will consume less power, but if the switch is only closed momentarily (or for relatively short periods), that shouldn't be an issue. Using a 10 kΩ resistor tends to convey the notion that the value is not critical to a person reading the schematic, while 4.7 kΩ can create the impression that it was specifically chosen.

Check your microcontroller datasheet to see if it has internal pullup/pulldowns that can be enabled. That can save you a part and some wiring, although some people prefer to use external pullups/pulldowns so that they know that the input behavior will be what they want.

One thing to watch for is a phenomenon known as "switch bounce". Basically, whenever the button is pressed or released, you will see many (possibly dozens) of HI/LO transitions. So if your logic is trying to count how many times the switch has been pressed, that will be a problem. There are ways to deal with bounce both in external hardware and in software. Just ask yourself whether it is detrimental if your program senses the button going LO, then HI, then LO, and so on over a period of about 20 milliseconds. If the answer is that it doesn't matter, then you can ignore the bounce issue.
 

Ian0

Joined Aug 7, 2020
13,097
4.7k says to me that it was designed by someone who learned his craft during the days of TTL.

You might want to use lower values (such as 4.7k or even 1k) if the switch is a long distance from the micrcontroller.
If it's a really long way away, you also might need other interference suppression components.
 
Top