Alexa skill for Arduino MKR
Introduction
Section titled â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.
- Set up the Arduino IoT Cloud
- Create a program that controls the RGB LEDs
- Install the Arduino Skill on the Alexa app
- Sync the Arduino IoT Cloud with Alexa
Requirements
Section titled âRequirementsâ- Arduino IoT Cloud
- Arduino Alexa skill
- Arduino MKR WiFi 1010 which you can buy on the official store
- Arduino MKR IoT Carrier which you can buy in the Arduino OplĂ IoT Kit
Hardware Setup
Section titled â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
Section titled â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
Section titled â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.
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.
Your device should now show up, and you will need to click on the âConfigure
â button.
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!
Creating a Thing and link your device
Section titled âCreating a Thing and link your deviceâ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.
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
Section titled â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 network details
Section titled â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
Section titled â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
Section titled â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
Section titled âInstall the Arduino Alexa SkillâThe steps necessary to install the Arduino Alexa Skill are:
- Open the Amazon Alexa app and tap on Devices
- 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.
- If you search for âArduinoâ youâll see a skill that has that exact name.
- Once selected, youâll need to enable it
- Sync it with your Arduino Cloud, by logging into it. Your Alexa and your Arduino IoT Cloud are now synced!
- Start discovering your devices!
Amazon Alexa devices setup
Section titled â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
Section titled â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
Section titled â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
Section titled âDocumentationâI took inspiration from this article to write this blog post.
Useful links: