NodeMCU IoT Starter Learning Kit Practical Book AHMAD FARID BIN MOHAMAD NUUR MAISYA BINTI MAZNI Politeknik Sultan Haji Ahmad Shah
Published by POLITEKNIK SULTAN HAJI AHMAD SHAH SEMAMBU 25350 KUANTAN Copyright ©2023, by Politeknik Sultan Haji Ahmad Shah. Materials published in this book under the copyright of Politeknik Sultan Haji Ahmad Shah. All rights reserved. no part of this publication may be reproduce or distributed in any form or by means, electronic, mechanical, photocopying, recoding, or otherwise or stored in a database or retrieval system without the prior written permission of the publishers. AHMAD FARID BIN MOHAMAD NUUR MAISYA BINTI MAZNI eISBN: 978-967-2766-77-3
PREFACE Welcome to the exciting world of IoT! This NodeMCU IoT Starter Learning Kit Practical Book is your starting point for understanding and creating smart, connected systems. Internet of Things is all around us, from smart homes to industries. It's about making everyday things smarter and more useful. This kit is designed to help you get hands-on with IoT. You will learn to write simple code and connect it to real world hardware. Throughout the eBook, you will find fun projects to practice what you learn. These projects are meant to be both educational and enjoyable, helping you apply your knowledge in practical ways. Furthermore, we will provide you the steps to develop PCB trainer kit board. Remember, this eBook is just the start. IoT is always evolving, so feel free to explore and adapt what you learn here to your own projects. Happy learning and creating!
CONTENTS Blynk Apps EasyEDA Software 03 16 Appendix 37 Introduction 02 Arduino IDE 12 Components 20 Practical Works 26 Exercises 34
INTRODUCTION NodeMCU iot is introduced to help students learn the basics of using esp8266 with the help of some basic components such as by OLED, relay and led. This kit comes with coding to give basic knowledge in using esp8266. Among the advantages of this kit is that the user does not need to connect wiring to the component, the coding is ready available and can be easily repaired if damage occurs. Even so, the main purpose of its introduction is to make it easier for users to learn esp8266 with simple project. User will be revealed with blynk application and Arduino software. In this manual, users or students will be shown how to draw schematic circuits and PCBs using easyEDA software. Then students or users will learn how to set up blynk apps to control the NodeMCU iot kit, and finally before students or users control the macu iot node, students or users will learn how to make programming using Arduino to program the esp8266 using the coding that has been provided in cloud. It is hoped that this book will benefit lecturers or students or anyone who is interested in learning the basics of ESP8266 PAGE 2
BLYNK APPS What is a Blynk apps? Blynk App: It allows you to create amazing interfaces for your projects using various widgets which are provided. Blynk Server: It is responsible for all the communications between the smartphone and hardware. You can use the Blynk Cloud or run your private Blynk server locally. Website for register: https://blynk.io/ PAGE 3
BLYNK SETUP STEP 1 1. Register blynk account --> https://blynk.io/ --> use email --> fill in information --> get confirmation in the email used to register blynk 2. Once successful register blynk app --> login 3. Click on templates --> new template --> NAME “RELAY MODULE” --> HARDWARE “ESP8266” -->Done. figure 2 PAGE 4 figure 1
4. Click Datastreams --> new datastream --> Virtual Pin --> fill in the information as below figure 3 5. NAME “RLY1” & PIN “V6” --> repeat Step 5 for the 2nd relay 6. NAME “RLY2” & PIN ” 7” 7. Click Web Dashboard --> click do not release the "switch" then place it in the dashboard --> refer to the diagram below. PAGE 5 figure 5 figure 4
8. Set the switch --> click the gear icon on the switch --> set TITLE (OPTIONAL) “SW1” --> select Datastream “RLY1(V6)” --> SAVE 9. Repeat the same steps for the 2nd switch Set the switch --> click the gear icon on the switch --> set TITLE (OPTIONAL) “SW2” --> select Datastream “RLY2(V7)” --> SAVE 10. Finally, click the save button --> refer to the figure below PAGE 6 figure 6
BLYNK SETUP STEP 2 Click search --> New Device --> click From template "we will select the template we have set" --> new devices --> select RELAY MODULE --> refer to the image below --> click Create 1. 2. Congratulations, you have successfully set blynk apps, at the moment blynk apps are still offline because the esp8266 is still not connected to the internet. PAGE 7 figure 7 figure 8
BLYNK HP SETUP STEP 1 download blynk apps fo smart phone 1. 2. click blynk to login --> insert user name --> insert password --> clik login 3. clikto relay modul --> at this time the system in online mood PAGE 8
BLYNK SMARTPHONE SETUP STEP 1 click this symbol --> click + 1. 2. click button --> make sure click to time 3. click "off switch" --> set DATASTREAM to "RLY 1(v6) --> setting MODE "SWITCH" 4. Click Design --> set Title LAMP -- > Style --> Color "green" PAGE 9
BLYNK HP SETUP STEP 1 click & hold "off switch" to adjust the size off button 1. 2. to set LED as indicator --> click wedget box --> find led --> click LED 3. to set the LED indicator --> click LED button --> set DATASTREAM to RLY 1(v6) 4. click Design --> set Title "LED1" --> aligment --> centel --> LED color "RED" PAGE 10
BLYNK HP SETUP 1. Well done, all set 2. Try to click each botton, the color will change everytime the botton click PAGE 11
ARDUINO IDE What is Arduino IDE app? Arduino is an open-source electronics platform based on easy-to-use hardware and software. It's intended for anyone making interactive projects. Arduino designs, manufactures, and supports electronic devices and software, allowing people around the world to easily access advanced technologies that interact with the physical world. Website for download : https://www.arduino.cc/en/software PAGE 12
PAGE 13 ARDUINO SETUP STEP 1 1. Open Arduino software 2. File --> preferences --> copy link only into "additional Boards Manager URLs:" a. https://raw.githubusercontent.com/espressif/arduino-esp32 /gh- pages/package_esp32_index.json b. http://arduino.esp8266.com/stable/package_esp8266com_index.json 3. Tools --> Board à Board Manager --> “type = all = ESP8266” --> INSTALL ( lates version) figure 9 figure 10
4. Sketch --> tools --> esp8266 --> NodeMCU 1.0 5. Tools --> select port (make sure the esp8266 is connected to the computer). 6. Enter the coding into the Arduino software 7. Enter the auth char "taken from the token in blynk apps" --> refer to figure below 8. Enter the char auth "internet network" 9. Enter char pass "internet password" PAGE 14 figure 11 figure 12
STEP 2 (Insert Library WiFi ESP8266) 1. Download the Wi-Fi manager library from the link provided @ google "Wi-Fi library for esp8622" 2. https://github.com/ekstrand/ESP8266wifi --> can be downloaded from here. 3. Click sketch --> add file --> select ESP8266 Wi-Fi file --> Open --> refer to the figure 13. 4. click Verify --> done 5. click Upload --> done. 6. If there is no error, you have succeeded. Library dan coding https://drive.google.com/drive/folders/116QslRkAC4HQ2welWecnLnn7zNO_k4c?usp=drive_linkLibrary PAGE 15 figure 13 figure 14
EasyEDA What is the meaning of EasyEDA? EasyEDA is an easier and powerful online PCB design tool that allows electronics engineers, educators, students, makers, and enthusiasts to design and share their projects. it free to use EasyEDA because we promise EasyEDA's core features are absolutely free for everyone. Although the great core features of EasyEDA will always be free, by choosing to pay a monthly subscription of a few dollars you can help us build an even better PCB design tool. Website to download : https://easyeda.com/ PAGE 16
STEP 1 – SCHEMATIC DESIGN 1. click www.easyeda.com --> download software --> register by email 2. Login --> username -->password. 3. File --> new --> project 4. Create New Project --> folder “ x” --> title “ esp8266 relay” --> path “x” --> save 5. Commonly library --> Click resistor --> Click diode 6. Click Library (to find components that are not in the commonly library) ESP8266 Node MCU --> ESP8266 PAGE 17 figure 15 figure 16
Component Part Name relay SRD-05VDC-SLC diode 1N4148 transistor 2N2222 terminal block DOMINO PAGE 18 figure 17 figure 19 figure 18
STEP 2 – CONVERT SCHEMATIC TO PCB 1. CLICK design --> convert schematic to PCB --> CLICK “no Keep Going” 2. CLICK Auto Route --> click on install Local Auto Router --> run as administrator file win64.bat --> CLICK run 3. click 2D 4. click 3D 2D 3D PAGE 19 figure 20
What is ESP8266 used for? What is the ESP8266? The ESP8266 module enables microcontrollers to connect to 2.4 GHz Wi-Fi, using IEEE 802.11 bgn. It can be used with ESP-AT firmware to provide Wi-Fi connectivity to external host MCUs, or it can be used as a self-sufficient MCU by running an RTOS-based SDK. Does ESP8266 need WiFi? Not only can the ESP8266 connect to a WiFi network and interact with the Internet, but it can also set up a network of its own, allowing other devices to connect directly to it. This example demonstrates how to turn the ESP8266 into an access point (AP), and serve up web pages to any connected client. Can ESP8266 connect to mobile hotspot? Things you'll need. A WiFi router/modem, or You can use your mobile hot spot. Your WiFi network name (SSID) and password (WPA). If you need to set up, check or change the WiFi network name or password, you'll need to check your modem's setup guide or user manual for instructions on how to do this ESP8266 PAGE 20 COMPONENTS
RELAY What is relay and its function? What is an Electrical Relay? | OMRON Device & Module . Relays are electrically operated switches that open and close the circuits by receiving electrical signals from outside sources. Some people may associate “relay” with a racing competition where members of the team take turns passing batons to complete the race. PAGE 21 Transistor 2N2222 What is transistor function? The 2N2222 is a common NPN bipolar junction transistor (BJT) used for general purpose low-power amplifying or switching applications. It is designed for low to medium current, low power, medium voltage, and can operate at moderately high speeds. It was originally made in the TO-18 metal can as shown in the picture.
What is the function of LM7805? The LM7805 voltage regulator operates by comparing the output voltage with an internal reference voltage and adjusting the pass transistor accordingly. Its primary function is to regulate the voltage supplied to electronic devices, ensuring they receive a stable and constant +5V DC power source PAGE 22 What is the function of the resistor? A resistor is an electrical component that limits or regulates the flow of electrical current in an electronic circuit. Resistors can also be used to provide a specific voltage for an active device such as a transistor. What does OLED mean? Organic Light-Emitting Diode The acronym 'OLED' stands for Organic Light-Emitting Diode - a technology that uses LEDs in which the light is produced by organic molecules. These organic LEDs are used to create what are considered to be the world's best display panels.
1 Lamp Connection The image below illustrates the connection process of the KIT module to control a lamp through the Blynk website or a smartphone. PAGE 23
2 Lamp Connection The image below demonstrates how to connect the KIT module to control two lamps using either the Blynk website or a smartphone PAGE 24
Relay Connection to Fan In the image below, illustrate how to connect the KIT module for fan control using the Blynk website or a smartphone. PAGE 25
PAGE 26 OLED DISPLAY “ Internet Clock” In the image below, demonstrate how to utilize an internet clock with an OLED display. 1. Download the coding from the link provided. https://drive.google.com/drive/folders/116Q-slRkAC4HQ2welWecnLnn7zNO_k4c? usp=share_link 2. Save it on your computer. Save As "name the file name ". (figure 21) figure 21 Practical Work 1
PAGE 27 3. Set NTP as above for Malaysia, for other countries please refer to "ntp.org" (figure 22) 4. Set "username" and "password" internet. (figure 23) 5. Set "Malaysia local time UTC". (figure 24) 6. Click verify --> if there is an error in the library --> download on the link that has been provided 7. You can also download from the link provided in the coding at the top. (figure 25) figure 25 figure 22 figure 23 figure 24
PAGE 28 8. If there is no error --> click upload make sure the “Board” and “Port” are correct. (figure 26) 9. If everything is finished, the display will come out like the diagram. found that the time displayed on the nodeMcu IOT board is the same as the time in the computer. (figure 27) figure 26 figure 27
PAGE 29 Humidity and Temperature In the image provided below, illustrate the process of creating a humidity and temperature monitor using Blynk and ESP822. 1. Download the coding from the link provided. https://drive.google.com/drive/folders/116QslRkAC4HQ2welWecnLnn7zNO_k4c?usp=share_link. folder name “ HUMIDITY” 2. Save it on your computer. Save As "name the file name ". figure 28 Practical Work 2
PAGE 30 3. Go to blynk web site --> set templates --> HUMIDITY. (figure 29) 4. Set "Datastreams” to V0 to HUMIDITY and V1 to “Temperature”. (figure 30) 5. Set "Web Dashboard” select “gauge “. (figure 31) figure 29 figure 30 figure 31
PAGE 31 6. Set gauge to “humidity” (V0) and “tempe” (V1). (figure 32) 7. Click “save” 8. Go to “Devices” select “New Devices “ and select ”humidity template”. (figure 33) 9. At the humidity select “Device Info” copy “FIRMWARE CONFIGURATION” to Arduino IDE coding declared. (figure 34) figure 32 figure 33 figure 34
PAGE 32 10. Copy and paste at ide arduino coding. (figure 35) 11. Set "username" and "password" internet. (figure 36) 12. Set "DHTPIN to 10 . (figure 37) 13. At ide arduino select tools --> select board nodemcu 1.0(ESP-12E Module) 14. Make sure to select the correct port. 15. Lastly click verify after “Done compiling” click “Upload” and wait until 100% uploading done. (figure 38) figure 35 figure 36 figure 37 figure 38
PAGE 33 16. Once all tasks are completed, you can view the humidity and temperature list image on the Blynk website. Additionally, you can configure this on your smartphone. (figure 39) figure 39
EXERCISE 1 Instructions: By using the appropriate coding, turn on LED3, LED4 and LED 5 using a smart phone and blynk website. PAGE 34
EXERCISE 2 Instructions: By using the appropriate coding, turn ON LED3 & LED 4 automatically at 2.00 PM and OFF at 2.05 PM by using smart phone PAGE 35
EXERCISE 3 Instructions: By using the appropriate coding, turn ON LED3 and RLY 1 automatically at 2.00 PM and OFF at 2.05 PM by using smart phone PAGE 36
APPENDIX A. Pinout reference “NodeMCU ESP8266” PAGE 37
NO COMPONENT FUNCTION 1. "ESP8266" Be the place to process the created program. All inputs and outputs will be controlled by esp8266. Esp8266 will be used together with blynk app and Arduino software. 2. "OLED" As a display 3. "RED LED" As a circuit indicator 4. " GREEN LED" As a circuit indicator RELAY ON/OFF 5. "RELAY" Used as a switch in a circuit (on/off) Uses 5V voltage to operate and can accept ac voltage 0V - 240V 6. SENSOR PORT user for input sensor example DHT11 sensor B. Component Functions AUDIENCE PAGE 38
Label GPIO Safe to use? Reason D0 GPIO16 HIGH at boot, used to wake up from deep sleep D1 GPIO5 D2 GPIO4 D3 GPIO0 connected to FLASH button, boot fails if pulled LOW D4 GPIO2 HIGH at boot, boot fails if pulled LOW D5 GPIO14 D6 GPIO12 D7 GPIO13 D8 GPIO15 Required for boot, boot fails if pulled HIGH RX GPIO3 Rx pin, used for flashing and debugging TX GPIO1 Tx pin, used for flashing and debugging CLK GPIO6 Connected to Flash memory SDO GPIO7 Connected to Flash memory CMD GPIO11 Connected to Flash memory SD1 GPIO8 Connected to Flash memory SD2 GPIO9 Connected to Flash memory SD3 GPIO10 Connected to Flash memory A0 ADC0 Analog input pin, cannot be configured as output PAGE 39 Top priority pins Pay close attention because their behavior, particularly during boot, can be unpredictable Avoid using these pins C. Which ESP8266 GPIOs are safe to use? https://lastminuteengineers.com/esp8266-pinout-reference/