Introduction
With a beginner’s understanding of Arduinos and the powerful ability to build circuits, write code, sense data, and act on that information, you are now ready to modernize the scope and potential of your Arduino-enabled projects! With the Arduino IoT Cloud and IFTTT platform, you can now cut the cord to your computer and create a connected and animated Arduino. This tutorial will use a simple photoresistor to measure light levels and send an email to subscribers when it gets dark out.
Parts List:
- Arduino MKR WiFi 1010
- Jumper wires
- Breadboard
- Photoresistor
- 10k ohm resistor
- Micro USB cable
Part 1 – Setting up your Arduino IoT
(For more detail, check out this setup guide)
1. Creating an Arduino Account
To start using the Arduino IoT cloud, log in or sign up to Arduino. You can access the Arduino IoT Cloud from any page on arduino.cc by clicking on the four dots menu in the top right corner. You can also go directly to the Arduino IoT Cloud.
2. Creating a Thing
Begin by selecting “Create Thing” to set up your MKR WiFi 1010. The Arduino IoT Cloud requires your computer to have the Arduino Agent installed. The configuration process is quick and easy, and can be done by clicking on the “Select device” button in the Thing overview. Here, select the “Configure new device” option.
3. Creating photoresistor variable
Create a variable for the Dashboard by selecting “Add Variable”. The photoresistor value is an integer voltage level and can be set up as an integer with “Read & Write” permissions. Keep the threshold change at 0 (new values will always be added if they are different from existing values)
4. Connecting to a Network
To connect to a Wi-Fi network, simply click the “Configure” button in the network section. Enter the credentials and click “Save”. This information is also generated into your sketch file!
5. Editing the Sketch
Now that we have configured variables, devices and network settings, we can get to programming our devices!
An automatically generated sketch file can be found in the “Sketch” tab. It has the same structure as a typical .ino file, but with some additional code to make the connection to your network and to the cloud.This sketch reads an analog sensor, and uses the cloud variable to store it. When the sketch has been uploaded, it will work as a regular sketch, but it will also update the cloud variables that we use!
Additionally, each time we create a variable that has the Read & Write permission enabled, a function is also generated, at the bottom of your sketch file. Each time this variable changes, it will execute the code within this function! This means that we can leave most of the code out of the loop() and only run code when needed.
To upload the program to our board, simply click the “Upload” button.
6. Creating a Dashboard
Dashboards are a visual user interface for interacting with your boards over the cloud. Access our dashboards by clicking on the “Dashboards” tab at the top of the Arduino IoT Cloud interface. After creating a new dashboard, add a widget and link it to Arduino Thing and the photoresistor variable.Once it is linked and as long as the board is connected to the cloud, the values will update.
*Note – It can take some time for the data and status of the board to update on the Arduino IoT Cloud website…be patient!
Part 2 – Connecting IFTTT
(For more detail, check out this setup guide)
Step 1 – IFTTT Setup
IFTTT, If This Then That, is a developer platform that allows a wide range of devices and projects to interact together and create smart devices and connected notifications. There is a wide range of applications to explore, but here we will use a simple Webhook integrated into the Arduino IoT Cloud platform to generate email notifications.
- Open maker.ifttt.com and sign in if prompted.
- Click Create in the top right. Select If This.
- In the search field, enter ‘Webhooks’ and select that service.
- Select Receive a web request.
- In the Event Name field, enter IFTTT_Trigger.
- Click the Create trigger button.
- Now, click on Then That. Select the Email service.
- Choose the Send me an email action. If this is your first time setting up an email action, click Connect, and proceed with the configuration as instructed on IFTTT.
- We can now configure the content of the email. Feel free to write any text you would like to include. The default is the variable output: {{Value1}}, {{Value2}} and {{Value3}} will correspond to the variable name (IFTTT_Trigger), the new value, and a timestamp of the change, respectively. Finally, click Create action.
- Both the trigger and action have now been configured. Click Continue.
- Optionally, change the applet title, and click Finish to create the applet.
- Click on your profile picture in the top right, then click My Services. Choose Webhooks at the bottom and click on Documentation in the upper right.
- Write IFTTT_Trigger in {event} field and copy the URL from the curl command (we’ll use it in the next section).
Step 2 – Arduino IoT Cloud Connection
Head back over to the Arduino IoT Cloud to create your connected Thing
- Go to Arduino IoT Cloud. If prompted, sign in to your Arduino account.
- In the Things tab, click CREATE THING.
- Initially, the title will be set to ‘Untitled’. Click on it and give it a name.
- Click ADD and enter the following values:
- Name: iFTTT_Trigger
- Variable type: Counter
- Variable Permission: Read & Write
- Variable Update Policy: On change
- Threshold: 1
- Click ADD VARIABLE to create the variable.
- With the variable created, click Set webhook at the bottom left of the page.
- Paste the URL inside the Webhook URL field and click SET WEBHOOK.
- Open the Dashboards tab, then either open an existing dashboard or click BUILD DASHBOARD.
- Enable the editing mode (notebook symbol) and click ADD. Under the THINGS tab, select the thing you created. Click CREATE WIDGETS with IFTTT_Trigger selected. Make sure that the step size is set to 1.000. Click DONE.
- Test the webhook and IFTTT applet by increasing the counter value. You should receive an email shortly.
Part 3 – Wiring the Photoresistor
To focus on the IoT and notifications setup, the circuitry setup for this tutorial is kept to a minimum.
- Connect the input of the photoresistor to 5V power input
- Connect the output of the photoresistor to the analog input, A0
- Use the 10k ohm resistor to improve the voltage sensitivity of the resistor
- Ground the entire system
Part 4 – Coding in Arduino.cc IDE
Now that we have connected to the Arduino MKR Wifi 1010 board wirelessly, we are able to code directly in the browser-based Arduino IDE. Creating the sketch is quite similar to the desktop version, with a few modifications now that we have added the connected capabilities.
This code will integrate both the Arduino IoT dashboard variables and the IFTTT trigger counter that we created.
Part 5 – Run program & check for notifications and operating dashboard
After saving your file, check that the Arduino is online and powered up (can be connected to computer or powered from an external battery). Compile and upload the file to send the Sketch (Secret Skech included) to the Arduino. *Note: The education plans (free version) in Arduino IoT allow for only 200s of compilation time per day*
Visit your project dashboard and you should start to see readings from the photoresistor populate the live chart
To test the IFTTT trigger, cover the photoresistor (with a dark cloth or box) until the values on the chart read <20. Head over to your email to receive a notification “It’s lights out! Time to Sleep!”.
Congrats on taking Arduino to new heights…best of luck with all of your future cloud-enabled, notification projects!
References:
This tutorial was aggregated and amended from a collection of setup references. For more detail beyond this tutorial or to adjust aspects specific to your project, explore the links below: