[Arduino development] two modes of Lesson1 NodeMCU connecting the Internet of things

NodeMUC development Lesson1

1. Circuit diagram of development board

GPIO: general I / O pin, corresponding to the pin corresponding to ESP8266 chip (blue in the figure)

ADC: start with a, analog pin

Vin: another way to power NodeMCU

3V3: provide 3.3v voltage for the outside world


  • Digital pin: as an input, it cannot be higher than 3.3v, otherwise it will damage the development board (and the output voltage can only be 3.3v)
  • Analog pin: the input cannot be higher than 1v

The black words on the light blue background are: Communication pin

  • serial communication
  • SPI communication

Black background: storage unit operation port

U0TXD: send data out (Transf)

U0RXT: receive data inward


  • RST: reset key
  • FLASH: used to brush firmware

2. Internet of things development foundation

2.1 access point mode

The MCU is used as a public wireless router to connect the computer to this access point

#include <ESP8266WiFi.h>

// Create Wifi name
const char *ssid = "FeverESP";
// Wifi password
const char *password = "fevertwice";

void setup() {
  // Start serial communication
  Serial.begin(9600); // Start serial communication

  // Start Wifi established by MCU
  WiFi.softAP(ssid, password);

  // Display window information
  Serial.print("Access point: "); // Output information through serial port monitor
  Serial.print("IP address: ");   // Notification IP address
  Serial.println(WiFi.softAPIP());  // Return Wifi address through function


void loop() {
  // put your main code here, to run repeatedly:


Open the serial port of IDE editor, and you will be prompted as follows:

Access point: FeverESP
IP address:

Open the command line cmd and use the ping command to successfully connect to the nodemocu interface

WiFi connection

Ping command

3. Wireless terminal mode

The wireless terminal mode realizes the network connection function by connecting to the same network as the computer

#Include < esp8266wifi. H > / / import library
const char* ssid     = "FeverWiFi";      // WiFi connection name
const char* password = "12345678";          // Connect WiFi password
void setup() {
  Serial.begin(9600);         // Start serial communication
  WiFi.begin(ssid, password);                  // Start network connection
  Serial.print("Connecting to ");              // Serial port monitor outputs network connection information
  Serial.print(ssid); Serial.println(" ...");  // Inform the user that nodemocu is trying to connect to WiFi
  int i = 0;                                   // This program statement is used to check whether the WiFi connection is successful

  // status() returns a status message, WL_CONNECTED is a WiFi status code
  while (WiFi.status() != WL_CONNECTED) {      // The return value of WiFi.status() function is determined by the WiFi connection status of NodeMCU. 
    delay(1000);                               // If the WiFi connection is successful, the return value is WL_CONNECTED                       
    Serial.print(i++); Serial.print(' ');      // Here, let nodemocu check the return value of WiFi.status() function every second through the While loop
  }                                            // At the same time, nodemocu will output the connection time to read seconds through the serial port monitor.

  // Output information
  Serial.println("Connection established!");   // Nodemocu will output "Connection established!" information through the serial port monitor.
  Serial.print("IP address:    ");             // The IP address of nodemocu will also be output.
  Serial.println(WiFi.localIP());              // This function is achieved by calling the WiFi.localIP() function. The return value of this function is the IP address of nodemocu.
void loop() {                                   

If you need to connect multiple WiFi network names and WiFi passwords, we can implement it by introducing the WiFi multi function

#Include < ESP8266WiFiMulti. H > / / this program uses the ESP8266WiFiMulti library
ESP8266WiFiMulti wifiMulti;     // Create an esp8266wifi multi object whose name is' WiFi multi '
void setup() {
  Serial.begin(9600);            // Start serial communication
//Store WiFi name and WiFi password through addAp function
  wifiMulti.addAP("FeverWiFi1", "12345678");  // These three statements record three different WiFi network information by calling the function addAP.
  wifiMulti.addAP("FeverWiFi2", "87654321"); 
  wifiMulti.addAP("FeverWiFi3", "13572468"); // The passwords of the three networks are 123456789876543213572468 respectively
  Serial.println("Connecting ...");         // Output information through the serial port monitor to inform the user that nodemocu is trying to connect to WiFi
  int i = 0;                                 
  while (wifiMulti.run() != WL_CONNECTED) {  // WiFi multi. Run(), nodemocu will search the WiFi stored in addAP function in the current environment
    delay(1000);                             // If multiple stored WiFi is found, nodemocu
    Serial.print('.');                       // The WiFi signal with the strongest signal will be connected.
  }                                           // Once the WiFI connection is successful, WiFI multi. Run() will return "WL_CONNECTED". This too

be careful:

  • Here is * * WiFi multi. Run(), which is slightly different from WiFi.begin(ssid, password) * * above
  • Here, the IP address of the WiFi router may change every time it is connected, making the address inconsistent, because the address is randomly assigned by the router

Run and upload the serial port monitor as shown below

Open CMD and try to detect whether nodemocu is connected to the computer

Write at the end

Note: all experiments in this column use the free simulation platform TinkerCAD, and the portal is as follows

Portal: ThinkerCAD

Code reference case Wireless terminal mode of nodemocu development board by Taiji maker

Ladies and gentlemen, I've seen it here. Please use your fingers to praise the blogger 8. Your support is the author's greatest creative power!
Lack of talent and learning. If there is any mistake, please correct it
This article is only for the purpose of learning and communication, not for any commercial purpose. If copyright issues are involved, please contact the author as soon as possible

Tags: C IoT arduino NodeMCU

Posted on Sat, 20 Nov 2021 04:22:00 -0500 by john010117