I want to connect a LED and Push button on the GPIO input pin of a MCU, STM32F103 so that when the push button is pressed then the state of LED indicates the button is pressed. Is it possible to connect a LED and Push button on the input pin?
Figure 1. Two options.
R3 and R4 added as per Spehro's comment.
When the button is pressed it pulls the GPIO to a well defined voltage. When the button is released it needs to be pulled to the opposite logic level (other voltage rail). This is done by a pull-up (a) or a pull-down (b) resistor. I assumed that the LED and series resistor would do that for you. Spehro (who actually does this stuff for a living) cautions that a separate resistor may be required due to the LED being in circuit and making the pull very weak.
Actually, this is quite simple. Wire it up like this:
You may even configure the GPIO as an open drain output and control the LED from the µC as well as the button. As you can't check the button while the GPIO is turned an output, you have to switch to input mode for a few µs every few ms. This is invisible.
What you can't have with this circuit is not turning on the LED when the button is pressed.