papunblg
Advanced Member level 3
- Joined
- Oct 22, 2010
- Messages
- 716
- Helped
- 172
- Reputation
- 344
- Reaction score
- 165
- Trophy points
- 1,343
- Location
- Kolkata India
- Activity points
- 6,421
Publish the schematic. Its importent! A pin may get high or low upon closing depending on how it is connected.
Figure shows two common ways to interface switches to a microcontroller input. Input P0 uses R1 as a pull up. If SW1 is open, P0 will be high, and read as a logical 1. When SW1 is closed, pin P0 is shorted to ground, or 0V, and P0 will read as a logical 0.
P1 has R2 as a pull down resistor. When SW2 is open, P1 is pulled low, and read as a logical 0. Closing SW2 causes current to flow through R2, raising the voltage at P1 to the Vcc level. At that point P1 will read as a logical 1.
Note that some microcontrollers have internal pull up resistors that can be enabled under program controller. You don’t need to wire up R1 if you use an internal pull up resistor. If you use an external pull up resistor, tie the high end to the same voltage used to run the microcontroller. Using a higher voltage will damage the microcontroller, and a lower voltage may result the circuit not working.
More details and Selecting Resistor Values---> see Interfacing switches to microcontrollers
Figure shows two common ways to interface switches to a microcontroller input. Input P0 uses R1 as a pull up. If SW1 is open, P0 will be high, and read as a logical 1. When SW1 is closed, pin P0 is shorted to ground, or 0V, and P0 will read as a logical 0.
P1 has R2 as a pull down resistor. When SW2 is open, P1 is pulled low, and read as a logical 0. Closing SW2 causes current to flow through R2, raising the voltage at P1 to the Vcc level. At that point P1 will read as a logical 1.
Note that some microcontrollers have internal pull up resistors that can be enabled under program controller. You don’t need to wire up R1 if you use an internal pull up resistor. If you use an external pull up resistor, tie the high end to the same voltage used to run the microcontroller. Using a higher voltage will damage the microcontroller, and a lower voltage may result the circuit not working.
More details and Selecting Resistor Values---> see Interfacing switches to microcontrollers
Last edited: