Warning: Declaration of Db::query($query) should be compatible with mysqli::query($query, $resultmode = NULL) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 29

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Deprecated: Function get_magic_quotes_runtime() is deprecated in /var/www/u1300519/data/www/acoptex.com/_lib/CacheLite/Lite.php on line 757

Warning: Cannot modify header information - headers already sent by (output started at /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php:0) in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 168

Warning: session_start(): Cannot start session when headers already sent in /var/www/u1300519/data/www/acoptex.com/_config/config.php on line 169

Warning: Use of undefined constant MYSQL_NUM - assumed 'MYSQL_NUM' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 92

Warning: Use of undefined constant MYSQL_ASSOC - assumed 'MYSQL_ASSOC' (this will throw an Error in a future version of PHP) in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64

Warning: mysqli_fetch_array() expects parameter 2 to be int, string given in /var/www/u1300519/data/www/acoptex.com/_lib/class.Db.php on line 64
jobs.html_title
15

members

Easy Basics: Project 066d ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3), 5V relay module - protected IO

of Acoptex.com in ESP8266 ESP-12

Basics: Project 066d

Project name: ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3), 5V relay module - protected IOT device control

Tags: ESP, ESP8266, WI FI module, ESP-12E, Ai Thinker, AI-Cloud, SOC, GPIO, General Purpose Input Output, System On a Chip, IOT, internet of things, how to upload sketch, sketch for ESP8266 ESP-12E module, LoLin NODEMCU V3, NODEMCU, V3, Development Board with USB-to-Serial Onboard, NodeMCU DevKit, IOT STARTUP, webserver, 5V relay, 5V relay module, garage door opener, garage door control, protected device control, IOT device control

Attachments: IOTdevicecotrolketch, garagedoorcontrolsketch

WARNING – THIS PROJECT INVOLVES HIGH VOLTAGES THAT CAN CAUSE SERIOUS INJURY OR DEATH. PLEASE TAKE ALL NECESSARY PRECAUTIONS, AND TURN OFF ALL POWER TO A CIRCUIT BEFORE WORKING ON IT. WE ARE NOT RESPONSIBLE FOR ANY DAMAGE, INJURY, DEATH AND OTHER THINGS CAUSED BY THIS PROJECT IMPLEMENTATION. 

In this project, you need these parts :

1. ESP8266 ESP-12E WI FI module with micro USB cable 1pc

2.Arduino IDE ( you can download it from here  )

3.Jumper cables F-M, F-F, M-M

4. Breadboard 1 pc

5. LED 2 pcs (red and green)

6. Resistor 2 pcs (220 Ohm)

7. Magnetic switch 1 set (for garrage door status)

8. 5V relay module 1 pc

 

9. Logical level converter 1 pc (can be resistors - voltage divider)

10. Power supply 5V DC for NodeMCU ESP8266 ESP-12E

General

We will learn how to make a web server that controls any IOT device, garage door. Control buttons protected by 4 digit password.

Understanding the 5V relay

You can read more about it here.

Understanding the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

The ESP8266 WiFi Module is a self contained SOC (System On a Chip) with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network.

The ESP8266 WiFi Module is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.

Each ESP8266 WiFi Module comes pre-programmed with an AT command set firmware, meaning, you can simply hook this up to your Arduino board and get about as much WiFi-ability as a WiFi Shield offers.

The ESP8266 WiFi Module is an extremely cost effective board. This module has a powerful enough on-board processing and storage capability that allows it to be integrated with the sensors and other application specific devices through its GPIOs (General Purpose Input Output) with minimal development up-front and minimal loading during runtime. Its high degree of on-chip integration allows for minimal external circuitry, including the front-end module, is designed to occupy minimal PCB area. The ESP8266 supports APSD for VoIP applications and Bluetooth co-existance interfaces, it contains a self-calibrated RF allowing it to work under all operating conditions, and requires no external RF parts.

In short, the ESP8266 module is a TTL "Serial to Wireless Internet" device, a small microprocessor with built in wi-fi. It is faster than most Arduino boards and has more memory than most Arduino boards and has less pins than an Arduino board.

The ESP8266 comes in a wide variety of versions (as shown in the figure below).

See the module list here.

Application:

  • create a web server
  • send HTTP requests
  • control outputs
  • read inputs and interrupts
  • send emails
  • post tweets

