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:

#define USE_AIRLIFT

Code Usage

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

Download: file
Connecting to Adafruit IO....

Adafruit IO connected.

This sketch continuously checks the relay feed for new values. 

Every weekday at 8AM, the scheduled trigger 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 trigger 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.

Troubleshooting

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 triggers 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 triggers, the values morning or night should be in the feed's value list. If they're not, check the trigger set up.

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

This page (Code with Arduino) was last updated on Nov 06, 2020.