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.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Installing the Arduino IDE Software
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.
Step 2: Opening Arduino IDE
Open the Arduino IDE from your desktop.
Press Ctrl+comma to open the preferences panel.
In the Additional Boards Manager enter the URL shown below and press OK.
Step 3: Open Boards Manager
Open the Boards Manager.
Step 4: Select the ESP 8266 Board Library
The Boards Manager window opens, scroll the window page to bottom till you see the module with the name ESP8266. Once you have found it, select that module, select version and click on the Install button. When it is installed close the window.
Step 5: Selecting the Board
To run My First IoT with Arduino we have to select the Board NodeMCU 1.0 (ESP-12E Module).
This can be done by scrolling down, as shown in the figure above. Press return
Step 6: Connecting to the PC
Connect the MyFirst IoT controller to your computer using the USB cable . When it connects the COM port will be detected and you should see your PC loading the appropriate drivers. Once that has completed go to the device manager and note the Com Port in use (shown in the above figure)
Step 7: My First Program
Now open the File tab and go to the Examples in that enter into Built-in example, go to 01.Basics and click on Blink to open the window.
Now click on tools to select the port: “COM” based on which COM port of the computer the controller connected to. To identify the COM port refer previous steps.
Step 8: Upload Your First Program
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.
Step 9: Adding Libraries
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
Step 10: Get the Blynk Application on Your Smartphone.
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.
Step 11: Create Your First Blynk App.
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.
Step 12: Run the Program
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!
Step 13: How the Code Works....
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).
Step 14: The Blynk Tab
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:
- Issues the command morse.on(); (using a library contained in the include file we included at the very beginning) which switches the LED on.
- Prints "LED On" to the serial interface (pc terminal)
- Sends "LED On" to the Blynk 'value display' widget which we designated at slot 1. It uses the Blynk.virtualWrite(V1, "LED Off"); instruction to do this.
- If a 1 is sent to the controller then it does the opposite of all of this.
Pretty simple eh?