Thursday, July 8, 2010

Arduino Button Bouncing - Why doesn't my LED remain on?

This is an update to my last posting on Getting Started with Arduino. After a couple of days of frustration, I purchased an Arduino Prototyping Shield (I don't think I'm yet ready to pick up the soldering iron and build it from a kit) as the Freetronics Starter Kit I purchased only comes with a mini breadboard and lots of the tutorials come with a prototyping shield and needed to see something consistent. Anyway, I was looking at this button tutorial on the Arduino website.

The circuit is similar to the one in my last post, and the sketch from the arduino website is reproduced below:

When tested out, the LED only turns on when the button is pressed. Turns out, due to the spring mechanism in the button, a rapid sequence of on off signals are sent when the button is pressed (Remember Arduino is a continous loop!). Hence a delay of about 10-50 milliseconds delay correctly detects a transition, as seen below: