The ESP32 is an affordable, all-in-one, option for connecting your projects to the internet using Adafruit.io IoT platform, Adafruit IO.
In the Arduino IDE, navigate to Sketch -> Include Library->Manage Libraries…
Enter Adafruit IO Arduino into the search box, and click Install on the Adafruit IO Arduino library option to install version 4.0.0 or higher.
When asked to install dependencies, click Install all.
If you do not already have an Adafruit IO account, create one now. Next, navigate to the Adafruit IO Dashboards page.
We’ll create a dashboard to visualize and interact with the data being sent between your ESP32-S2 board and Adafruit IO.
Create a New Dashboard
Name your new Dashboard
Your new dashboard should appear in the list.
- Click the link to be brought to your new dashboard.
We’ll want to turn the board’s LED on or off from Adafruit IO. To do this, we’ll need to add a toggle button to our dashboard.
Click the cog at the top right-hand corner of your dashboard, click Create New Block.
Select the toggle block.
Under My Feeds, enter led as a feed name. Click Create.
Choose the led feed to connect it to the toggle block. Click Next step.
Change Button On Text to 1
Change Button Off Text to 0
Click Create block
Under Block Settings,
Next up, we’ll want to display button press data from your board on Adafruit IO. To do this, we’ll add a gauge block to the Adafruit IO dashboard. A gauge is a read-only block type that shows a fixed range of values.
Click the cog at the top right-hand corner of your dashboard.
In the dashboard settings dropdown, click Create New Block.
Select the gauge block.
Create a feed named button and Click create
Click the button feed and click next step
Under block settings,
- Change Block Title to Button Value
- Change Gauge Min Value to 0, the button’s state when it’s off
- Change Gauge Max Value to 1, the button’s state when it’s on
- Click Create block
Your dashboard should look like the following:
For this example, you will need to open the adafruitio_26_led_btn example included with the Adafruit IO Arduino library. In the Arduino IDE, navigate to File -> Examples -> Adafruit IO Arduino -> adafruitio_26_led_btn.
Before uploading this code to the ESP32-S2, you’ll need to add your network and Adafruit IO credentials. Click on the config.h tab in the sketch.
Obtain your Adafruit IO Credentials from navigating to io.adafruit.com and clicking My Key. Copy and paste these credentials next to
Enter your network credentials next to
Click the Upload button to upload your sketch to the ESP32-S2. After uploading, press the RESET button on your board to launch the sketch.
Open the Arduino Serial Monitor and navigate to the Adafruit IO dashboard you created. You should see the gauge response to the button press and the board’s LED light up in response to the Toggle Switch block.
You should also see the ESP32-S2’s LED turning on and off when the LED is toggled.