Fig: Switch
In this tutorial i will take you through the process of interfacing Arduino with a switch. If you haven't gone through my previous post on blinking LEDs with Arduino click here .
A switch is an electrical component used to disconnect or connect the conducting path in an electrical circuit. Electronic devices such as transistors, MOSFETs, and relays can be acted as switches and they fall under the category of electrical/electronic switches.
There are two ways of connecting a switch to a PIC MCU:
- Pull-Up method
- Pull-Down method
Whenever Switches are pressed or when two metals strike each other, Spikes are usually generated. The Arduino can misread these spikes as different or multiple switch press whereas the switch was pressed just once. To avoid this error ,there is need for a filtering mechanism which can be achieved with hardware (a filtering circuit) or software. In this tutorial we would use the software approach and what we are going to do is to initiate a small delay and check again for the status of the switch. if the microcontroller reads a Logic Zero ( Pull-up method) then we can be certain that the switch was pressed and vice-versa.
In this Tutorial we would be using the Pull-Up method. Our aim is to turn ON or turn OFF an LED whenever the switch is closed or opened . our switch is connected to I/O PIN13 of the Arduino UNO and note that Pin13 must then be configured as an input pin in order to read the status of the switch. The LED is connected to I/O pin4 of the Arduino UNO which is configured as an output pin.
Materials Required:
- Arduino UNO
- LED
- 330R Resistor
- Switch
- 10K Resistor
CODE:
0 Comments