Control Your IoT Cloud Kit via Blynk

Use the popular Blynk app to control and change the state of your IoT Cloud Kit through your smartphone.

Components and Supplies

Apps and Online Services

About This Project

In this tutorial, we'll toy around the new IoT Cloud Kit from Arduino, featuring a MKR WiFi 1010, the Environmental Shield and the MKR Relay Proto Shield (among LEDs, breadboards, LEDs and wires).

We are going to control and monitor all data from the device using the popular bottom-up DIY monitoring app Blynk.

Install the App

After you create account / log in to the app, you'll be ask to input the hardware you are using.

Select your hardware.
Select your hardware.

Blynk has a huge user base and try to keep the list of hardware up-to-date. Nevertheless you won't find Arduino MKR1010 in the list, when you'll be ask to choose your hardware. Even if we are using Arduino MRK1010 you can select Arduino MKR1000 at this stage.

Give the project a name: I'll choose env-test. Since today I'm keeling an hacker, I'll choose DarkTheme!

If you do everything all right you'll be sent an auth token to the mail address you specified when registered. Keep this code for you and don't share it to anyone!

Connect Your Blynk App to Your Board

In the Arduino IDE, open the Library Manager, and look for the Blynk library.

Search for the Blynk library.
Search for the Blynk library.

Then open

File>Examples>Blynk>Boards_wifi>Arduino_MKR 1010

Input your data (ssid, password, and token), then upload the code to the board.

I'm assuming you have connected the board to the Environmental Shield and to the Proto Carrier.
I'm assuming you have connected the board to the Environmental Shield and to the Proto Carrier.

In order to check if the connection between the Blynk servers and your board is actually working, you have to press the play button in the top right corner and check if the little red dot disappeared from the lower right corner of the menu, as well as the notification area empty.

Press the playbutton in the top right corner.
Press the playbutton in the top right corner.

I'd like to test if the connection is really working by creating two pushbutton to control relay on D1 and D2.

Test the connection by creating two pushbuttons.
Test the connection by creating two pushbuttons.
Select pin.
Select pin.

If everything is working, by pressing I can hear the Relays ticking on the board.

Let's Add the Extra Data the Environmental Shield Is Providing

As you probably noticed, when defining a PIN you can decide whether it being digital, analog or virtual. We'll import the

Arduino_MKRENV 
Library and send our data as virtual pins.

1#include <Arduino_MKRENV.h>
2// Environmental Shield Data
3float t;
4float h;
5float p;
6float l;

Before the setup() function we are going to declare this function:

1// This function sends Arduino's up time every second to Virtual Pin (5, 6, 7, 8).
2// In the app, Widget's reading frequency should be set to PUSH. This means
3// that you define how often to send data to Blynk App.
4void sendSensor()
5{
6 float h = ENV.readHumidity();
7 float t = ENV.readTemperature();
8 float p = ENV.readPressure();
9 float l = ENV.readLux();
10 // You can send any value at any time.
11 // Please don't send more that 10 values per second.
12 Blynk.virtualWrite(V5, h);
13 Blynk.virtualWrite(V6, t);
14 Blynk.virtualWrite(V7, p);
15 Blynk.virtualWrite(V8, l);
16}

In the

setup()
, we simply remind the board to update Blynk on a certain interval.

1// Setup a function to be called every second
2 timer.setInterval(1000L, sendSensor);

Last but not least, we need to update our

loop() function 
using timer.

1void loop()
2{
3 Blynk.run();
4 timer.run();
5}

Complete Sketch

What If You Want to Automate a Process?

Blynk is really handy if you want to monitor data. If you want to be notified or create an action based on the behavior of the data, you'll have to create this heuristic on Blynk Cloud.

For example, if I want the relay to close when the light is growing over a certain threshold, I'll have to create an event.

Automate with Eventor settings.
Automate with Eventor settings.

Or Blynk app now is like this:

The results.
The results.

Happy Blynking with the IoT Cloud Kit!

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.