# Adafruit IO Basics: Digital Input

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/024/676/medium800thumb/adafruit_io_raspberry_pi_button.jpg?1448317755)

_Want to send data from your electronics project to the Internet and display it on a webpage?_

This guide will teach you to send data from a digital input, such as a momentary push-button, to Adafruit IO. Using Adafruit IO, you will build a visual Dashboard with a Gauge block to display (in real-time!) when the push button has been pressed or depressed.

Adafruit IO allows you to connect and interact with this project either by:

1. Programming a microcontroller, microcomputer, or desktop computer (configurable, and powerful, but requires coding skills)   
  
or  
  
2. Using our no-code "WipperSnapper" firmware (super fast! no coding! but only for some microcontroller boards)

## Option 1. Build and Program this project with Arduino or CPython

This guide contains instructions and code for building this project using Arduino, the Adafruit IO Arduino client library, and an Arduino-compatible board. We also include instructions for building this project using a Raspberry Pi and code for CPython (a.k.a desktop-computer Python).

## Option 2. No Code? No Problem! Build this guide using Adafruit IO and WipperSnapper!

With Adafruit IO, you can connect your devices without writing a single line of code using our custom WipperSnapper firmware. Load the WipperSnapper firmware onto your board, add credentials, and plug it into power. Your board will automatically register itself with your Adafruit IO account.

From there, you can add&nbsp;_components_&nbsp;to your board such as buttons, switches, potentiometers, sensors, and more! Components are&nbsp;_dynamically&nbsp;_added to hardware, so you can immediately start interacting, logging, and streaming the data your projects produce without writing code.

## Pre-Requisite Reading: Adafruit IO Basics

This guide is part of a series of guides that cover the basics of using Adafruit IO.&nbsp;If you haven't read through the Adafruit IO feed and dashboard basics guides, you should do that before continuing with this guide so you have a basic understanding of the core functionality of Adafruit IO.

### Adafruit IO Basics: Feeds

