Embedded Systems & Firmware
A switch alone is connected to a microcontroller input pin, with no pull-up or pull-down resistor. What can happen while the switch is open?
- AThe pin always reads 1
- BThe pin floats at an undefined level, and noise makes it read 0 and 1 erratically
- CThe microcontroller loses power
Show answer and explanation
Answer: B. The pin floats at an undefined level, and noise makes it read 0 and 1 erratically
A CMOS input draws almost no current, so with nothing connected its voltage is undefined and noise from nearby signals or even a hand nearby changes the reading. Sitting at an intermediate voltage can also cause shoot-through current in the input circuit, raising power consumption. With a pull-up resistor to the supply, the pin reads 1 when the switch is open and 0 when it closes to ground. Most microcontrollers offer built-in pull-ups.
- A. With nothing connected, the value is undefined.
- B. Correct. A resistor is needed to hold it at a defined level.
- C. Power is not cut.