Chapter 3

More Arduino Programming Tricks

IN THIS CHAPTER

Bullet Reading the status of push buttons

Bullet Generating random numbers

Bullet Using a potentiometer as input

In this chapter, you learn some additional Arduino programming techniques that will become invaluable in your Arduino projects. Specifically, you learn how to handle input data in the form of push buttons, how to generate random numbers that will make your programs more interesting by adding a degree of randomness, and how to read the value of a potentiometer.

Using a Push Button with an Arduino

In Chapter 2 of this minibook, you learn how to connect an LED to an Arduino I/O pin and turn the LED on or off by using digitalWrite function in an Arduino program. The digitalWrite function uses the I/O pins as output pins by setting the status of an I/O pin to HIGH or LOW so that external circuitry (such as an LED) can react to the pin's status.

But what if you want to use an I/O pin as an input instead of an output? In other words, what if you want the Arduino to react to the status of an external circuit instead of the other way around? The easiest way to do that is to connect a push button to an I/O pin. Then, you can add commands ...

Get Electronics All-in-One For Dummies, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.