Switch Interfacing with AT89C51


Switch is an input device to any electronics or electrical system. If we want to interface a switch to the microcontroller then we must select a small switch because microcontroller runs on +5V DC supply.

Switch comes in multiple types such as SPST, SPDT, DPST and DPDT switches. The SPST switch is connected to P3.0 port pin and SPDT switch is connected to P3.1 port pin and 8-bit DIP switch is connected to Port1. Depending upon the application requirement we can select appropriate switch to build the interactive system.

The basic fundamental to interface a switch is the switch should be connected between port pin and Ground. A pull-up resistor should also be connected to the same pin. If port pin is having internal pull-up resistor then external pull-up resistor need not to be connected. Due to this connection, microcontroller can sense Logic ‘1’ and Logic ‘0’ easily. When we don’t press a switch, logic ‘1’ appears on the corresponding port pin through pull-up resistor and when we press a switch, the port pin gets directly connected to the Ground that means logic ‘0’ appears on the pin. With these fundamentals, microcontroller can read the external logic states on the pin.

Leave a Reply