Alexa skill for Arduino MKR

post hero image

Introduction

Thanks to Arduino IoT Cloud, Arduino Alexa skill and the WiFi module of Arduino MKR boards it’s very easy to create a powerful IoT device! In this post we’ll set up the Arduino IoT Cloud to manage the Alexa skill that will tell the Arduino MKR WiFi 1010 how to control some RGB LEDs.

Goals

  1. Set up the Arduino IoT Cloud
  2. Create a program that controls the RGB LEDs
  3. Install the Arduino Skill on the Alexa app
  4. Sync the Arduino IoT Cloud with Alexa

Requirements

Hardware Setup

Simply put the Arduino MKR WiFi 1010 inside the Arduino MKR IoT Carrier and plugin a USB-B Mini.

Set up the Arduino IoT Cloud

Navigate to the Arduino IoT Cloud.

Please Note: You will need an Arduino account to use the Arduino IoT Cloud.

Configure a new device

Once you are in the Arduino IoT Cloud, click on the “Devices” tab. This will open a new page which will ask you to add a new device. Click on the “Add device” button.

Configure a new device

You will have an option of either configuring a new Arduino device, or a third party device. Select the “Set up an Arduino device” option.

You will need to connect your cloud compatible board to your computer. You will also need to have installed the Arduino Create Agent. If it is not installed, the set-up wizard will ask you to install it.

Arduino Create Agent not found

Your device should now show up, and you will need to click on the “Configure” button.

Device ready to be configured

You will now be asked to name your device. For this first example I named my board Flower. Click on “Next” to proceed: the board will start to configure. This process may take a few minutes.

Once it is done, we will be directed to the devices page, where we can see our device. Congratulations, you have just made your first device IoT ready!

You are all set

After your device is configured, you can move on to the next step: creating your very first Thing. Click on the “Things” tab: you should now see a button that says “Create thing”, which you’ll need to click.

Create your first thing

You can now see an interface with multiple options. This is your Thing configuration overview. You can select what network you’re connecting to, what device you’re using and create variables that you want to sync.

Let’s start by linking your configured device, by clicking on the “Select Device” button to the right. This will open up a window, where you can “Associate” the board with this Thing.

Create the RGB variable

After your device is configured, you need to create the variable that will store the R, G, B data that will be retrieved from Alexa. Click on the “Add Variable” button in the Thing overview.

Name the variable Led, and as variable type, select Colored Light under the Alexa compatible data types. Then click on “Add Variable”.

Add Variable pop-up modal

Add network details

Now that you have created a variable, you can configure the network details to allow the Arduino MKR WiFi 1010 to connect to the Internet. This is done by clicking on the “Configure” button in the “Network” section.

Write the sketch code

With all configurations done, you can move onto creating the program. By clicking on the Sketch tab, you can start editing the code right away.

When, later on, you will connect the cloud to Alexa, the data will be received directly from the Alexa app. Whenever the data updates, the onLedChange() function will execute, where it will fetch the data from Alexa (the RGB values) and light up the Carrier’s LEDs with the right color.

You can find the full code in the snippet.

Upload the code in the snippet above to your MKR WiFi 1010 board. When it has successfully uploaded, go to the Serial Monitor tab to initialize the program.

Set up Alexa

You’ll now need the Amazon Alexa app (which you can download from the Apple App Store or the Google Play Store).

Install the Arduino Alexa Skill

The steps necessary to install the Arduino Alexa Skill are:

  1. Open the Amazon Alexa app and tap on Devices
  2. Tap on the Enable Smart home skills button: you’ll now see a list of featured ones, where we need to search for the right skill.
  3. If you search for “Arduino” you’ll see a skill that has that exact name.
  4. Once selected, you’ll need to enable it
  5. Sync it with your Arduino Cloud, by logging into it. Your Alexa and your Arduino IoT Cloud are now synced!
  6. Start discovering your devices!

Amazon Alexa devices setup

After waiting a little, you should see a new screen appear, where it says that it found a light and gets connected.

Click “Set Up Device”. If you like, you can also add it to a group (this way you can control and organize your devices more easily), otherwise skip this part. I added the device in a group called “Bedroom” so I can easily control the lights and the music in my bedroom.

Control the lights

To control the lights on our setup, you’ll need to head over to the Devices tab in the Alexa app, click on the “Lights” button (where you can see all the available lights). If you have other lights already connected, they will appear here as well. In my case, I only have Led, which is the same name as the variable created earlier in the Arduino IoT Cloud. If you click on Led you’ll access the color and brightness control.

You can now ask Alexa to turn on or off Led! Here are some examples of what you can say to your Alexa device to control the Arduino MKR LEDs.

  • ”Alexa, turn Bedroom red” (if your Led device is placed inside a Bedroom group)
  • “Alexa, turn Led yellow"
  • "Alexa, turn Bedroom off”

Conclusion

This is the very first IoT Arduino Device you can build in few hours without having to think about developing your own Alexa skill nor having to deal with a wiring jungle.

I really loved this project because it gives a taste of the Arduino IoT Cloud potential. I can’t wait to develop a thousand of other IoT projects like this (but more complex, off course) and share my journey with you!

Documentation

I took inspiration from this article to write this blog post.

Useful links: