I have just bought a new board, the NodeMCU ESP8266 ESP-12 Devkit 0.9. This board has more GPIO than the ESP8266 ESP-01, so you can attach more components to it. This is also an Arduino-compatible board, and you can upload sketches to it via the Arduino IDE.
Our goal in this activity is to send commands to three (4) LEDs (connected to digital pins) to turn them on or off, and fetch data from a photoresistor (a.k.a light dependent resistor or LDR), which is connected to an analog pin in the board. To start with, we need the following components:
- One (1) NodeMCU ESP8266 ESP-12/ESP-12E WiFi Module
- Four (4) LEDs (Red, Blue, Green, Yellow)
- Four (4) 220-Ohm Resistors (for the four LEDs)
- One (1) Photoresistor or LDR
- One (1) 10K-Ohm resistor (for the Photoresistor/LDR)
- Breadboard/s (you may need two for the Devkit 0.9 version)
- Jumper wires
Pinout for the board is the following (I will include the pinout for the Devkit 0.9 and the Devkit 1.0, although the actual image used here is of a lower version):
Basically, pinout is the same, except that the Dekvit Version 0.9 has lesser available GPIOs than Devkit Version 1.0. But in this exercise, I will be using pins that are commonly available between the two board versions.
Using the components listed above, we assemble everything on the breadboard:
You might get confused with the pin labeling on the board.
Red pin is connected to pin D5 of the NodeMCU board
Blue pin is connected to pin D6 of the NodeMCU board
Green pin is connected to pin D7 of the NodeMCU board
Yellow pin is connected to pin D8 of the NodeMCU board
Photoresistor is connected to Analog pin A0 via a 10K-Ohm resistor
The actual image is below (I used the Dekvit Version 0.9 here):
I made another one with different components arrangements, but using the same pins still:
Basically, the two “implementations” are exactly the same.
Now that we are done with our setup, we will be needing an IoT platform. We will be using Blynk in this activity. I suggest you download first the Blynk mobile app to your phone. This is available in iOS and Android.
Download the app, and register using it. App is free by the way. Creating an account is pretty simple. Open the app, tap Create New Account, enter your email address and your desired password, then voila! You can start kicking!
Once the account is created, we can start start a new project. On the screen, tap the New Project. New screen will let you name the project, what board to use and how connectivity to the Internet is made. Tapping Create Project, an email will be sent providing you with the Auth Token, and sample sketches which you will be uploading to your board.
You will now be presented with a blank slate. You may now start adding components by tapping on the empty area of the app. Tap on the Button. New button will now be added the the project.
To configure the button, you need to tap it, and a configuration screen for the component pops up:
For LED pin assignment, refer to the schematic descriptions. Now, add three more buttons for Blue, Green and Yellow and connect them to D6, D7 and D8 respectively. Your screen should look like this by now:
One more component to be added is a display component to show the values from our LDR or Photoresistor. Tap on a vacant area of the app. Scroll down to Display, and tap Gauge:
After tapping the Gauge widget, you will see it added to your project:
Tap on the widget to configure it. Assign the component to Analog Pin 0. I changed the label to “Brightness”. You may also change the color by tapping the colored circle next to the label field. Tap OK afterwards.
Now, all of our components are properly labeled:
Now, check your email. You should be able to find an email from Blynk (from dispatcher) with the following details similar to the screenshot below:
The email contains the Auth Token. It also has a link to the sketch generator. Copy the Auth Token, then click on the Sketch generator link. Screenshot of the Sketch generator is somewhat similar below:
In the Sketch generator, you need to select the appropriate values for the fields:
Board : NodeMCU
Connection : ESP8266 WiFi
Auth Token : paste the one from the email
Example : Blynk Blynk (this default example will do)
Now, copy the sketch to the Arduino IDE. Select the appropriate board.Be sure to change the values for the SSID and the password.
I am using NodeMCU Devkit Version 0.9, so I will choose this from the boards. You may opt to choose the latest version of the board if this is what you are using:
After successfully uploading the sketch, the board will now try connect to the wifi access point (as configured in the sketch).
Now open the Blynk app. Tap on the “play” button at the top right portion of the screen:
Provided that the board has successfully connected to the wifi, you receive LDR sensor data and the values will reflect to the Gauge widget. Try to tap on the four buttons randomly to turn on or off the LEDs. You should be able to turn the LEDs on or off.
Then, voila! Your done with an IoT simple project with Blynk and NodeMCU WiFi Module.
This article serves as a documentation for myself, and for others who might want to try this activity.
Thank you very much.