HOW DOES IT WORK

The ESP8266 WI FI module can be controlled from your local wifi network or from the internet (after port forwarding set on your router). The ESP8266 communicates with the Arduino through a serial interface.  It uses the Arduino’s Rx and Tx pins (digital pins 0 and 1) connected to the ESP8266 ESP-12E module for receiving commands and communicates back. The module features a full TCP/UDP stack support and can be configured as a web server. 

ESP8266 ESP-12E module

We will use ESP8266 ESP-12E module in this project. 

Out of the many ESP-NN modules that have been released, ourselves alongside the rest of the ESP8266 community became fond of the FCC-certified ESP-12E, also known as the ESP-12F given that the first versions of the ESP-12E weren't FCC-certified!

The ESP-12E module breaks out all the available ESP8266 pins, and it includes a visible LED for indicating the status of the SoC's Tx pin, which is very useful during programming.  In addition, under the tin can, the ESP-12E a 4MB SPI flash storage IC – typically the Winbond W25Q32FV, and all the necessary components needed for the onboard ESP8266 to operate properly (e.g., crystal, capacitors, resistors). It also includes an onboard antenna with a reasonable range (–70~–80 dBm at 50 feet).

Features:

  • ESP8266 ESP-12E module
  • Built-in USB to Serial UART Adapter (CP2102 or CH340)
  • Reset button
  • Input button (also used for bootloading)
  • Surface-mount, user-controllable red LED
  • 3.3V 500mA voltage regulator (LM1117 or AMS1117)
  • Two diode-protected power inputs (one for a USB cable, another for a battery)
  • No need to press reset/flash for progamming
  • Supports Wi-Fi protocol 802.11 b / g / n;
  • Supported modes Wi-Fi - access point, client;
  • The input voltage is 3.7V - 20V;
  • Operating voltage 3V-3.6V;
  • The maximum current is 220mA;
  • Built-in TCP / IP stack;
  • Operating temperature range from -40С to 125С;
  • 80 MHz, 32-bit processor;
  • Time to wake up and send packets 22ms;
  • Built-in TR switch and PLL;
  • The presence of power amplifiers, regulators, power management systems.

There are several generations of NodeMcu boards - V1 (version 0.9), V2 (version 1.0) and V3 (version 1.0). The designations V1, V2, V3 are used for sale in online stores. Often there is confusion in the boards - for example, V3 is externally identical to V2. Also, all boards work on the principle of open-source, so they can be produced by any company. Amica, DOIT and LoLin / Wemos are the main makers of NodeMcu boards.

V1 and V2 are easy to compare - they have different sizes. Also, the second generation is equipped with an improved modification of the ESP-12 chip and 4 MB of flash memory. The first version, obsolete, is made in the form of a bright yellow platform. It is inconvenient to use it, since it covers 10 outputs of the breadboard. The second generation made to correct this disadvantage - it has become narrower, the outputs are well suited to the board's contacts. The V3 boards same as V2 but have a more reliable USB-output. The LoLin board is manufactured by LoLin, from differences from the previous board, it can be noted that one of the two reserved outputs is used for additional ground, and the second one is for feeding USB power. Also, the board is larger than the previous ones.

The ESP-12E is a great breakout for the ESP8266, however, in order to maintain a small footprint it's been designed without any holes for pin headers. Rather than a breadboard-able module, the ESP-12E is meant to be mounted on a PCB.  Moreover, to further increase the usability of the ESP-12E during rapid prototyping, some power regulation and USB connectivity are necessary.  This is what ourselves and other US-based DIY Electronics vendors have contributed to the ESP8266 ecosystem.  In our case we've developed a board that includes, among other passive components and discrete ICs, a CP2102 or CH340 USB to Serial UART adapter, a NCP1117 (AMS1117) 3.3 VDC Voltage Regulator, a micro-USB connector, and through-hole (male) pin headers.

This board breaks out all the (available) ESP8266 pins to through-hole headers for easy breadboarding.  The board also includes additional GND, Vin, 3.3VDC signals for easy access during development.  This development board for the ESP8266 SoC inside the ESP-12E module is out-of-the-box ready for you to connect it to your computer, install USB drivers, and start writing programs that connect to your Wi-Fi network!

