Lesson goal: Read a digital input from the Arduino (a 1 or 0 only)

Previous: Read a digital input | Home | Next: Study your button pushing

In a previous lesson, you saw how to read a digital input, which was always a 0 or a 1. It might have seemed kind of silly to have such limit data. But it is not. Here's an example of digital information: a switch. A switch can be either pressed or unpressed. These are the two possible states of a switch. You can think of pressed as a 1 and unpressed as a 0--see TWO states. A switch is kind of a digital device.

Wire up the circuit shown below, then run the following code. Press the button a few times. What do you see as the output?

Now you try. Seeing how a push-button switch returns digital information.

Type your code here:

See your results here:

Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

  1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

  2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

  3. Then click the "Use on iPhone" button that you'll see.