Push Button Switch

A switch is a mechanical device that opens and closes a circuit. A slide or a toggle switch controls the flow of electricity from one part of a circuit to another. It either remains open or remains closed.

With a push button or momentary switch, the circuit is closed only for the time the switch is pressed. The behaviour that is wanted is for the switch to act as toggle so the circuit can cycle from the "off" state to the "on" state each time with just a single press.

 

Digital Input

 

A push button switch can send a signal to the Arudino micro-controller as an INPUT. That signal can be determined to be HIGH or LOW. Once the signal is received by the controller, the programming in the controller makes a determination of the state of the circuit. When programmed correctly, the push button switch is a useful and fundamental constructor in the digital circuits.

 

Mechanical Noise

 

As a switch is pressed, the contacts inside may bounce a little. These are bits of metal that produce uneven contact. In the circuit this is detected as noise and can cause the circuit to flip-flop from open to closed very quickly. To smoothen out this signal, some clever bit of programming can be used so that the micro-controller waits a very small amount of time before taking a reading.

 

 

Push Button Circuit

The above diagram is the wiring setup for for a push button switch and a single LED. Port #5 is configured to take the input of the switch and port #6 is an output to drive the LED.

 

When the switch is closed, 5V is connected to the ground and the switch reads a LOW state. When the switch is open (the normal unpressed state), the switch reads HIGH. Port #5 has an internal resistor that is set to pull the port to a HIGH state by default (called an PULLUP resistor).

 

When the appropriate code is run in the micro-controller the push button switch behaves like a toggle. The code that runs remembers the state of the LED and cycles it.

 

The code for this switch can be found in my Pastebin link here.