You can find more about NodeMCU DEVKIT V1.0 here.

NodeMCU

NodeMCU is, at the moment, the most popular alternative firmware that runs on the ESP8266.  Based on the eLua project, it runs a Lua interpreter onboard the ESP8266, which is able to execute commands written in the Lua scripting language.  The commands are sent to the ESP8266 via the Serial UART interface.

NodeMCU is a great starting point for Makers as it provides an interactive environment that allows running commands not only for controlling the ESP8266's wireless interface, but also its GPIO and hardware functionality such as PWM.  In addition, we have access to the full scope of the Lua programming language for writing our applications.  In the case of the default firmware (AT+Commands Interpreter), the application code would have to be developed using a programming language suited to the host microcontroller or SoC that would be sending the commands over Serial (e.g., C/C++ for the Atmel/ARM microcontrollers on Arduino boards).

Not only does the NodeMCU firmware allows us to execute commands interactively, but we can save our applications as a script in the ESP-12E's flash memory, and instruct it to run the application code every time it restarts!

ESP8266 ESP-12E module has three operational modes: 

1. Access Point (AP) — In AP, the Wi-Fi module acts as a Wi-Fi network, or access point (hence the name). It allows other devices to connect to it. And establishes a two-way communication between the ESP8266 and the device that is connected to it via Wi-Fi. 

2. Station (STA) — In STA mode, the ESP-12E can connect to an AP (access point) such as the Wi-Fi network from your house. This allows any device connected to that network to communicate with the module. 

3. Both — In this mode ESP-012E act as both an AP as well as in STA mode. Refer to the following site for more ESP8266 AT commands. 

Disadvantages of the NodeMcu module

The main disadvantage is the ability to execute only LUA scripts located in the RAM. This type of memory is small, the volume is only 20 KB, so writing large scripts causes a number of difficulties. First of all, the whole algorithm will have to be divided into linear blocks. These blocks must be written to separate files on the system. All these modules are executed using the dofile operator.

At writing it is necessary to observe a rule - at data interchange between modules it is necessary to use global variables, and at calculation inside of modules - local. It is also important to call the collectgarbage (garbage collector) function at the end of each written script.

ESPlorer

ESPlorer — Integrated Development Environment (IDE) for ESP8266 developers.
The essential multiplatforms tools for any ESP8266 developer from luatool author’s, including a LUA for NodeMCU and MicroPython. Also, AT commands are supported.
Required JAVA (SE version 7 and above) installed.
You can download it here.
Supported platforms
  • Windows(x86, x86-64)
  • Linux(x86, x86-64, ARM soft & hard float)
  • Solaris(x86, x86-64)
  • Mac OS X(x86, x86-64, PPC, PPC64)
Detailed features list
  • Syntax highlighting LUA and Python code
  • Code editor color themes: default, dark, Eclipse, IDEA, Visual Studio
  • Undo/Redo editors features
  • Code Autocomplete (Ctrl+Space)
  • Smart send data to ESP8266 (without dumb send with fixed line delay), check correct answer from ESP8266 after every lines.
  • Code snippets
  • Detailed logging

Signals and connections of LED

The operating voltage of the LED is 1.8V and the operating current is 10mA-20mA. The Arduino Uno board can supply 5V or 3.3V power. We will use 5V for this project, so the minimum resistance of the current limiting resistor should be (5 V to 1.8 V)/20 = 160 Om. The 220 Om offered in the kit is suitable and you can also choose other resistors that meet the condition. The larger the resistance is, the dimmer the LED will get.

Signals and connections of 5V relay

The SRD-05 VDC-SL-C relay has three high voltage terminals (NC, C, and NO) which connect to the device you want to control. The other side has three low voltage pins (Ground, Vcc, and Signal) which connect to the Arduino.

NC: Normally closed 120-240V terminal

NO: Normally open 120-240V terminal

C: Common terminal

Signals and connections of the ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3)

TX - transmit pin. GPIO pin

RX  - receive pin.  GPIO pin

3V3 (or 3V or 3.3V) - power supply pin (3-3.6V). 

GND ( or G) - ground pin.

RST - reset pin. Keep it on high (3.3V) for normal operation. Put it on 0V to reset the chip.

EN - Chip enable. Keep it on high (3.3V) for normal operation.

