Arduino Uno Quick Start Manual page 68

Hide thumbs Also See for Arduino Uno:
Table of Contents

Advertisement

Top
Connected
Connected
The following picture shows a simple circuit using a pushbutton. Connect
pin 7 (chosen completely arbitrarily) to the pushbutton, and connect the
pushbutton via a 10kΩ resistor to ground. Then connect the 5-volt power
supply to the other pin of the button. Make sure the pushbutton s orientation
is right. Its connected pins have to bridge the gap of the breadboard.
All in all, this approach seems straightforward, but why do we need a resistor
again? The problem is that we expect the pushbutton to return a default
value (
LOW
) in case it isn t pressed. But when the button isn t pressed, it would
be directly connected to ground and would flicker because of static and
interference. Only a little bit of current flows through the resistor, and this
helps prevent random fluctuations in the voltage at the input pin.
When the button is pressed, there will still be 5 volts at the Arduino s digital
pin, but when the button isn t pressed, it will cleanly read the connection to
ground. We call this a pull-down resistor; a pull-up resistor works exactly the
other way around. That is, you have to connect the Arduino s signal pin to
power through the pushbutton and connect the other pin of the pushbutton
to ground using a resistor.
Now that we ve eliminated all this ugly unstable real-world behavior, we can
return to the stable and comforting world of software development. The follow-
ing program checks whether a pushbutton is pressed and lights an LED
accordingly:
Front
www.it-ebooks.info
Working with Buttons
49
Side
report erratum
discuss

Hide quick links:

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the Arduino Uno and is the answer not in the manual?

Subscribe to Our Youtube Channel

Table of Contents