Monday, April 16, 2012

Making push button work as a switch using arduino

In this post we will look into how we can user a push button like a switch, i.e. it turns on a circuit on one push and turns off the circuit in the next using an arudino uno board.

The circuit that we will use is the same one used in "Controlling a buzzer with a push button" but the program will be modified.

In this program we will have boolean variable,alt,which will be used to control the output at pin 3. Let us say we set the variable "alt" to HIGH intially.

Each time the push button is pressed the variable is used the set the output at digital I/O pin 3 :

Then the value of the variable is negated :

Thus value of alt changes to LOW.

In the iteration when the push button gets pressed again the negated value is applied to the pin 3, changing the value at pin 3 from HIGH to LOW.

The same steps are repeated again and again.

The output at pin3 thus will keep switching between the HIGH and LOW states at each press of the push button, just like the operation of a normal switch. Here is the program for same In the above program, there is a delay after the digitalWrite becuase otherwise the processor will loop through the interations at a very fast rate and we will not be able to view the desired operation.

Also note the delay if of 1 second so if the pushbutton is pressed more than once with in a second the output behaviour can not be garunteed.


No comments:

Post a Comment

Follow by Email