When you are just starting off in electronics, there are many design pitfalls that can lead to hours of frustrating troubleshooting. I highlighted the importance of troubleshooting in this earlier blog post regarding my work on the automated energy harvester. Many times these faults are fixed with a very simple tweak to the circuit design or component selection. One of the most basic of the faults is the infamous “floating pin” or “floating input” that can affect the I/O pins of digital integrated circuits. To best explain a floating input and how it can negatively affect your project consider the circuit in Figure 1:
When the momentary button is pressed it connects the I/O pin to Vcc and the microcontroller would register the input as a high. Now, what happens when the button is released? If you were like me you would assume the microcontroller, now that it is no longer connected to Vcc, would register a logic low. But this is not the case because the gate is not connected to ground; rather, it is floating. The microcontroller may register a low, but it might just as well register a high. By not being connect to a source, Vcc, or GND, the I/O pin is susceptible to electrical noise that makes the I/O randomly fluctuate between low and high. Such sources include thermal noise and electromagnetic interference (EMI) since the leads of the chip act like tiny antennas when they are floating.
You might be tempted to solve the problem with a solution seen in Figure 2. The problem with simply connecting the input to Vcc occurs when you press the button and create a short circuit between Vcc and GND. The short circuit could generate enough heat to damage your circuit. Or at the very least cause power supply voltage to drop to ground potential resulting in a non-functioning device. In short, bad things will happen.
So our solution, as shown in Figure 3, is to insert a pull-up resistor between Vcc and the I/O pin or a pull-down resistor between ground and the I/O. Using a pull-up resistor the I/O pin will normally see a logic high and when the button is pressed it will see a low. This is sometimes referred to as “active low” logic. Alternatively with a pull-down resistor, the I/O pin will normally see a logic low and when the button is pressed it will see a logic high. This is referred to as “active high” logic.
In our button example, use of a pull-up versus a pull-down resistor is rather subjective. Both will work, you just need to remember how to handle the button press in the firmware. There are other applications such as analog comparators or communication protocols such as I2C that are “open drain” based and thus require a pull-up resistor to raise the voltage on the communications lines. We will discuss I2C and open drain circuits further in a future blog post.
Another issue with reading button presses is called “bounce”. That is when a microcontroller registers multiple button presses even if the user only pushes the button once due to the mechanical oscillation of the button. We will also discuss button debouncing techniques to combat this problem in a future blog post as well.
Do you have troubleshooting horror stories you want to share? Let us know if floating pins have ever caused you design problems in the comments down below.
*** All circuits were done in the new MultiSim BLUE from Mouser and NI. Check it out at www.mouser.com/MultiSimBlue.
Michael Parks, P.E. is the owner of Green Shoe Garage, a custom electronics design studio and technology consultancy located in Southern Maryland. He produces the S.T.E.A.M. Power podcast to help raise public awareness of technical and scientific matters. Michael is also a licensed Professional Engineer in the state of Maryland and holds a Master’s degree in systems engineering from Johns Hopkins University.
Privacy Center |
Terms and Conditions
Copyright ©2019 Mouser Electronics, Inc. - A TTI and Berkshire Hathaway company.
Mouser® and Mouser Electronics® are trademarks of Mouser Electronics, Inc.
All other trademarks are the property of their respective owners.
Corporate headquarters and logistics center in Mansfield, Texas USA.