Vin - External power supply 5VDC.

D0-D8 - GPIO (General Purpose Input Output) pins 

D5-D8 - SPI interface

D1-D2– I²C/TWI Interface

SC (or CMD) - (Chip Select) - the pin that the master can use to enable and disable specific devices. GPIO pin

SO (or SDO) - Master In Slave Out (MISO) - SPI communication. The Slave line for sending data to the master. GPIO pin

SK (or CLK) - SCK (Serial Clock) - SPI communication.The clock pulses which synchronize data transmission generated by the master. GPIO pin

S1 (or SD1) - Master Out/Slave In (MOSI). SPI communication. The Master line for sending data to the peripherals. GPIO pin

S2 (or SD2) - GPIO pin

S3 (or SD3) - GPIO pin

VU (or VUSB) - external power 5VDC.

A0 - ADC output.

RSV - reserved

Wiring

WARNING – THIS PROJECT INVOLVES HIGH VOLTAGES THAT CAN CAUSE SERIOUS INJURY OR DEATH. PLEASE TAKE ALL NECESSARY PRECAUTIONS, AND TURN OFF ALL POWER TO A CIRCUIT BEFORE WORKING ON IT. WE ARE NOT RESPONSIBLE FOR ANY DAMAGE, INJURY, DEATH AND OTHER THINGS CAUSED BY THIS PROJECT IMPLEMENTATION. 

It can be a powerful light or other equipment connected to 5V relay.The relay has two different types of electrical contacts inside – normally open (NO) and normally closed (NC). The one you use will depend on whether you want the 5V signal to turn the switch on or turn the switch off. The 120-240V supply current enters the relay at the common (C) terminal in both configurations. To use the normally open contacts, use the NO terminal. To use the normally closed contacts, use the NC terminal.We will use NO (Normally open)configuration, when the relay receives a HIGH signal the 120-240V switch closes and allows current to flow from the C terminal to the NO terminal. A LOW signal deactivates the relay and stops the current. So if you want the HIGH signal to turn ON the relay, use the normally open terminal.

Make sure that the high voltage connections to the 5V relay module are very well secured. Identify the hot power wire (red wire in the diagram above) in the cord leading to the light bulb and make a cut. Connect the side leading to the light bulb to the NO terminal of the 5V relay, and the side leading to the plug to the C terminal. This way the relay is on the hot side, and current is switched before it reaches the light bulb. It’s dangerous to put the relay on the neutral wire, since if the device fails current can still fault to ground when the relay is off.

1. IOT device control protected by 4 digit password


2. Garage door control protected by 4 digit password


Step by Step instruction

1. Adding ESP8266 platform to Arduino IDE

the Arduino environment has to be set up to make it compatible with the 
ESP-01 module. It is required to have Arduino version 1.6.4 or higher in order to install the ESP8266’s platform packages.

The Arduino environment has to be set up to make it compatible with the ESP8266 ESP-12E module. It is required to have Arduino IDE version 1.6.4 or higher in order to install the ESP8266’s platform packages.

  1. Open Arduino IDE. 
  2. Open the Preferences window from the Arduino IDE. Go to File -> Preferences.
  3. Enter http://arduino.esp8266.com/stable/package_esp8266com_index.json into Additional Board Manager URLs field and click the “OK” button. If you already have a URL in there, and want to keep it, you can separate multiple URLs by placing a comma between them. (Arduino 1.6.5 added an expanded text box, separate links in here by line.)

  4. Open Boards manager. Go to Tools -> Board -> Boards Manager…

  5. There should be a couple new entries in addition to the standard Arduino boards. Look for esp8266. or scroll down to the ESP8266 entry (usually at the bottom). Select the ESP8266 entry. When you click it an install option will appear. Select the latest version and click install
  6. The board definitions and tools for the ESP8266 include a whole new set of gcc, g++, and other reasonably large, compiled binaries, so it may take a few minutes to download and install (the archived file is ~110MB). Once the installation has completed, an Arduino-blue “INSTALLED” will appear next to the entry.

2. Uploading sketch to ESP8266 ESP-12E module 

 If you’re using an ESP-12E NodeMCU Kit, uploading the sketch is very simple, since it has built-in programmer. 

