[AVR] How to sense the Switch is Open or close?

Status
Not open for further replies.

sundar-edaboard

Junior Member level 1
Joined
Sep 5, 2013
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
Bahrain
Visit site
Activity points
131


Hi,

How to configure the I/O pins to sense the switch is closed or open?

How the circuit works?
 

As far as I see, the diode doesn't have any purprose in this cicuit, if you intended to use a zener diode then the 1N4148 is anyways a poor choice since it's a small signal low noise silicon diode.

Keep the switch and the resistor in series, but connect the other side of the switch to VCC and the other side of the resistor to ground. When the button is pressed, the node between them will be connected to ground and the logic level will be 0. If the switch is not pressed, then the resistor will pull up the node to VCC, resulting in a logic 1 at this point. Simply sense the voltage at this point with any digital IO pin (you only need one) and you're able to determine the state of the switch. For a normally closed switch (NC) swap the position of resistor and switch in the circuit.
 
hi. simply you can set the left I/O as out put and set the right hand I/O as in put, after that if the right I/O was High when you set left I/O as 1 ,the switch is close and if no the switch is open.
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…