 To read whether a switch is open or closed, the microcontroller configures one pin as an input with an internal pull-up resistor.The other pin is configured as an output and set to the low logic level.If the input pin reads low, then the switch is closed, and if the input pin reads high, then the switch is open.