[Adafruit IO Basics: Feeds](https://learn.adafruit.com/adafruit-io-basics-feeds)
### Adafruit IO Basics: Dashboards

[Adafruit IO Basics: Dashboards](https://learn.adafruit.com/adafruit-io-basics-dashboards)
# Adafruit IO Basics: Digital Input

## Get Started with Adafruit IO

Adafruit IO is integrated with your&nbsp;[adafruit.com account](https://accounts.adafruit.com/)&nbsp;so you don't need to create yet another online account! You need an Adafruit account to use Adafruit IO because we want to make sure the data you upload is available to only you (unless you decide to publish your data).

## I have an Adafruit.com Account already

**If you already have an Adafruit account, then you already have access to Adafruit IO**. It doesn't matter how you signed up, your account will make all three available.

To access Adafruit IO, simply visit [https://io.adafruit.com](https://io.adafruit.com) to start streaming, logging, and interacting with your data.

## Create an Adafruit Account (for Adafruit IO)

An Adafruit account makes Adafruit content and services available to you in one place. Your account provides access to the [Adafruit shop](https://www.adafruit.com/), the [Adafruit Learning System](https://learn.adafruit.com/), and [Adafruit IO](https://io.adafruit.com/). This means only one account, one username, and one password are necessary to engage with the content and services that Adafruit offers.

If you do not have an Adafruit account, signing up for a new Adafruit account only takes a couple of steps.

Begin by visiting [https://accounts.adafruit.com](https://accounts.adafruit.com).

**Click the Sign Up button** under the "Need An Adafruit Account?" title, below the Sign In section.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/220/medium800/adafruit_io_Create_account_sign_in_up_page.png?1697479894)

This will take you to the **Sign Up** page.

**Fill in the requested information,** and **click the Create Account button.**

![](https://cdn-learn.adafruit.com/assets/assets/000/125/219/medium800/adafruit_io_Create_Account_info_entered.png?1697479894)

This takes you to your Adafruit Account home page. From here, you can access all the features of your account.

You can also access the Adafruit content and services right from this page. Along the top of the page, you'll see a series of links beginning with "Shop". To access any of these, simply click the link.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/217/medium800/adafruit_io_Create_account_home_page.png?1697479894)

For example, **to begin working with Adafruit IO, click the IO link** to the right of the rest of the links. This is the same for the other links as well.

That's all there is to creating a new Adafruit account, and navigating to Adafruit IO.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/218/medium800/adafruit_io_Create_Account_io_homepage.png?1697479770)

# Adafruit IO Basics: Digital Input

## Arduino Wiring

You will need the following parts for this tutorial:

* **1x** Adafruit IO compatible Feather
* **3x** jumper wires
* **1x** 10k resistor
* **1x** momentary button

You will need to connect the following pins to the button and 10k resistor:

* Feather **GND** to one side of the momentary button
* Feather **Pin 5** to the other side of the momentary button
* Feather **3V** to one leg of a **10k** resistor
* The second leg of the **10k** resistor to the same side of the momentary button as **Pin 5**

**Note:** Resistors are *not* polarized, so the 10k resistor can be connected to the circuit in either direction.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/313/medium800/adafruit_io_02_fritzing.png?1487119070)

# Adafruit IO Basics: Digital Input

## Arduino Setup

You should go through the setup guides associated with your selected set of hardware, and make sure you have internet connectivity with the device before continuing. The following links will take you to the guides for your selected platform.

* [Adafruit Feather HUZZAH ESP8266 Setup Guide](../../../../adafruit-io-basics-esp8266-arduino)

You will need to make sure you have at least **version 2.3.1** of the Adafruit IO Arduino library installed before continuing. You will also need the Arduino HTTP library and Adafruit MQTT library so check the setup guide above to get all set up!

![](https://cdn-learn.adafruit.com/assets/assets/000/039/367/medium800/adafruit_io_Screen_Shot_2017-02-16_at_2.41.36_PM.png?1487274257)

For this example, you will need to open the **adafruitio\_06\_digital_in** example in the **Adafruit IO Arduino** library.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/314/medium800/adafruit_io_Screen_Shot_2017-02-15_at_1.23.02_PM.png?1487183104)

Next, we will look at the network configuration options in the sketch.

# Adafruit IO Basics: Digital Input

## Arduino Network Config

To configure the network settings, click on the **config.h** tab in the sketch. You will need to set your Adafruit IO username in the **IO_USERNAME** define, and your Adafruit IO key in the **IO_KEY** define.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/317/medium800/adafruit_io_03_config.png?1487185264)

## WiFi Config

WiFi is enabled by default in **config.h** so if you are using one of the supported WiFi boards, you will only need to modify the **WIFI_SSID** and **WIFI_PASS** options in the **config.h** tab.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/318/medium800/adafruit_io_04_wifi.png?1487185900)

## FONA Config

If you wish to use the FONA 32u4 Feather to connect to Adafruit IO, you will need to first comment out the WiFi support in **config.h**

![](https://cdn-learn.adafruit.com/assets/assets/000/039/319/medium800/adafruit_io_05_wifi_disable.png?1487186164)

Next, remove the comments from both of the FONA config lines in the FONA section of **config.h** to enable FONA support.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/320/medium800/adafruit_io_06_fona.png?1487186409)

## Ethernet Config

If you wish to use the Ethernet Wing to connect to Adafruit IO, you will need to first comment out the WiFi support in **config.h**

![](https://cdn-learn.adafruit.com/assets/assets/000/039/321/medium800/adafruit_io_05_wifi_disable.png?1487186577)

Next, remove the comments from both of the Ethernet config lines in the Ethernet section of **config.h** to enable Ethernet Wing support.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/322/medium800/adafruit_io_07_ethernet.png?1487186729)

Next, we will look at how the example sketch works.

# Adafruit IO Basics: Digital Input

## Arduino Code

The **adafruitio\_06\_digital_in** example uses digital pin 5 by default on all boards, and that can be modified if needed by changing the **BUTTON_PIN** define. 

**Note:** If you are using the WICED Feather, you will need to change the **BUTTON_PIN** define to *PC5* instead of the default setting of *5*.

```
/************************ Example Starts Here *******************************/

// digital pin 5
#define BUTTON_PIN 5
```

The next chunk of code sets up two boolean variables to track button state, and an Adafruit IO Feed instance for a feed called **digital**.

```
// button state
bool current = false;
bool last = false;

// set up the 'digital' feed
AdafruitIO_Feed *digital = io.feed("digital");
```

In the setup function, we set the **BUTTON_PIN** as a digital input, and connect to Adafruit IO. The code will wait until you have a valid connection to Adafruit IO before continuing with the sketch. If you have any issues connecting, check **config.h** for any typos in your username or key.

```
void setup() {

  // set button pin as an input
  pinMode(BUTTON_PIN, INPUT);

  // start the serial connection
  Serial.begin(115200);

  // wait for serial monitor to open
  while(! Serial);

  // connect to io.adafruit.com
  Serial.print("Connecting to Adafruit IO");
  io.connect();

  // wait for a connection
  while(io.status() &lt; AIO_CONNECTED) {
    Serial.print(".");
    delay(500);
  }

  // we are connected
  Serial.println();
  Serial.println(io.statusText());

}
```

Next, we have the main loop() function. The first line of the loop function calls `io.run();` this line will need to be present at the top of your loop in every sketch. It helps keep your device connected to Adafruit IO, and processes any incoming data.

```
void loop() {

  // io.run(); is required for all sketches.
  // it should always be present at the top of your loop
  // function. it keeps the client connected to
  // io.adafruit.com, and processes any incoming data.
  io.run();
```

The next chunk of code inside the **loop()** checks the current state of the button, and saves the state of the button in the **current** variable. Because we are using a pullup resistor, we will need to flip the button state.

If the button state is **LOW** it means the button is pressed, so we set `current = true;`. If the button state is **HIGH** it means the button is released, so we set `current = false;`.

We then check if the **current** button state is equal to the **last** button state. If it is equal, we will return early and not continue with the rest of the loop.

```
  // grab the current state of the button.
  // we have to flip the logic because we are
  // using a pullup resistor.
  if(digitalRead(BUTTON_PIN) == LOW)
    current = true;
  else
    current = false;

  // return if the value hasn't changed
  if(current == last)
    return;
```

The final chunk of the `loop()` function prints the current value to the Arduino Serial Monitor, and sends the current value to the **digital** feed on Adafruit IO. We also set `last = current;` so we can tell if the state of the button has changed in the next run of the loop.

```
  // save the current state to the 'digital' feed on adafruit io
  Serial.print("sending button -&gt; ");
  Serial.println(current);
  digital-&gt;save(current);

  // store last button state
  last = current;

}
```

Upload the sketch to your board, and open the Arduino Serial Monitor. Your board should now connect to Adafruit IO.

```
Connecting to Adafruit IO....

Adafruit IO connected.
```

You can now press the button, and you should see button presses being sent to Adafruit IO.

```
sending button -&gt; 1
sending button -&gt; 0
sending button -&gt; 1
sending button -&gt; 0
```

Check your dashboard on Adafruit IO, and you should see the gauge respond to button presses.

![](https://cdn-learn.adafruit.com/assets/assets/000/039/323/medium800thumb/adafruit_io_raspberry_pi_button.jpg?1487189113)

# Adafruit IO Basics: Digital Input

## WipperSnapper Setup

Warning: 

## What is WipperSnapper

WipperSnapper is a firmware designed to turn any WiFi-capable board into an Internet-of-Things device without programming a single line of code. WipperSnapper connects to [Adafruit IO](https://io.adafruit.com/), a web&nbsp;platform designed ([by Adafruit!](https://www.adafruit.com/about)) to&nbsp;_display_,&nbsp;_respond_, and&nbsp;_interact_&nbsp;with your project's data.

Simply load the WipperSnapper firmware onto your board, add credentials, and plug it into power. Your board will automatically register itself with your Adafruit IO account.

From there, you can add&nbsp;_components_&nbsp;to your board such as buttons, switches, potentiometers, sensors, and more! Components are&nbsp;_dynamically&nbsp;_added to hardware, so you can&nbsp;immediately start interacting, logging, and streaming the data your projects produce without writing code.

## Sign up for Adafruit.io

You will need an Adafruit IO account to use WipperSnapper on your board. If you do not already have one, head over to [io.adafruit.com](https://io.adafruit.com/) to create a&nbsp;_free_ account.

## Install WipperSnapper

Log into your [Adafruit IO](https://io.adafruit.com/) account. Click the _New Device_ button at the top of the page.

![](https://cdn-learn.adafruit.com/assets/assets/000/112/548/medium800/wippersnapper_setup__board_selector__web__new_device_1.png?1655919766)

After clicking New Device, you should be on the _board selector_ page. This page displays every board that is compatible with the WipperSnapper firmware.

![](https://cdn-learn.adafruit.com/assets/assets/000/112/550/medium800/wippersnapper_setup__board_selector__web__selector_maion.png?1655920178)

In the board selector page's search bar, search for the ESP32-S2 TFT Feather&nbsp;(or your board of choice).&nbsp;Once you've located the board you'd like to install WipperSnapper on,_&nbsp;_click the&nbsp;_Choose Board_&nbsp;button to bring you to the self-guided installation wizard.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/023/medium800/wippersnapper_chrome_MlFWX7xoCQ.png?1699542895)

Follow the step-by-step instructions on the page to install Wippersnapper on your device and connect it to Adafruit IO. You may need to revisit this New Device page if you're Wireless Network details change in the future.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/024/medium800/wippersnapper_chrome_7L8p15Fiiy.png?1699543039)

If the installation was successful, a popover should appear displaying that your board has successfully been detected by Adafruit IO.

Give your board a name and click "Continue to Device Page".

![](https://cdn-learn.adafruit.com/assets/assets/000/126/025/medium800/wippersnapper_adafruit_products_tft_s2_detected.png?1699543464)

You should be brought to your board's device page.

Next, Visit this guide's **WipperSnapper Essentials** pages to learn how to interact with your board using Adafruit IO.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/026/medium800/wippersnapper_adafruit_products_s2_tft_device_page.png?1699543484)

## Feedback

Adafruit.io WipperSnapper is in **beta** and you can help improve it!

If you have&nbsp; suggestions or general feedback about the installation process - visit [https://io.adafruit.com/support](https://io.adafruit.com/support), click _"Contact Adafruit IO Support"_ and select _"I have feedback or suggestions for the WipperSnapper Beta"._

## Troubleshooting

If you encountered an issue during installation, please try the steps below first.

If you're still unable to resolve the issue, or if your issue is not listed below, get in touch with us directly at [https://io.adafruit.com/support](https://io.adafruit.com/support "https://io.adafruit.com/support"). Make sure to click&nbsp; _"Contact Adafruit IO Support"_ and select "_There is an issue with WipperSnapper. Something is broken!"_

### 

A lot of people end up using a charge-only USB cable and it is very frustrating! Make sure you have a USB cable you know is good for data sync.&nbsp;USB Hubs can also interfere so make sure the device is directly connected to your computer.

If you're computer isn't up to date with the latest driver updates, then you may not have the software driver necessary for the USB Serial controller that speaks to the Microcontroller. Find the latest drivers on your boards learn guide page, or [here](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather/arduino-ide-setup) for the ESP32-S2 TFT Feather.

If you've already installed the firmware, but can't set your secrets then try resetting the board and it should show up (if it supports USB Mass Storage), otherwise it might be easiest to go back to the new device page and set up the board's software again by following the steps for your board.

### 

First, make sure that you selected the correct board on the board selector.

Next, please make sure that you entered your WiFi credentials properly, there are no spaces/special characters in either your network name (SSID) or password, and that you are connected to a 2.4GHz wireless network.

If you're still unable to connect your board to WiFi, please [make a new post on the WipperSnapper technical support forum with the error you're experiencing, the LED colors which are blinking, and the board you're using.](https://forums.adafruit.com/viewforum.php?f=66)

### 

Try hard-resetting your board by unplugging it from USB power and plugging it back in.

If the error is still occurring, please&nbsp;[make a new post on the WipperSnapper technical support forum with information about what you're experiencing, the LED colors which are blinking (if applicable), and the board you're using.](https://forums.adafruit.com/viewforum.php?f=66)

## "Uninstalling" WipperSnapper&nbsp;

WipperSnapper firmware is an application that is loaded onto your board. There is nothing to "uninstall". However, you may want to "move" your board from running WipperSnapper to running Arduino or CircuitPython. You also may need to restore your board to the state it was shipped to you from the Adafruit factory.&nbsp;

### Moving from WipperSnapper to CircuitPython

Follow the steps on the [Installing CircuitPython page](https://learn.adafruit.com/welcome-to-circuitpython/installing-circuitpython) to install CircuitPython on your board running WipperSnapper.

- If you are unable to double-tap the RST button to enter the UF2 bootloader, follow the _"Factory Resetting a WipperSnapper Board"_ instructions below.

Uploading this sketch will overwrite WipperSnapper. If you want to re-install WipperSnapper, follow the instructions at the top of this page.

### Moving from WipperSnapper to Arduino

If you want to use your board with Arduino, you will use the Arduino IDE to load&nbsp;_any_ sketch onto your board.

First, follow the page below to set up your Arduino IDE environment for use with your board.

[Setup Arduino IDE](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather/arduino-ide-setup)
Then, follow the page below to upload the "Arduino Blink" sketch to your board.

[Upload Arduino Blink Sketch](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather/arduino-blink)
Uploading this sketch will overwrite WipperSnapper. If you want to re-install WipperSnapper, follow the instructions at the top of this page.

### Factory Resetting a WipperSnapper Board

Sometimes, hardware gets into a state that requires it to be "restored" to the original state it shipped in. If you'd like to get your board back to its original factory state, follow the guide below.

[Factory Reset Guide](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather/factory-reset)
# Adafruit IO Basics: Digital Input

## Wiring

Before you get this wired up, you'll need a few components!

Mainly you'll want a Push Button (almost any size button should be fine), a resistor (to pull the signal wire's voltage up to a high level - 3volts), and a few wires (or Jumper Cables).

Have a look at the shopping list below, then check your existing components for any matching resistors / buttons, or pickup a few from the store.

## Parts

For this example, we are using an&nbsp;Adafruit ESP32-S2 TFT Feather.

This board is&nbsp; **perfect** &nbsp;for IoT projects as it includes&nbsp;all the&nbsp;features of a Feather main board: the comforting warmth of an ESP32-S2 WiFi microcontroller, and the crispness of a 240x135 pixel color TFT display. This feather comes with native USB and&nbsp; **4 MB flash + 2 MB of PSRAM** , so it is perfect for use with CircuitPython, WipperSnapper, or Arduino with low-cost WiFi. Native USB means it can act like a keyboard or a disk drive. WiFi means it's awesome for IoT projects. And Feather means it works with the large community of Feather Wings for expandability.

### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

In Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
![Adafruit ESP32-S2 TFT Feather powered on by a USB- C power source displaying the product tittle in a red, yellow, green, white and blue. ](https://cdn-shop.adafruit.com/640x480/5300-06.jpg)

However, you can use any WipperSnapper-compatible hardware with this tutorial. You will need to modify the pin location as a result since it won't match the Adafruit ESP32-S2 TFT Feather.

You will also need the following additional parts:

### Part: 10K Ohm Resistor
quantity: 1
25 Pack of 10K Ω Resistors (You only need one for this project!)
[10K Ohm Resistor](https://www.adafruit.com/product/2784)

### Part: Breadboard
quantity: 1
Half-Size Breadboard with Mounting Holes
[Breadboard](https://www.adafruit.com/product/4539)

### Part: Jumper Wires
quantity: 1
Breadboarding wire bundle
[Jumper Wires](https://www.adafruit.com/product/153)

### Part: Momentary Pushbutton
quantity: 1
Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack
[Momentary Pushbutton](https://www.adafruit.com/product/1119)

## Wiring
You will need to connect the following pins to the button and 10k resistor:

- Feather&nbsp; **GND** &nbsp;to one side of the momentary button
- Feather&nbsp;**Pin GPIO5 (D5)**&nbsp;to the other side of the momentary button
- Feather&nbsp; **3V** &nbsp;to one leg of a&nbsp; **10k** &nbsp;resistor
- The second leg of the&nbsp; **10k** &nbsp;resistor to the same side of the momentary button as **D5** (left side of button in this image)

**Note:** &nbsp;Resistors are&nbsp;_not_&nbsp;polarized, so the 10k resistor can be connected to the circuit in either direction.

![raspberry_pi_wiring-aiobasics-digital-input-arduino_bb-s2-tft.png](https://cdn-learn.adafruit.com/assets/assets/000/126/027/medium640/raspberry_pi_wiring-aiobasics-digital-input-arduino_bb-s2-tft.png?1699543966)

# Adafruit IO Basics: Digital Input

## Configuring WipperSnapper

Info: 

In the real (physical) world we have electrical components, so to represent that on our WipperSnapper device page in Adafruit IO we also have components! They are like digital twins with the real world electrical components, but before you can use them you have to tell your device which ones to use and how!

So now that you have the physical hardware setup, including the electrical components and wiring, it's time to setup your Button component on the WipperSnapper Device page...

## Add a Component to Your Device
Connect your board to Adafruit IO Wippersnapper and&nbsp;**[navigate to the WipperSnapper board list](https://io.adafruit.com/wippersnapper).**

On this page,&nbsp; **select the WipperSnapper board you're using** &nbsp;to be brought to the board's interface page.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/101/medium800/raspberry_pi_chrome_MpFpPSw6eJ.png?1700242351)

Use the New Component button to bring up the Component Picker window.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/102/medium800/raspberry_pi_a772ixvxt6f.png?1700242493)

Select the **Push Button** component from the New Component window.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/755/medium800/raspberry_pi_Screenshot_2023-11-01_132650.png?1698845247)

The&nbsp; **Create Push Button Component** window will be shown.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/529/medium800/adafruit_io_Screenshot_2023-10-23_125307.png?1698062004)

Change the **Push Button Pin** to match your wiring, if you followed the Wiring guidance above then the pin is **D5 (SCK)**.

Info: 

Adjust the&nbsp; **Return Interval** to be&nbsp; **On Change** instead of Periodically (periodically measures at regular intervals, whereas on-change records a measurement every time the pin value changes)

Enable the option to **Specify Pin Pull Direction** , and select the **Pull Up** radio button.

This is to determine if a logic high (1) or logic low (0) should indicate the pressing of the button. This is determined in our circuit by the resistor pulling the button signal line up to 3 volts when not pushed (logic high). When the button is pushed, the internal switch contacts connect, which joins the other side of the switch to the signal wire (ground becomes connected which takes the signal to zero volts a.k.a. low logic level).

![](https://cdn-learn.adafruit.com/assets/assets/000/126/021/medium800/raspberry_pi_Screenshot_2023-11-09_133516.png?1699542027)

You should now be presented with the Push Button component on your device page.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/108/medium800/raspberry_pi_QKwhMmG6wp.png?1700247433)

Test the circuit by holding the button down until you see the value on the device page change, then release and watch the state return to Unpressed.

![](https://cdn-learn.adafruit.com/assets/assets/000/126/022/medium800thumb/raspberry_pi_digitalio_wippersnapper.jpg?1699542351)

It's worth noting that behind the scenes WipperSnapper + Adafruit IO creates a new data [feed](https://learn.adafruit.com/adafruit-io-basics-feeds/overview) for each component. A [feed](https://learn.adafruit.com/adafruit-io-basics-feeds/overview) is where new data values are published or subscribed to, you can see all your feeds on your [Feeds page](https://io.adafruit.com/feeds).

Great, now that's working as expected, it's on to creating the Adafruit IO Dashboard. Head on over to the [Dashboards](https://io.adafruit.com/dashboards "https://io.adafruit.com/dashboards") page.

# Adafruit IO Basics: Digital Input

## Usage

Here you'll create then test an Adafruit IO Dashboard, to allow interactive visualisation and control of your WipperSnapper components (or any other Adafruit IO feed). To get started head on over to the&nbsp;[Dashboards](https://io.adafruit.com/dashboards "https://io.adafruit.com/dashboards")&nbsp;page.

## Build Adafruit IO Dashboard
Click the **New Dashboard** button on the Dashboards page to create a new dashboard.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/125/533/medium800/adafruit_io_oQunx0ZnDX.png?1698074924)

In the **Create a new Dashboard** dialog give the new dashboard an appropriate name, plus a description if you wish, then click the **Create** button.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/535/medium800/adafruit_io_Screenshot_2023-10-23_162959.png?1698075022)

You will be returned to the list of dashboards, with a new entry for the one you created.

Click the dashboard name in the list to be taken to the new dashboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/536/medium800/adafruit_io_SyvSJLwuv2.png?1698075189)

You'll be presented with an empty dashboard, with a drop-down menu to the right-hand side for Dashboard Edit Controls, which is where the **Create New Block** option is located.&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/125/537/medium800/adafruit_io_2sDDbDwGPL.png?1698075674)

There are also options for editing layout, dark/light mode, block borders, and dashboard privacy (as well as&nbsp;_deleting the dashboard_). You can get a more in-depth learn guide for dashboards [here](https://learn.adafruit.com/adafruit-io-basics-dashboards). For now, click the **Create New Block** option.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/538/medium800/adafruit_io_UehFg43TYQ.png?1698075687)

On the&nbsp; **Create a new block** dialog you'll see a list of available block types.

Click on the **Gauge** block type to start the process of adding the block.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/542/medium800/adafruit_io_1LAMeeVgHX.png?1698077249)

Next, you'll be taken to the **Connect a Feed** page, where you need to select which feed to connect to the Gauge block. Select the new button feed we created then use the **Next Step** button.

Note that the groups/devices in the list can be collapsed/expanded to hide or show their feeds. You may need to expand a group to find your button feed.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/543/medium800/adafruit_io_i0KabPIRmW.png?1698077603)

On the&nbsp; **Block Settings** page change the&nbsp; **Gauge Max Value** to **1** , the **Decimal Places** to&nbsp; **0** , and the&nbsp; **Gauge Label** to anything you like, or blank (an empty value in the box), then press the **Create Block** button.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/550/medium800thumb/adafruit_io_chrome_SL7sKH1PYI.jpg?1698085287)

You may wish to Edit the layout (using the Dashboard Settings drop-down), or just continue onto usage so we can test this thing!

## Usage

While looking at the WipperSnapper Device page, or the Dashboard, **press and hold the button** for a second or two then release.

On the dashboard you'll see the Gauge change from 1 to 0 when the button is held down, and from 0 to 1 when released. The WipperSnapper Device page will show the Push Button component state change between Pressed and Unpressed.

![](https://cdn-learn.adafruit.com/assets/assets/000/125/559/medium800thumb/adafruit_io_digitalio_wippersnapper.jpg?1698092836)

Congratulations, you've successfully completed the guide!

# Adafruit IO Basics: Digital Input

## Python Wiring

## Parts
### Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM

[Raspberry Pi 3 - Model B+ - 1.4GHz Cortex-A53 with 1GB RAM](https://www.adafruit.com/product/3775)
The Raspberry Pi 3 Model B is the most popular Raspberry Pi computer made, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 3 better? How about a&nbsp;_faster_ processor, 5 GHz WiFi, and updated Ethernet chip with PoE capability?...

In Stock
[Buy Now](https://www.adafruit.com/product/3775)
[Related Guides to the Product](https://learn.adafruit.com/products/3775/guides)
![Angled shot of Raspberry Pi 3 - Model B+](https://cdn-shop.adafruit.com/640x480/3775-11.jpg)

If you're following along with a [Raspberry Pi](https://www.adafruit.com/category/105), we're going to use a T-Cobbler Plus for the IO Basics Projects. This add-on prototyping board lets you easily connect a Raspberry Pi (Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3) to a solderless breadboard.

### Assembled Pi T-Cobbler Plus - GPIO Breakout

[Assembled Pi T-Cobbler Plus - GPIO Breakout](https://www.adafruit.com/product/2028)
 **This is the assembled version of the Pi T-Cobbler Plus. &nbsp;It only works with the Raspberry Pi Model Zero, A+, B+, Pi 2, Pi 3, Pi 4, and Pi 5!** (Any Pi with 2x20 connector)  
  
The Raspberry Pi has landed on the Maker World like a 40-GPIO pinned, quad-USB ported,...

In Stock
[Buy Now](https://www.adafruit.com/product/2028)
[Related Guides to the Product](https://learn.adafruit.com/products/2028/guides)
![Angled shot of Assembled Pi T-Cobbler Plus next to GPIO ribbon cable](https://cdn-shop.adafruit.com/640x480/2028-07.jpg)

### Part: Jumper Wires
quantity: 1
Breadboarding wire bundle.
[Jumper Wires](https://www.adafruit.com/product/153)

### Part: Button
quantity: 1
Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack
[Button](https://www.adafruit.com/product/1119)

## Wiring
![](https://cdn-learn.adafruit.com/assets/assets/000/057/154/medium800/adafruit_io_01_DIG_INPUT.png?1530807006)

You'll need to make the following connections:

- Pi **GND** to a common&nbsp; **ground** rail.
- Pi&nbsp; **GND** &nbsp;to one side of the momentary button.
- Pi&nbsp; **Pin 12** &nbsp;to the other side of the momentary button.

Next, [proceed to the Python Setup Page](https://learn.adafruit.com/adafruit-io-basics-digital-input/python-setup) of this guide.

# Adafruit IO Basics: Digital Input

## Python Setup

If you're following along with a Raspberry Pi, Beaglebone or any other supported small linux computer, we'll use a special library called&nbsp;[**adafruit\_blinka**](https://pypi.org/project/Adafruit-Blinka/)&nbsp;([named after Blinka, the CircuitPython mascot](https://www.adafruit.com/?q=blinka)) to provide the layer that translates the CircuitPython hardware API to whatever library the Linux board provides. It's CircuitPython, on Pi!

![](https://cdn-learn.adafruit.com/assets/assets/000/056/898/medium800/adafruit_io_blinkapi.gif?1530563193)

## Update your Pi and Python
Warning: 

In this page we'll assume you've already gotten your Raspberry Pi up and running and can log into the command line.

Go ahead and **ssh** into your Raspberry Pi via terminal or a ssh client:

`ssh pi@raspberrypi.local`

Run the standard updates:

`sudo apt-get update`

`sudo apt-get upgrade`

and

`sudo pip3 install --upgrade setuptools`

## Make sure you're using Python 3!
The default python on your computer may not be python 3. Python 2 is officially discontinued and all our libraries are Python 3 only.

We'll be using&nbsp;`python3`&nbsp;and&nbsp;`pip3`&nbsp;in our commands, use those versions of python and pip to make sure you're using 3 and not 2

# Install Python Libraries
## Installing Adafruit Blinka Library
Now you're ready to install all the python support

Run the following command to install the Raspberry PI GPIO library:

```
pip3 install RPI.GPIO
```

![](https://cdn-learn.adafruit.com/assets/assets/000/056/897/medium800/adafruit_io_sensors_pip.png?1530562955)

Run the following command to install&nbsp; **adafruit\_blinka**

```
pip3 install adafruit-blinka
```

The computer will install a few different libraries such as&nbsp;`adafruit-pureio`&nbsp;(our ioctl-only i2c library),&nbsp;`spidev`&nbsp;(for SPI interfacing),&nbsp;`Adafruit-GPIO`&nbsp;(for detecting your board) and of course&nbsp;`adafruit-blinka`

## Installing Adafruit IO Python Library
![](https://cdn-learn.adafruit.com/assets/assets/000/057/153/medium800/adafruit_io_iopython.png?1530802075)

We'll also need to install the [Adafruit IO Python Client Library](https://github.com/adafruit/io-client-python)&nbsp;to communicate with Adafruit IO.

Run the following command to install the **Adafruit IO Client for Python**** :**

```
pip3 install adafruit-io
```

Warning: 

## Downloading Example Code
The example code is contained within the Python IO Client's&nbsp;_examples/basics&nbsp;_subdirectory.

Navigate to the root directory of your Pi:

```
cd ~
```

Then, download the latest version of the _adafruit/io-client-python_ repository by running:

```
git clone https://github.com/adafruit/io-client-python.git
```

Navigate to that folder's example folder for the examples:&nbsp;

```
cd io-client-python/examples/basics/
```

That's it! We're all set up.

Next, let's upload some code and learn how it works.

# Adafruit IO Basics: Digital Input

## Python Code

## Code
Before we run the script at the bottom of this page, we'll need to change&nbsp;`ADAFRUIT_IO_USERNAME`&nbsp;and&nbsp;`ADAFRUIT_IO_KEY`&nbsp;to the username and key for your Adafruit IO account.

- If you need the AIO Key, navigate to [your Adafruit IO Profile](https://io.adafruit.com/profile)

```
# Set to your Adafruit IO key.
# Remember, your key is a secret,
# so make sure not to publish it when you publish this code!
ADAFRUIT_IO_KEY = 'YOUR_AIO_KEY'

# Set to your Adafruit IO username.
# (go to https://accounts.adafruit.com to find your username)
ADAFRUIT_IO_USERNAME = 'YOUR_AIO_USERNAME'
```

We're going to set up an instance of the feed we created earlier:

`digital = aio.create_feed(Feed(name="digital"))`

In the `while True`&nbsp;loop, we're going to check the value of the button and send it to Adafruit IO. A delay (time.sleep()) has been added to avoid timing out by sending too many requests to Adafruit IO.

```
while True:
    if not button.value:
        button_current = 1
    else:
        button_current = 0

    print('Button -&gt; ', button_current)
    aio.send(digital.key, button_current)

    # avoid timeout from adafruit io
    time.sleep(1)
```

## Running the Code
Make sure you're within the _/io-client-python/examples/basics_&nbsp;directory.&nbsp;

If you're not sure which directory you're in, you can check this by running `pwd`&nbsp;and you should see the following output from your terminal:

`~/io-client-python/examples/basics`

Let's run the script. In your terminal, run:

`python3 digital-in.py`

You can now press the button, and you should see button presses being sent to Adafruit IO:

```
Button -&gt; 1
Button -&gt; 0
Button -&gt; 1
Button -&gt; 0
```

Check your dashboard on Adafruit IO, and you should see the gauge respond to button presses:

![](https://cdn-learn.adafruit.com/assets/assets/000/057/385/medium800thumb/adafruit_io_raspberry_pi_button.jpg?1531169230)

## Code
https://github.com/adafruit/io-client-python/blob/master/examples/basics/digital_in.py

# Adafruit IO Basics: Digital Input

## Adafruit IO FAQ

## Encountering an issue with your Adafruit IO Arduino Project?

If you're having an issue compiling, connecting, or troubleshooting your project, check this page first.

_Don't see your issue?_&nbsp;&nbsp;[Post up on the Adafruit IO Forum with your issue](https://forums.adafruit.com/viewforum.php?f=56).

### **I encounter the following error when compiling my sketch:**

**`  fatal error: Adafruit_MQTT.h: No such file or directory, `** `#include "Adafruit_MQTT.h"`

The Adafruit IO Arduino library is dependent on our Adafruit IO MQTT Library.

To resolve this error, from the Arduino IDE, navigate to the **Manage Libraries...** option in the **Sketch -\> Include Library** menu.

![adafruit_io_library_menu.png](https://cdn-learn.adafruit.com/assets/assets/000/065/260/medium640/adafruit_io_library_menu.png?1541529617)

To resolve this error, from the Arduino IDE, navigate to the **Manage Libraries...** option in the **Sketch -\> Include Library** menu.

![adafruit_io_mqtt_install.png](https://cdn-learn.adafruit.com/assets/assets/000/065/259/medium640/adafruit_io_mqtt_install.png?1541529632)

### 

Your board is not connecting to Adafruit IO, but why? Let's find out:

**First** , check in&nbsp;`config.h`&nbsp;that you have the correct&nbsp;`IO_USERNAME`,&nbsp;`IO_KEY`,&nbsp;`WIFI_SSID`, and&nbsp;`WIFI_PASS`&nbsp;are set correctly.&nbsp;

**Next** , we're going to modify the while loop which waits for an IO connection in your sketch. Change the line in the status check loop from&nbsp;`Serial.println(.);`to&nbsp;`Serial.println(io.statusText());`

`// wait for a connection`  
`while(io.status() < AIO_CONNECTED) {`  
`Serial.println(io.statusText());`  
`delay(500);`  
`}`

Verify and re-upload the sketch. If you're receiving a&nbsp; **Network disconnected&nbsp;** error message, the board is not able to talk to the internet. Re-check your hardware, connections, and router settings.&nbsp;

If it's still not showing&nbsp; **Adafruit IO connected** ,&nbsp;check the&nbsp;[IO status on the Adafruit Status page](https://status.adafruit.com/)&nbsp;to make sure the service is online.

### 

Possibly - you can check&nbsp;[IO status on the Adafruit Status page](https://status.adafruit.com/).&nbsp;

### 

There's a&nbsp;[monitor page built-into Adafruit IO](https://io.adafruit.com/monitor)&nbsp;which provides a live view of incoming data and error messages. Keep this page open while you send data to your Adafruit IO devices to monitor data and errors.&nbsp;


## Featured Products

### Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT

[Adafruit ESP32-S2 TFT Feather - 4MB Flash, 2MB PSRAM, STEMMA QT](https://www.adafruit.com/product/5300)
We've got a new machine here at Adafruit, it can uncover your deepest desires. Don't believe me? I'll turn it on right now to prove it to you! What, you want unlimited mozzarella sticks? OK well, that's not something we can provide. But we can provide your...

In Stock
[Buy Now](https://www.adafruit.com/product/5300)
[Related Guides to the Product](https://learn.adafruit.com/products/5300/guides)
### Raspberry Pi 5 - 4 GB RAM

[Raspberry Pi 5 - 4 GB RAM](https://www.adafruit.com/product/5812)
The Raspberry Pi 5&nbsp;is the newest Raspberry Pi computer, and the Pi Foundation knows you can always make a good thing _better_! And what could make the Pi 5 better than the 4? How about a&nbsp;_faster_ processor, USB 3.0 ports, and an updated Gigabit Ethernet chip with PoE...

In Stock
[Buy Now](https://www.adafruit.com/product/5812)
[Related Guides to the Product](https://learn.adafruit.com/products/5812/guides)
### Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack

[Tactile Switch Buttons (12mm square, 6mm tall) x 10 pack](https://www.adafruit.com/product/1119)
Medium-sized clicky momentary switches are standard input "buttons" on electronic projects. These work best in a PCB but [can be used on a solderless breadboard as shown in this tutorial](https://learn.adafruit.com/adafruit-arduino-lesson-6-digital-inputs?view=all). The...

In Stock
[Buy Now](https://www.adafruit.com/product/1119)
[Related Guides to the Product](https://learn.adafruit.com/products/1119/guides)
### Half Sized Premium Breadboard - 400 Tie Points

[Half Sized Premium Breadboard - 400 Tie Points](https://www.adafruit.com/product/64)
This is a cute, half-size breadboard with&nbsp;400 tie points, good for small projects. It's 3.25" x 2.2" / 8.3cm&nbsp;x 5.5cm&nbsp;with a standard double-strip in the middle and two power rails on both sides.&nbsp;You can pull the power rails off easily to make the breadboard as...

Out of Stock
[Buy Now](https://www.adafruit.com/product/64)
[Related Guides to the Product](https://learn.adafruit.com/products/64/guides)
### Adafruit Pi T-Cobbler Plus Kit Breakout for 2x20 Raspberry Pi

[Adafruit Pi T-Cobbler Plus Kit Breakout for 2x20 Raspberry Pi](https://www.adafruit.com/product/1989)
The Raspberry Pi A+/B+/Pi 2/Pi 3/Zero has landed on the Maker World like a 40-GPIO pinned, quad-USB ported, credit card sized bomb of DIY joy. And while you can use most of our great Model B accessories by hooking up our [downgrade cable,](https://www.adafruit.com/product/1986)...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/1989)
[Related Guides to the Product](https://learn.adafruit.com/products/1989/guides)
### Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25

[Through-Hole Resistors - 10K ohm 5% 1/4W - Pack of 25](https://www.adafruit.com/product/2784)
ΩMG! You're not going to be able to resist these handy resistor packs!&nbsp;Well, axially, they&nbsp;do all of the resisting for you!

This is a **25 Pack of 10K Ω Resistors.** More specifically, they are **carbon film** , through-hole...

In Stock
[Buy Now](https://www.adafruit.com/product/2784)
[Related Guides to the Product](https://learn.adafruit.com/products/2784/guides)
### Breadboarding wire bundle

[Breadboarding wire bundle](https://www.adafruit.com/product/153)
75 flexible stranded core wires with stiff ends molded on in red, orange, yellow, green, blue, brown, black and white. These are a major improvement over the "box of bent wires" that are sometimes sold with breadboards, and faster than stripping your own solid core wires. Makes...

In Stock
[Buy Now](https://www.adafruit.com/product/153)
[Related Guides to the Product](https://learn.adafruit.com/products/153/guides)

## Related Guides

- [Adafruit ESP32-S2 TFT Feather](https://learn.adafruit.com/adafruit-esp32-s2-tft-feather.md)
- [Adafruit IO Basics: Color](https://learn.adafruit.com/adafruit-io-basics-color.md)
- [Adafruit IO Basics: Digital Output](https://learn.adafruit.com/adafruit-io-basics-digital-output.md)
- [Playing Animated GIF Files in CircuitPython](https://learn.adafruit.com/using-animated-gif-files-in-circuitpython.md)
- [Adafruit IO Basics: Analog Input](https://learn.adafruit.com/adafruit-io-basics-analog-input.md)
- [RPi Stock Alert Alarm](https://learn.adafruit.com/rpi-stock-alert-alarm.md)
- [Raspberry Pi Azure IoT Hub Dashboard with CircuitPython](https://learn.adafruit.com/raspberry-pi-iot-dashboard-with-azure-and-circuitpython.md)
- [Forecast the Weather at Home with a No-Code Barometer ](https://learn.adafruit.com/dps310-analog-barometer.md)
- [Blinka Says Tabletop Arcade Game](https://learn.adafruit.com/blinka-says-tabletop-arcade-game.md)
- [Getting Started with Microsoft Azure and CircuitPython](https://learn.adafruit.com/getting-started-with-microsoft-azure-and-circuitpython.md)
- [PyLeap ESP32-S3 TFT Boxing Glove Tracker w/ Adafruit IO](https://learn.adafruit.com/esp32-s2-tft-boxing-glove-tracker-w-adafruit-io.md)
- [HID Reporter](https://learn.adafruit.com/hid-reporter.md)
- [CircuitPython Web Workflow Code Editor Quick Start](https://learn.adafruit.com/getting-started-with-web-workflow-using-the-code-editor.md)
- [File Glider](https://learn.adafruit.com/file-glider.md)
- [Mini Weather Station ESP32-S3 TFT](https://learn.adafruit.com/mini-weather-station-esp32-s2-tft.md)
- [Feather TFT STEMMA Case](https://learn.adafruit.com/feather-tft-stemma-case.md)
