In this Instructable we will learn how to install Arduino IDE for the My First IoT Device so by the end we can run arduino code on it and control it from your mobile phone.
Install Arduino IDE software from this link http://www.arduino.cc/en/main/software.
After installing an Arduino IDE icon is created on the Desktop.
Click on the right arrow shown in the figure to upload the program to the module. Once the program has uploaded the LED on the controller will blink on and off at one second intervals.
Congratulations - you have just executed your first IoT device. Now lets move onto something a bit more interesting and switch the LED on and off from your mobile phone.
The Arduino compiler makes extensive use of libraries. These are discrete pieces og code that help the device to carry out a multitude of tasks.
Let's do this one at a time.
Download the Blynk zip file shown above. Note where you have stored it.
Open the Sketch tab, take the 'Include Library' option and then 'Add .zip library'. Point the selection screen at the location of the zip file you downloaded and confirm.
After a few seconds the library will be added to your Arduino IDE.
Repeat for the remaining libraries
Go to your phones app store and search for Blynk. Install the Blynk application and run it.
You'll need to provide an email address and a password. Make sure that it is a valid email address because that is where authentication tokens will get sent.
The kind people at Blynk give you 2000 'Energy' units to get you started. As you build more complex projects you will require more 'Energy' which you can buy in the application.
For the moment we are going to delete projects as we move from one example to the next and take advantage of a really neat feature of Blynk the project QR code. We'll get onto that in the next step.
Press the QR symbol at the top of the screen and your camera will switch on.
Aim your camera at the QR code above and Blynk will create the project for you.
Within a few seconds you will get an authentication code sent to you via email.
In the Arduino IDE select File/Examples/My_IOT_Device/Blynk_LED.
The program file will open.
Copy and paste the authentication token you received from Blynk and input your SSID and Password into the screen.
Press the upload arrow button to send the program to the controller.
On the Blynk app press the play button on the top right of the screen.
You'll see an LED button and a status field. Pressing the button will turn the LED on your controller on and off and update the status accordingly.
Congratulations - you can now control your project from anywhere in the World where you have internet access!
This isn't a programming tutorial - but here is an insight into the code and how it works with Blynk.
I have purposely put the code into separate tabs on the Arduino IDE so that you can see the major components. There is no need to do that when you start to program.
Lets look at the Blynk_LED tab first. Other than project authorisation codes, SSID and password you won't need to change this for any of the project examples.
This contains important information about the library in use (#include ).
The setup tab does just that - it runs once as the controller boots up and issues instructions for setup. In this case we are setting up the serial monitor to run at 115200 baud and setting up Blynk and the wifi.
The loop tab does just that - it loops round and round repeatedly executing whatever code is within it. In this case it makes sure that blynk and the timers are running (which we will set up in a different tutorial along with the program, timers and utilities tabs).
Before we look at the code let's just take a look at those two 'widgets' on the Blynk screen.
The 'button' is designated as a 'virtual' pin and we have selected slot 0 for it (V0). It's a widget that generates an output which gets sent to the controller. Note that we have set it as an On/Off switch rather than Push (momentary) switch.
The status indicator is a 'value display' widget and it gets data sent to it from the controller. It has been set up as a virtual pin and we have selected slot 1 for it.
Now lets look at the code.
The first statement - BLYNK_WRITE(V0) - is telling the code to listen for an instruction from Blynk coming from virtual pin 0. Each time that button changes Blynk will send either a 0 or a 1 to the controller - contained in param.asInt().
If a 0 is sent then the controller:
Pretty simple eh?