In today’s world of microcontrollers, there have been many inventions and designs concerning the communication over a Wi-Fi network between 2 or more gadgets. Since the appearance of the ESP8266, the Wi-Fi communication between 2 (or more) µC has never been easier. In this article I will give information and a basic example of the NodeMCU-version of the ESP866 (picture on the first page). This wonderful piece of technology can be easily programmed in the Arduino IDE and works together with the Blynk-software. To understand what this article is about and make use of it, I assume you have the basic knowledge of the Arduino µC & Arduino IDE. Without further ado, let’s begin with the basics.
Here I will begin with the basics of the 2 pieces of technology this article is about.
This microchip has been around for about 4 years, but it’s rather beginner-unfriendly. This is due to its lack of breadboard compatibility, just a few GPIO’s to use and its lack of USB to serial interface (meaning that you can’t just plug it into your PC to program it), I’ll talk about an enhanced version of this microchip, the NodeMCU microcontroller. It is a microcontroller because it has the usual digital I/O with PWM pins, a SPI and I²C interface, and of course a USB to serial converter so that it can be easily programmed by plugging it into a PC and using the Arduino IDE, meaning it makes a µC unnecessary. Furthermore, it has a 10-bit analog to digital converter, but most importantly though, it has a built-in ESP8266 microchip, which makes this board fantastic. I have been using it for quite a while now, and it comes very in handy.
This application can be found both in the AppStore and Google Play. It’s basically the interface between your smartphone and the ESP8266. By creating an account, you get access to many controls, displays and even a notification manager for Twitter, your mail address or just notifications from your smartphone.
Including the ESP8266 in the Arduino IDE
With the theory out of the way, we can now begin by integrating the NodeMCU board in the Arduino IDE, to program it.
After opening the Arduino IDE, head over to preferences.
Then, on the bottom of the page, there is a text field for additional board manager.
There, you must put the following link: http://arduino.esp8266.com/stable/package_esp8266com_index.json
Now, head to the Boards Manager, as shown in the picture.
With the Boards Manager open, type in “esp8266” and you will see a package with the ESP8266-based boards. You just must hit install. Congratulations, now you can access the NodeMCU board from Tools → Board.
Including the Blynk library in the Arduino IDE
Now you have the NodeMCU integrated in the Arduino IDE. The next step is to integrate the Blynk library, so that that the µC can communicate with the Blynk App which you downloaded (if you didn’t already do it, head over to the AppStore or Google Play, type Blynk and download the app).
First step: Click Here to Download Latest version of Blynk Library for Arduino IDE
There, you will see a file named Blynk_Release_vx.x.x.zip. (Credits to vshymanskyy for the upload).
After you clicked on it, a download will start. Head over to your downloads folder, search for the file, extract it, then you will get a folder. Once you enter it, you shall see another 2 folders:
Now, enter the libraries folder, select the folders inside and head over to C:\Program Files (x86)\Arduino and open the libraries folder. Now you just have to paste the folders you copied beforehand.
The same treatment gets the tools folder you just downloaded. Copy the files inside, head over to C:\Program Files (x86)\Arduino and open the tools folder and hit paste.
Congratulations! Now you have integrated both the NodeMCU Board and the Blynk library. Now we can start with the real functional principle.
Now, there are many ways to program this board, but I will refer to the easiest one. Head over to File → Examples → Blynk → Boards_WiFi → BlynkBlink → NodeMCU, as shown in the picture.
A new sketch will open, with the example. The main content of the sketch shall look like this:
Very simple, you might think? And you are right. This few commands, once executed, connect your board to your WiFi network and simultaneously connects the Blynk app with the board. Now, in order to upload it to the board successfully, we have to do a couple of things in the sketch and in the Blynk app.
Initialising the connection between the Board and Blynk app
First, head over to your downloaded Blynk app. On the screen, you can either log in using Facebook or create a new account. The next video which I made myself will show you how to create a new project: https://goo.gl/TcZ95Q
When you are finished doing so, you have received an authentication token on the email address you logged in with. You can copy the token for now.
Next step takes place in the example sketch you opened earlier.
You have to paste the authentication token between the apostrophes (“ “) from char auth[ ]. Next, you have to type in the SSID(name) of your network in the ssid[ ] apostrophes, and the password in the pass[ ] apostrophes.
After you have done that, you can upload the sketch, but before that there’s just one more thing to do: you must configure the right board, baud rate and COM Port. To do so, head over to Tools → Board, and in the drop-down menu, select the NodeMCU 0.9, as shown in the picture below
Now that you selected the right board, if you head over to Tools again, you will see that some other options appeared now, but for you only the Upload Speed and Port is relevant. The Upload Speed means how fast the code will be uploaded to your board, and for a safe transfer, select 115200, if not selected automatically. Now I recommend unplugging any other µC or Board from your PC, and connect the NodeMCU Board, with a micro-USB cable. After Windows recognized the device, head over Tools → Port and select the given COMxx. Hit Upload in the Arduino IDE. After compiling, the build-in LED on the Board shall start blinking rapidly. After the upload has been done, you are good to go.
Now, make sure that your Smartphone is connected to the Internet (doesn’t matter if it’s connected to the same WiFi network as the Board). Next, open your previously made project, and in the top-right corner you will see a play symbol. Press it and let the magic happen.
Now, you shall see this. Press the Board-like button left from the Play Button: Here you can see your Board and its online status.
Now, in order to check if everything works fine, you can make a small check: swipe to the left in order to bring up the menu with the controls you can use. From there, click the Button, and it should be placed on your screen. Now click it, and a screen will pop up with the properties of the button. Make sure you configure it like this:
Now for the explanation: the GP16 pin is the build-in LED on the Board. You want to configure it to switch from 1 to 0 when you push the button. It sounds weird, but the build in LED is pulled to VCC when the state is low. Now hit the Play button and the project should start. Press the button and see how the LED goes on and off. Congratulations! You have established a connection between your board and the Blynk app.
Now, after this whole waiting, you are ready to begin with your first basic project.
As a little idea what you can do with this setup: you will need 3 LED’s with the color of your choice. With the help of 3 buttons, you will turn each one on/off.
So as mentioned, you will need 3 LED’s and a breadboard for this setup. A thing you must know is that the digital I/O pins work with a 3.3 V level. So it will output maximum 3.3 V and an input voltage can be maximum 3.3V. We will have to keep that in mind when we calculate the current limiting resistors we will use for the LED’s.
Next step is to calculate the resistors. As we know, the resistance is voltage divided by current. Such an LED can handle maximum 20mA, and with 3.3 V means 3.3V/20mA. The result is 165 Ohms. Now, there are no 165 Ohms resistors, so you have to choose the next bigger value, which is 200 Ohms. Select 3 of them, and you can start wiring everything up, like shown in this simple schematic:
Now, in the Blynk app, delete the previously placed Button, and place 3 new Buttons. Click on the first one and configure the PIN to be GPIO15. This is D8 on the Board. Then go the next button and configure the PIN to GPIO13. This is D7 on the Board. Click on the last button and configure the PIN to GPIO12. This is D6 on the Board. Now hit the Play button and have fun switching the LED’s on and off. Now if you want the LED’s to stay on or off, click the Play button again, which now looks like a Stop-button when the project is running. Now you can edit the buttons again. Click the first one and on the bottom of the properties page you have the option to make the push-button a switch. Just switch the toggle to “SWITCH” from “PUSH”. Now press Play again and enjoy switching the LED’s on/off.
I hope you enjoyed this basic tutorial and learned how much stuff you can do with this Board. If I see your appreciation, there will be more tutorials with advanced setups to follow.
Read Next Article: Using ESP8266 and MIT App Inventor to control a Relay | IoT
Article Content is Protected and Copyrighted © by Mr. Robert Poloboc (DIY Projects Maker)
You should mention that on startup and reset the gpu pins status is uncontrollable
The Imax for a pin in esp8266 is 12mA and the typically in uC is 4mA, if you exceed this 4mA be sure that is in the datasheet
I am having two problems. One is after downloading Blynk application in mobile phone after pressing play button red dot with message ” wasn’t online yet ” appears. what it mean and why it is not going online ? Secondly after successful uploading with token card and SSID with password it shows serial monitor blank and not working at all. Please help.