Book Image

Arduino Development Cookbook

By : Cornel M Amariei
Book Image

Arduino Development Cookbook

By: Cornel M Amariei

Overview of this book

Table of Contents (16 chapters)
Arduino Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Button with no resistor


It is simple to connect a button to the Arduino. You need the button, some wires, and a resistor. But what if we no longer need the resistor and want to still be able to use the button with no false readings?

The resistor is mandatory for proper operation of a button, and everybody will insist on using it. However, there is a little secret embedded in each Arduino pin. Each pin already has a pull-up resistor that we can enable with just one small change in our code.

Getting ready

For this recipe, you will need just two components:

  • An Arduino board connected to a computer via USB

  • A push button

How to do it…

There is just one simple step in this recipe:

  1. Connect the Arduino GND to a terminal on the button and connect the chosen digital pin to the other terminal.

Schematic

Here is one implementation on the 12th digital pin. Other digital pins can also be used.

Here is a simple way of wiring the button:

For most buttons with standard through-hole terminals, we can directly input the...