Before use ESP8266 ESP-12E WI FI module (LoLin NODEMCU V3), you need to download the manufacture's driver (CH340)  for this chip and install it in your PC. Here is the link. See the description of driver installation package below: CH340 / CH341 USB to serial WINDOWS driver installation package that supports 32/64 bit Windows 10 / 8.1 / 8/7 / VISTA / XP, SERVER 2016/2012/2008/2003, 2000 / ME / 98, through Microsoft digital signature authentication, support USB to 3-wire and 9-wire serial port, with the product release To the end user. Applicable scope: CH340G, CH340C, CH340B, CH340E, CH340T, CH340R, CH341A, CH341T, CH341H chips.

If you have CP2102 chip then  you need to download the manufacture's driver for this chip and install it in your PC. Driver for Mac, Windows, Linux or more.. 

  1. Do wiring.
  2. Open Arduino IDE.
  3. Plug your ESP8266 ESP-12E module into your PC USB port.
  4. Choose your NodeMCU board. Go to Tools -> Board -> NodeMCU 1.0 (ESP-12E Module)
  5. Select the correct com port.
  6. Replace the SSID and password for the local WiFi network and 4 digit code to control buttons in the IOTdevicecotrolketch with your own data.
  7. Verify and upload the IOTdevicecotrolketch to your ESP8266 ESP-12E module. AT commands will not work after that. You need to Flash the firmware to enable them again.
  8. Open Serial monitor at baud rate of 115200 bps.
  9. You will see the IP address of your ESP8266 ESP-12E module.
  10. Open any browser from a device (PC, cell phone, tablet) that is connected to the same router that your ESP8266 ESP-12E module is.
  11. Type the IP address (for example we had 192.168.0.117) which you have seen in Arduino IDE serial monitor and press Enter button.
  12. You can control IOT device now. You will need to enter correct 4 digit code which you set in sketch - we had 1234. If this code will be correct you will have control.
  13. If you check the serial monitor, you can see what’s happening on the background. The ESP receives an HTTP request from a new client – in this case, your browser. You can also see other information about the HTTP request – these fields are called HTTP header fields, and they define the operating parameters of an HTTP transaction.
  14. If you want to use sketch for garage door control replace the SSID and password for the local WiFi network and 4 digit code to control buttons in the garagedoorcontrolsketch with your own data.
  15. Verify and upload the garagedoorcontrolsketch to your ESP8266 ESP-12E module.
  16. AT commands will not work after that. You need to Flash the firmwareto enable them again.
  17. Open Serial monitor at baud rate of 115200 bps.
  18. You will see the IP address of your ESP8266 ESP-12E module.
  19. Open any browser from a device (PC, cell phone, tablet) that is connected to the same router that your ESP8266 ESP-12E module is.
  20. Type the IP address (for example we had 192.168.0.117) which you have seen in Arduino IDE serial monitor and press Enter button.
  21. You can control your garage door now. You will need to enter correct 4 digit code which you set in sketch - we had 1234. If this code will be correct you will have control. When you press Activate button - it will trigger the garage door opener and will open the garage door. You will probably need to adjust the timing delay between LOW and HIGH signal on the end of the sketch to suit your garage door opener.
  22. Magnetic switch will send the status of your garage door.
  23. If you check the serial monitor, you can see what’s happening on the background. The ESP receives an HTTP request from a new client – in this case, your browser. You can also see other information about the HTTP request – these fields are called HTTP header fields, and they define the operating parameters of an HTTP transaction.

Code

Replace the SSID, password, 4digit code with your own data. You can also specify different server port (we used common 80).

Summary

We have learnt how to make a web server that controls any IOT device, garage door. Control buttons or button protected by 4 digit password.

Library

  • ESP8266WiFi library included in Arduino IDE. 

Sketch

  • You can find it on the begining of this project


Other projects of Acoptex.com
Medium Basics: Project 083w Sipeed Maixduino board - Using PlatformIO IDE of Acoptex.com in Sipeed Maixduino 08-08-2019
Medium Basics: Project 083e Sipeed Maixduino board - Uploading MaixPy of Acoptex.com in Sipeed Maixduino 04-08-2019
Medium Basics: Project 083f Sipeed Maixduino board - Using MycroPython of Acoptex.com in Sipeed Maixduino 04-08-2019

jobs.published_at
jobs.viewed