As an alternative to using CircuitPython, more advanced coders may wish to program the project using the Arduino IDE.

Setup Arduino

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. 

You will need to make sure you have at least version 3.7.0 of the Adafruit IO Arduino library installed before continuing.

For this example you will need to open the adafruitio_25_scheduled_trigger example in the Adafruit IO Arduino library.

Configure Sketch

Before uploading the code, you'll need to configure the sketch to include your Adafruit IO account and network credentials. 

Click on the config.h tab in the sketch. You will need to set your Adafruit IO username in the IO_USERNAME define, and set your Adafruit IO key in the IO_KEY define.

Set your WiFi SSID after the WIFI_SSID define and your WiFi password after the WIFI_PASS define.

You will also need to uncomment the line:


Code Usage

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.

This sketch continuously checks the relay feed for new values. 

Every weekday at 8AM, the scheduled action publishes the value "morning" to your relay feed.

When the feed updates with a new value, the sketch's handleMessage() function executes and checks if the value matches the text "morning". 

If the feed's value matches the text "morning", the PyPortal's D3 pin is written HIGH. This turns on the outlet and your appliance.

Every evening at 11PM,  the scheduled action publishes the value "night" to your relay feed. The handleMessage() will read the new value, check if it matches the text "night", and turns off the outlet.


My appliance is not turning on or off.

First, check your wiring against the assembly and wiring page.

Next, make sure your Adafruit IO feed is named relay and your actions are set up to send the value morning and night every weekday.


Then, navigate to your Feeds page and click the relay feed. If it's been a day since you set up the actions, the values morning or night should be in the feed's value list. If they're not, check the action set up.

This guide was first published on Sep 29, 2020. It was last updated on Jun 18, 2024.

This page (Code with Arduino) was last updated on Mar 08, 2024.

Text editor powered by tinymce.