Message IOT Training KitRGB Nano20210904.V1Course One
DirectoryLesson 1 Installing IDE1.1 Introduction1.2 Installing Arduino1.3 Installing Libraries1.4 Arduino1.5 Introduction to RGB NanoLesson 2 Light LED2.1 Overview2.2 working principle2.3 Connection description2.4 Code explanation2.5 Upload codeLesson 3 Button control LED3.1 Overview3.2 Connection description3.3 Code explanationLesson 4 Active buzzer4.1 Overview4.2 Connection description4.3 Code explanationLesson 5 Passive buzzer5.1 Overview5.2 Connection description5.3 Code explanationLesson 6 Traffic Light6.1 Overview6.2 working principle6.3 Wiring schematic881013151518181819192015151515171717181919192028282828....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
232525252626282828293030323232333436363637383840414142426.4 Code explanation....................................................................................Lesson 7 Running water light...............................................................................7.1 Overview.................................................................................................7.2 working principle....................................................................................7.3 Wiring schematic....................................................................................7.4 Code explanation....................................................................................Lesson 8 WS2812B...............................................................................................8.1 Overview.................................................................................................8.2 working principle....................................................................................8.3 Characteristics........................................................................................8.4 Wiring schematic....................................................................................8.5 Code explanation....................................................................................Lesson 9 Gradient RGB.........................................................................................9.1 Overview.................................................................................................9.2 Working principle...................................................................................9.3 Wiring schematic....................................................................................9.4 Code explanation....................................................................................Lesson 10 DS1307.................................................................................................10.1 Overview...............................................................................................10.2 LCD1602 Introduction.......................................................................... 10.3 DS1307 Introduction............................................................................ 10.4 Wiring schematic................................................................................... 10.5 Code explanation................................................................................. . Lesson 11 Show temp...........................................................................................11.1 Overview...............................................................................................11.2 Analog Temperature Sensor Introduction............................................11.3 Wiring schematic..................................................................................11.4 Code explanation..................................................................................
Lesson 12 Show temp and humi12.1 Overview12.2 Wiring schematic12.3 Code explanationLesson 13 Ultrasonic module13.1 Overview13.2 Ultrasonic sensor Introduction13.3 Wiring schematic13.4 Code explanationLesson 14 Photosensitive resistance14.1 Overview14.2 Component Introduction14.3 Connection Diagram14.4 Wiring schematic14.5 Code explanationLesson 15 Rotary encoder control RGB15.1 Overview15.2 Project wiring diagram15.3 Code explanationLesson 16 NRF24L01 launch16.1 Overview16.2 Project wiring diagram16.3 Code explanationLesson 17 Infrared control LED17.1 Overview17.2 Project wiring diagram17.3 Code explanationLesson 18 Infrared control RGB18.1 Overview4444444547474748485050505253535555555557575757606060616363.............................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................
18.2 Project wiring diagram......................................................................... 63 18.3 Code explanation..................................................................................63 Lesson 19 Bluetooth control RGB.........................................................................6619.1 Overview...............................................................................................66 19.2 Connection description........................................................................ 66 19.3 Code explanation..................................................................................67 19.4 Bluetooth remote control.....................................................................69 Lesson 20 ESP8266 Development board..............................................................7120.1 introduction .........................................................................................71End of Course One - Start of Course TwoThe ESP8266 is a Wi-Fi module ideal for Internet of Things and home automationprojects. This article is a beginner's guide to the ESP8266 development board. 20.2 ESP8266 specifications......................................................................... 7120.3 ESP8266 version................................................................................... 72 20.4 NodeMCU pin arrangement peripherals.................................................7320.5 What pins are used in NODEMCU ESP8266?......................................... 73Lesson 21 Installing the ESP8266 development board in the Arduino IDE..........7521.1 Install the ESP8266 plug-in in the Arduino IDE.................................... 7521.2 Test the installation............................................................................ 78 21.3 Wiring Diagram.....................................................................................80Lesson 22 ESP8266 NodeMCU WiFi control traffic light module.........................8122.1 Asynchronous Network Server.............................................................81 22.2 Schematic Diagram ..............................................................................82 22.3 Wiring Diagram.....................................................................................83 22.4 ESP asynchronous Web server code.....................................................85 22.5 How the code works...............................................................................90Lesson 23 ESP8266 Node MCU button control LED........................................... 10123.1 ESP8266 NodeMCU controls digital output....................................... 10123.2 Project example..................................................................................101
23.3 Wiring diagram..................................................................................102 23.4 Working Code....................................................................................102 23.5 ...........................................................................................................103 23.6 Upload code...................................................................................... 105 23.7 Object diagram................................................................................... 105Lesson 24 ESP8266 Controlling LED Brightness (PWM)..................................... 10624.1 ESP8266 NodeMCU PWM.................................................................. 106 24.2 Schematic diagram............................................................................ 108 24.3 Upload code....................................................................................... 110 24.4 Wiring Diagram.....................................................................................110Lesson 25 ESP8266 Node MCU Web Server Control LED Brightness (PWM).... 11125.1 Working Code.....................................................................................112 25.2 Code working principle...................................................................... 116 25.3 Build a web page................................................................................ 117 25.4 Web server Demo.................................................................................125Lesson 26 ESP8266 controls WS2812 lights via Blinker..................................... 12626.1 Arduino configuration......................................................................... 126 26.2 Working Code.......................................................................................128 26.3 App Connection Configuration.............................................................134 26.4 The wiring diagram................................................................................139Lesson 27 ESP8266 NodeMCU displays temperature & humidity in combination with Blinker 27.1 DHT11 Sensor ...................................................................................140 27.2 Install the library................................................................................141 27.3 Working code explanation................................................................. 141 27.4 Wiring Diagram ....................................................................................144Lesson 28 ESP8266 Nodem combined with HC-SR04 Ultrasonic Ranging......... 14828.1 Ultrasonic transducer....................................................................... 148 28.2 Wiring Diagram...................................................................................14928.3 Explanation of working Code............................................................149
Notes:
8/160Lesson 1 Installing IDE1.1 IntroductionThe Arduino Integrated Development Environment (IDE) is the software side ofthe Arduino platform.In this lesson, you will learn how to setup your computer to use Arduino andhow to set about the lessons that follow.The Arduino software that you will use to program your Arduino is available forWindows, Mac and Linux. The installation process is different for all three platformsand unfortunately there is a certain amount of manual work to install the software.STEP 1: Go to https://www.arduino.cc/en/software.The version available at this website is usually the latest version, and the actualversion may be newer than the version in the picture.
9/160Click Windows Installer.STEP2 Download the development software that is compatible with theoperating system of your computer. Take Windows as an example here.Click JUST DOWNLOAD. Also version 1.8.9 is available in the material we provided,and the versions of our materials are the latest versions when this course wasmade.
10/1601.2 Installing ArduinoClick I Agree to see the following interface.
11/160Click NextYou can press Browse… to choose an installation path or directly type in thedirectory you want.Click Install to initiate installation.
12/160Next, the following icon appears on the desktop.Double-click to enter the desired development environment.Finally, the following interface appears, click Install to finish the installation.
13/160Installing Arduino (Mac OS X)Download and Unzip the zip file, double click the Arduino.app to enter ArduinoIDE; the system will ask you to install Java runtime library if you don’t have it in yourcomputer. Once the installation is complete you can run the Arduino IDE.Installing Arduino (Linux)You will have to use the make install command. If you are using the Ubuntu system, itis recommended to install Arduino IDE from the software center of Ubuntu.Installing Additional Arduino Libraries.Once you are comfortable with the Arduinosoftware and using the built-in functions, you may want to extend the ability of yourArduino with additional libraries.Libraries are a collection of code that makes it easy for you to connect to a sensor,display, module, etc. For example, the built-in Liquid Crystal library makes it easy totalk to character LCD displays. There are hundreds of additional libraries available onthe Internet for download. The built-in libraries and some of these additional librariesare listed in the reference. To use the additional libraries, you will need to install them.How to Install a Library? Using the Library Manager. To install a new library into yourArduino IDE you can use the Library Manager (available from IDE version 1.8.9). Open the IDE and click to the "Sketch" menu and then Include Library > ManageLibraries.1.3 Installing LibrariesTroubleshooting tip: If you receive an error during anupload, make sure you have the correct AVR core installed.Tools > Board > Board Manager...
14/160and then Include Library > Manage Libraries.Example: IRromoteOpen Arduino software - project - load library - add a .zip library.Add method two:Copy the library folder to the Libraries folder in the Arduino installationdirectory. Restart Arduino and the added library will take effect.
15/1601.4 Arduino1.5 Introduction to RGB NanoLed: 2-13, built-in LED, connected to pin 2-13, when this pin outputs highArduino is an open source electronic platform based on easy-to-use hardware andsoftware.Suitable for anyone working on interactive projects. Usually, an Arduinoproject consists of circuits and codes.The Arduino board is a circuit board that integrates a microcontroller, input and outputinterfaces, etc. The Arduino board can use sensor s to sense the environment andreceive user operations to control LEDs, and so on. We just need to assemble thecircuit and write the code. Currently, there are several models of Arduino developmentboards, and the codes between different types of development boards are common(due to different hardware, some development boards may not be fully compatible).Popular main control boards include.The 14 digital ports of RGB Nano can be used as digital input or output, defined bypinmode() in the program, and controlled by digitalwrite and digitalread() functionblocks. They work at 5V. Each port provides output current or receives 40 mA current.There is a pull-up resistor inside with a resistance value of 20-50 kOhms. Otherterminals have special definitions.Serial: 0 (Rx) and 1 (TX). Used to receive (Rx) and transmit (TX) TTL serial data.External interrupt: terminals 2 and 3. These external interfaces can beconfigured to generate interrupts later, can be triggered when an external low leveloccurs, or when a rising edge and a falling edge occur. For more information, see theattachinterrupt() function.PWM: 3, 5, 6, 9, 10, 11, provide 8-bit PWM output, use the analogwrite()function.SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication.Although the hardware supports them, they are not included in the Arduino software.
16/160voltage, the LED is on, when outputting low voltage, the LED is off.button: 2, is a built-in button, connected to pin 2, this pin can be used as a pull-upinput, when the software is configured, it can detect whether the button is pressed.buzzer: 8 is the built-in pin, connected to pin 8. A passive buzzer module is connectedto this pin. When this pin outputs a frequency level, the buzzer can make a differentsound.RGB: 13 is a built-in pin, connect to pin 13, this pin integrates WS2812RGB light,you can use software configuration to make it emit different colorsRGB Nano has eight analog inputs, each with a resolution of 10 bits (ie 1024 differentpossibilities). By default, the measured voltage to ground is 5V. Of course, its upperlimit can also be modified by the analogreference() function. Analog pins 6 and 7cannot be used as digital ports. In addition, some ports have many special functions.I2C: A4 (SDA) and A5 (SCL). There are other ports on the board.Aref: Reference voltage of analog input, used with ananlogreference().Reset: Pull down the potential and reset the microprocessor. After pressing thebutton, the whole system can be reset.
17/160
18/160Lesson 2 Light LED2.1 Overview2.2 Working principleThrough this project, you can learn how to use RGB Nano to light up a 10mm LEDmodule. After downloading the program and connecting the line, you will see that theLED light is successfully lit. If it is not lit, you need to check whether the line is correctlyconnected and check whether the pin number of the connected micro controllercorresponds to it.LED (Light Emitting Diode), which converts electrical energy into light energy, also hasunidirectional conductivity and a reverse breakdown voltage of about 5V. Its forwardvolt-ampere characteristic curve is very steep, and the current-limiting resistor must beconnected in series. In a 5V circuit, a resistor of about 400 ohms is generally used. Thelonger of the two pins of the LED is the positive pole. There are two ways to connect,when the positive pole of the led through the current limiting resistor and Arduino.TheI/O port is connected and the other end is grounded. At this time, when the Arduinooutput is high, the led is lit, and when the output is low, the led is off.When the negative pole of the led is connected to the I/O port of the Arduino, theother end is connected to the 5V voltage through the current limiting+ resistor. At thistime.When the output is low, the led is lit, and when the output is high, the led is off.
19/160Define LED signal enable pin.Use the DuPont line to lead the D13 pin of the micro controller to any interface of theJP12 header, plug it in, and the line is successfully connected. The wiring diagram is asfollows. If you do not use a resistor with an LED, then it may well be destroyed almostimmediately, as too much current will flow through, heating it and destroying the'junction' where the light is produced.There are two ways to tell which is the positive lead of the LED and which thenegative.Firstly, the positive lead is longer.Secondly, where the negative lead enters the body of the LED, there is a flatedge to the case of the LED.If you happen to have an LED that has a flat side next to the longer lead, youshould assume that the longer lead is positive.2.4 Code explanation2.3 Connection description
20/160Choose NANO development board.Main function, let 13 pin output high level.Function initialization, define 13 pin as output.2.5 Upload code
21/160Click upload.Click compile.Select port.
22/160Lesson 3 Button Control LED3.1 Overview3.3 Code explanation3.2 Connection descriptionUse DuPont wire to lead the D13 pin of the single-chip microcomputer to any interfaceof the JP12 header, plug it in and the connection is successful, connect the D2 pin ofthe single-chip microcomputer to the S port on the header JP1, and the button wiringis also completed. The wiring diagram is as follows.Through this project, you can learn how to use the input of the RGB Nano controlbutton to light up a 10mm LED light. After downloading the program and connectingthe line, you need to press the WS1 button. After pressing it, you will see the LED lightis successfully lit. After pressing it again, the LED light will go out. If it is not lit, checkwhether the circuit is correctly connected, and check whether the pin number of theconnected microcontroller corresponds to it.
23/160Define LED signal enable pin.Define global variables, which are used as flag bits for buttons and LEDs, functioninitialization, define 13 pin as output, and define 2 pin as input State.The main function is to judge whether the button is pressed, after pressing it, judgewhether it has been pressed according to the flag bit, and determine whether the LEDis lit or extinguished according to the flag bit.
24/160Lesson 4 Active buzzer4.1 Overview4.2 Connection descriptionConnect the D3 pin of the single-chip microcomputer to the S interface of the JP7 rowseat with a DuPont cable, and the connection is successful when it is plugged in.Thewiring diagram is as followsThrough this project, you can learn how to use RGB Nano to make the active buzzersound an alarm. After downloading the program and connecting the line, you will hearan alarm sound from the buzzer. If the buzzer does not sound, you need to checkwhether the circuit is correctly connected, and check whether the pin number of theconnected micro controller corresponds to it.
25/1604.3 Code explanationDefinition Active buzzer signal enable pin is the third pin.The function is initialized, and pin 3 is defined as output.The main function allows the micro controller to output a high level of 500MS andthen a low level of 500MS, so that the active buzzer can sound an alarm.
26/160Lesson 5 Passive Buzzer5.1 Overview5.2 Connection descriptionNo wiring is required in this lesson, because the passive buzzer has been integrated onthe RGB Nano, and the corresponding pin of the passive buzzer is pin D8. If there is nosound when downloading the program, check whether there is a swing switch abovethe buzzer Turn on, this swing switch is the connection switch between the D8 pin andthe passive buzzer, here you need to pay attention!The wiring diagram is as follows.Through this project, you can learn how to use RGB Nano to make a passive buzzersound an alarm. You can hear the sound after downloading the program. This isemitted by the passive buzzer, which is emitted once every 0.5S.
27/1605.3 Code explanationDefine the passive buzzer signal enable pin as the D8 pin.A global flag is defined, and the function is initialized at the same time, and pin8 is defined as an output.The main function is to make the single-chip microcomputer output a level frequency,which can make the passive buzzer sound. After a period of time, the passive buzzercan make an alarm sound. If you want to make the passive buzzer sound all the time ,You can make the "beep_bit" variable always wait for 0.
28/160Lesson 6 Traffic Light6.1 Overview6.2 working principleThe signal light plays a pivotal role in the traffic signal system, serving as thefundamental language of road traffic.Above, we have finished conducting a control experiment involving a single small light.Now, let's move on to a slightly more intricate experiment involving a traffic light. Inessence, observant individuals will notice that this experiment aims to extend thesingle small light experiment to include three colors, allowing us to simulate a trafficlight experiment.The traffic signal light is composed of a red light (signifying no passage), a yellowlight (signifying a warning), and a green light (signifying permission to pass).It is categorized into the following types of signal lights:Motor vehicle signal light & non-motor vehicle signal lightPedestrian crossing signal lightLane signal lightDirection indicator signal lightFlashing warning signal lightRoad and railway plane crossing signal lightThe road traffic signal lamp falls under the category of traffic safety products. It plays acrucial role in enhancing road traffic management, decreasing traffic accidents,optimizing road efficiency, and enhancing overall traffic conditions.It is designed for use at intersections, including T-junctions and other crossing points. Aroad traffic signal control machine manages it to ensure the safe and organizedmovement of vehicles and pedestrians.
29/1606.3 Wiring schematic
30/1606.4 Code explanationThe green light flashes every 500 milliseconds for a total of three timesSet the number 2,3,4 ports to output mode as they are connected to the LEDpositive terminal.Set digital pin 2 to high and the rest to low with a delay of 5 seconds, leaving thegreen light on for 5 seconds.
31/160The red light flashes three times every 500 milliseconds.Turn on the yellow light and turn off the red and green light for 1 second. Then the redlight goes on for five seconds.
32/160Lesson 7 Running Water Light7.1 Overview7.2 Working PrincipleIn this course, you will learn how to control the led on and off to achieve the flowlight function.Small light on RGB-Nano, and can realize the function of light on, off and flashing,and the LED flashing time is set by itself.When the pin output is low, the LED light will not be lit, when the pin output ishigh, the LED light will be lit.To control the light and achieve the effect of a water lamp, multiple pin controlsare necessary. Digital pins 2 through 13 are utilized here to manage the on and offtimes of the light.Creating a Running Water Light Effect:All lights turn off before gradually lighting up from left to right.The sequence starts fast but slows down over time, eventually reaching theslowest flow.This circular process can be customized with different effects according to yourpreference.
33/1607.4 Code explanation7.3 Wiring schematicSpecify two time variables, and proceed to configure pins 2 through 13 to outputmode. First, activate the second light for a set duration, then switch it off.Subsequently, illuminate the third light, pause briefly, extinguish the third light,illuminate the fourth light, and continue in this manner.
34/160From the 13th light on, wait for a period of time to turn off the 13th light, let thetwelfth light on, wait for a period of time, turn off the second light, continue to lightand turn off the next light.
35/160Lesson 8 WS2812B8.1 Overview8.2 Working PrincipleThe WS2812B chip comes with a built-in LED driver, enabling one IO port tomanage multiple LEDs along with functions like brightness and color adjustments.The WS2812B is an intelligent LED light source that features an integrated controlcircuit alongside its luminous circuit.The shape is the same as a 5050 LED lamp bead, and each element is a pixelpoint.The pixel includes a smart digital interface data latch signal shaping amplifier drivecircuit. It also features a high-precision internal oscillator and a 5V voltageprogrammable fixed current control component to ensure the color consistency of thepixel light.The data protocol uses a single-line return-to-zero code communication mode. Whenthe pixel is powered on and reset, the controller transmits data to the DIN end. Thefirst 24-bit data sent is received by the first pixel and forwarded to the data latchwithin the pixel.After internal shaping and circuit shaping, the amplified data is then sent to the nextcascaded pixel via the DO port. With each pixel transmission, the signal is decreased by24 bits.Automatic shaping and forwarding technology is utilized for pixels, allowing thenumber of cascaded pixels to be unrestricted by signal transmission but solely by signaltransmission speed.RGB is integrated on the development board, and the control pin of the RGBlight is connected to pin 13 of the RGB-Nano board.
36/1608.3 Characteristics1. The control circuit and RGB chip are integrated in a 5050 package component,forming a complete external control pixel point.2. Built-in signal shaping circuit, any pixel after receiving the signal through thewaveform .3.Type output, ensure that the line waveform distortion will not accumulate. 4. Built-inpower on reset and power off reset circuit. 5. The three primary colors of each pixelcan achieve 256-level brightness display, complete the full true color display of16777216 colors, and the scanning frequency is not less than 400Hz/s.6. Serial level connection port, through a signal line to complete the datareception and decoding.7. Any two-point transmission distance does not need to increase any circuitwhen it is less than 5 meters.When the refresh rate is 30 frames per second, the cascade number for low-speedmode should be a minimum of 512 points, while for high-speed mode, it should not beless than 1024 points. The data transmission speed can reach up to 800Kbps.9.The color of the light is highly consistent and cost-effective.
37/1608.5 Code explanation8.4 Wiring schematicInitialization of certain settings is required, including setting the baud rate of the serialport to 9600 and initializing the RGB light function.Referring to the library controlling the WS2812B RGB light, since the RGB light signalpin links to the development board processor pin 13, the pin 13 definition in the codecorresponds to the RGB signal pin.
28/160We will move through 12 cycles, corresponding to the 12 lights we have in the matrix.Call the clear function first, and in the for loop, turn the first light on and set the color togreen. Note: (Red, Green, Blue) = (0, 0, 0) in the pixel.setPixelColor (i, pixels.Color(1, 150, 0)
39/160Lesson 9 Gradient RGB9.1 Overview9.2 Working PrincipleWS2812B features a built-in LED driver chip. This course will teach you how to managemultiple LEDs, adjust brightness and colors, and perform other functions using just oneIO port.The pixel contains an intelligent digital interface data latch signal shaping amplifierdrive circuit, also contains a high-precision internal oscillator and 5V voltageprogrammable fixed current control part, effectively ensure the pixel light color highlyconsistent.The data protocol adopts the communication mode of single-line return to zero code.After the pixel is powered on and reset, the DIN end accepts the data transmitted fromthe controller. The first sent 24bit data is extracted by the first pixel and sent to thedata latch inside the pixel.After internal shaping and circuit shaping, the remaining data is amplified andforwarded to the next cascaded pixel through the DO port. Every transmission of apixel, the signal is reduced by 24bit.WS2812B is an intelligent external controlled LED light source integrating controlcircuit and luminous circuit.The shape is the same as a 5050 LED lamp bead, and each element is a pixelpoint.
40/160Automatic shaping and forwarding technology is adopted for pixels, so that thenumber of cascaded pixels is not limited by signal transmission, but only limited bysignal transmission speed.RGB is integrated on the development board, and the control pin of the RGBlight is connected to pin 13 of the RGB-Nano board.9.3 Wiring schematicPay attention to the yellow DuPont wire connecting Pin D13 and JP15 on the RGB-Nanoboard.
41/1609.4 Code explanationDo some initial setup.Referring to the library controlling the WS2812B RGB light, the RGB light's signal pin islinked to pin 13 of the development board's processor. Therefore, the pin 13 definitionin the code corresponds to the RGB signal pin. With a total of 12 lights, the programsets the number of all LEDs to 12.Call the rainbow function with a parameter of 2 milliseconds, which represents thetime delay for each gradient, and call the RGB function after the gradient ends.
42/160
43/160Lesson 10 DS130710.1 Overview10.2 LCD1602 IntroductionIn numerous electronic devices, time-dependent operations are essential. Evenwhen the main system is offline, it's crucial to continue tracking time and date fordevices like computers and mobile phones. This is where the real-time clock (RTC)module comes into play. Here, you'll discover how to utilize the RTC DS1307module effectively.RGB-Nano development board to make a time prompter displayed by the LCD screen.Introduction to the pins of LCD1602:VSS: A pin that connects to ground.VDD: A pin that connects to a +5V power supply.VO: A pin that adjust the contrast of LCD1602.RS: A register select pin that controls where in the LCD’s memory you are writingdata to. You can select either the data register, which holds what goes on the screen,or an instruction register, which is where the LCD’s controller looks for instructionson what to do next.R/W: A Read/Write pin that selects reading mode or writing mode E: An enablingpin that, when supplied with low-level energy, causes the LCD module to executerelevant instructions.D0-D7 Pins that read and write data.A and K: Pins that control the LED backlight.
44/16010.3 DS1307 IntroductionDS1307 is a low power, with 56 bytes of non-volatile RAM full BCD code clock calendarreal-time clock chip, address and data transmission through a two-wire bidirectionalserial bus, the chip can provide seconds, minutes, hours and other information, thedays of each month can be automatically adjusted. It also has leap year compensation.The Real Time Clock, or RTC, is a system that tracks the current Time and can beused with any device that needs to maintain an accurate Time.You can also track the exact time without using an RTC system, but RTC has someimportant advantages. Here are some of them: Release system time from timecalculations (this feature is critical because in many cases the CPU is performingdelicate tasks such as receiving sensor data.If you do not use RTC, the CPU must also track time and it may interrupt theprocessor main task.Real-Time Clock Systems (RTCS) usually come with a backup power source that usesCR2025 button batteries to keep running during power outages. These systemstypically rely on a 32.768kHz crystal oscillator. But why this specific frequency? Thereason behind choosing 32,768 is that it corresponds to 2 to the power of 15,simplifying one-second generation. Moreover, the crystal must be small, reasonablybroad, and energy-efficient, making 32,768 Hz the perfect option to meet theserequirements.The crystal's strength decreases as its frequency increases, while powerconsumption rises as the frequency decreases.
45/16010.5 Code explanation10.4 Wiring schematicBefore the program starts to run, you need to set some initialization Settings, the baudrate of the serial port, the initialization of the display.To simplify and streamline our programming, declare the necessary libraries for thedrive LCD display and DS1307 clock chip. Define the connected pins of the LCD displayand development board as digital ports 7, 8, 9, 10, 11, and 12.Note: Before uploading the code, ensure to modify the current code"DS1307_Write.ino" to match the local time. Once the "DS1307_Write.ino" code isuploaded successfully, proceed to upload the "DS1307.ino" code. Upon completion,the device will display the correct local time.
46/160Print the date and time in the serial port.Call the function of DS1307. You need to write the date into DS1307 and then read thedata.
47/160
48/160Lesson 11 Show Temperature11.1 Overview11.2 Analog Temperature Sensor IntroductionThroughout this lesson, you will discover how to utilize the LCD 1602 display toshowcase temperature data. This display features LED backlighting and canexhibit two lines, each containing a maximum of 16 characters.You can see the rectangles of each character and the pixels that make up eachcharacter on the monitor.The monitor is blue and white and is used to display text. In this lesson, we willrun the LCD library's RGB-Nano board temperature display routine.A thermistor is a specialized resistor that varies its resistance according totemperature, exhibiting a stronger correlation than regular resistors. The term"thermistor" is a blend of "thermal" and "resistor." Thermistors serve various purposessuch as inrush current limitation, temperature sensing (usually NTC type), automaticovercurrent protection, and self-regulating heating components.SpecificationModel No: NTC-MF52 39503PinTemperature Range : ~55℃~+125℃Accuracy :+/-0.5℃Pull-up resistor : 10KΩ
49/160Thermistor PINOUT CONFIGURATION: S = Signal + = +5V - = 0V or GNDCall LCD display library, define analog interface A0 to connect analog temperaturesensor. Define the pins that connect the LCD display to the development board asdigital ports 7, 8, 9, 10, 11, 12.11.3 Wiring schematic11.4 Code explanation
50/160The serial port baud rate is set to 9600, and the LCD screen is initialized.The simulated data of the simulated temperature sensor is obtained and displayedon the serial port debugging window and LCD screen after calculation.
51/160Lesson 12 Show Temperature and Humidity12.1 Overview12.2 Wiring schematicIn this lesson, you will learn how to connect and use a display screen to displaydata measured by a temperature and humidity sensor.The display has LED backlighting and can display two lines of up to 16 characterseach.You can see the rectangles of each character and the pixels that make up eachcharacter on the monitor.The display is blue and white and is used to display text. In this lesson, we will runthe LCD library's RGB-Nano sample program for measuring temperature andhumidity.
52/16012.3 Code explanationInvoke the library of the T/H sensor (DHT11) and LCD display and define the processornumber 2 to connect to the T/H sensor. Define the LCD display and developmentboard connected pins, are digital port 7,8,9,10,11,12 pins.The serial port baud rate is set to 9600, the DHT11 sensor is initialized, and theLCD screen is initialized.
53/160Obtain the humidity and temperature data of the sensor and display them in realtime on the serial port debugging window and LCD screen.
54/160Lesson 13 Ultrasonic module13.1 Overview13.2 Ultrasonic sensor IntroductionIn this lesson, you will learn how to connect and use ultrasonic ranging sensorsand LCD 1602 displays. The display has LED backlighting and can display two linesof up to 16 characters each.You can see the rectangles of each character and the pixels that make up eachcharacter on the monitor.The display is blue and white and is used to display text. In this lesson, we will runthe RGB-Nano sample program to display the ultrasonic sensor measurementdistance information on the LCD 1602 display.Ultrasonic sensor module HC-SR04 provides 2cm-400cm non-contact measurementfunction, the ranging accuracy can reach to 3mm. The modules includes ultrasonictransmitters, receiver and control circuit. The basic principle of work:Using IO trigger for at least 10us high level signal, The Module automaticallysends eight 40 kHz and detect whether there is a pulse signal back.If the signal is returned promptly, it indicates a high level of output during theduration of high IO activity, from sending the ultrasonic signal to its return.Test distance = (high level time × velocity of sound (340m/s) /2. You only need tosupply a short 10us pulse to the trigger input to start the ranging, and then the modulewill send out an 8 cycle burst of ultrasound at 40 kHz and raise its echo. The Echo is adistance object that is pulse width and the range in proportion. You cancalculate the range through the time interval between sending trigger signal andreceiving echo signal. Formula: us / 58 = centimeters or us
55/160Declaration drives LCD screen library, ultrasonic sensor module HC-SR04interface./ 148 =inch; or: the range = high level time * velocity (340M/S) / 2; we suggest to useover 60ms measurement cycle, in ordersignal.to prevent trigger signal to the echoThe data measured by the ultrasonic sensor module HC-SR04 is processed bythe RGB-Nano board, and the data is displayed on the LCD screen.13.3 Wiring schematic13.4 Code explanation
56/160Initialize the serial port and screen, and set the ultrasonic sensor moduleHC-SR04 interface .Obtain the data measured by the ultrasonic sensor module HC-SR04 and displayit in the serial debugging window and LCD screen.
57/160Lesson 14 Photosensitive Resistance14.1 Overview14.2 Component IntroductionPhotosensitive resistors can be widely used in a variety of light control circuits, such aslight control, regulation and other occasions, can also be used for light controlswitches.In this experiment, we first carried out a relatively simple use experiment ofphotosensitive resistance.Since photosensitive resistor is a component that can change the resistance valueaccording to the light intensity, it also needs the analog port to read the analog valuenaturally. In this experiment, we can learn from the PWM interface experiment andchange the potentiometer into a photosensitive resistor to realize that the brightnessof the LED small lamp will also change accordingly when the light intensity is different.The resistance of photosensitive resistors is significantly high in low-light and darkconditions.The brighter the light, the lesser the resistance.Photoinductive resistance, is the use of semiconductor photoelectric effect madeof a resistance value with the intensity of the incident light and change theresistor.In situations of intense incident light, the resistance decreases, while in dimlighting conditions, the resistance increases. Photosensitive resistors arecommonly used for tasks such as light measurement, light control, and convertinglight variations into electrical signals.
58/160In the figure above, RL is a photosensitive resistor, and R1 is a series resistor. In thedark, RL is going to be very, very large, so Vout is going to be very large, close to 5V.The formula is as follows:As soon as the light hits, the value of RL decreases rapidly, so Vout decreases with it.It can be seen from the above formula that the selection of R1 should not be too small,preferably around 1K ~ 10K, otherwise the ratio will not change significantly.By measuring the voltage change on both sides of the photosensitive resistor, thechange of the photosensitive resistance value can be known and the illuminationintensity value can be obtained.In the connection diagram, we can find a partial voltage resistor in series for thephotosensitive resistor.RLVout= ∗VinR1 + RL
59/16014.3 Connection Diagram
60/16014.5 Code explanation14.4 Wiring schematicDefine the photoresistor to connect to analog pin A0 and the LED to connect todigital pin 4.When the photoresistor senses low light, it activates the LED light by setting thepin that connects to the LED light to output mode high.
61/160Use the analog reading function to read the data of the photosensitive resistor, andthen take this data as the judgment condition of day and night. If the detected data isless than 500, it indicates that the current environment has become dark, so let the pinconnected to the LED output high level, and make the LED light up.
62/160Lesson 15 Rotary encoder control RGB15.1 Overview15.3 Code explanation15.2 Project wiring diagramThrough this project, you can learn to use a rotary encoder to control the RGBdisplay running light on the micro controller RGB Nano.Connection description: Connect the D13 pin of the single-chip microcomputer to theDIN interface of the JP15 row with a DuPont cable, and the connection is successfulwhen it is plugged in. Next, connect the D2 pin of the micro controller to the "CLK" ofthe JP13 row seat with a DuPont line, connect the D3 pin to the "DT" of the JP3 rowseat, and connect the D4 pin to the "SW" of the JP13 row seat. You can connectsuccessfully.Contains RGB library files, defines the number of RGB lights and pin numbers,and defines the function pins and the global variables required by the function.
63/160When the function is initialized, it also sets the work type of the pin and enablesinterrupt 1 function concurrently.The main function, the value sent by the encoder through the display function to makethe corresponding RGB light be lit. By changing the "count" you can change the lightthat is litThe encoder processing function will determine whether the encoder is rotatingforward or backward, and at the same time change the value of "count".
64/160Lesson 16 NRF24L01 launch16.1 Overview16.3 Code explanationContains the library files that the project must use.16.2 Project wiring diagramThrough this project, you will learn to use NRF24L01 to send data and display itusing the serial port of the IDE compiler.Connection description: Connect the D9, D10, D11, D12, and D13 pins of the MCU tothe "CSN", "CE" "MOSI" "MISO" "SCK" on the header below JP3 with DuPont cables,and plug the NRF24L01 module into the JP3 socket. Once the wiring is complete, theconnection is successful.
65/160The function pins of the program are defined in the global variable definitionInitialize the function with a baud rate set to "57600" to match the serial port's baudrate; otherwise, it may result in generating garbled, unreadable characters.The serial port continuously prints the sent data "data" to download the program.After connecting the DuPont cable, you can open the debugging window of the IDE toview it. Pay special attention to setting the baud rate. The default baud rate is 9600and needs to be changed to 57600.
66/160Experimental phenomena.
67/160Lesson 17 Infrared Control LED17.1 Overview17.2 Project wiring diagramThroughout this project, you will gain experience in using an infrared remote control toactivate the LED wirelessly. Simply download the program, connect the DuPont cable,and use the play button on the remote control to toggle the LED on and off.Connection description: Connect D2 of the single-chip microcomputer to pin "S"of JP16 with a DuPont cable, and connect D13 to any pin of JP12, and theconnection is successful.
68/16017.3 Code explanationThe function initialization and pin definition have been covered in previous lessons andremain unchanged, so I will not elaborate on them here. The focus will be on theinfrared processing function. Upon receiving a key value, the infrared receiver functionwill assess it. This key value can be displayed via the serial port and observed in theserial debugger. Upon evaluating the specified key value, we set the LED state totoggle, allowing for the LED to be switched on and off.
69/160The “play” button of the remote control has been set with the specified functionin the program.
70/160Lesson 18 Infrared control RGB18.1 Overview18.3 Code explanation18.2 Project wiring diagramThe initialization of the function and the function pin definition of the function havebeen discussed in the previous course, but they are the same, so feel free to reviewthe section if needed.Through this project, you will learn to use an infrared remote control to turn on RGBremotely. After downloading the program, connect the DuPont cable and press 1, 2, 3,4, 5, and 6 on the remote control to display five colors of red, green, blue, yellow,white, and the last one is to turn off RGB.Connection description: Connect D2 of the single-chip microcomputer to the pin "S" ofJP16 with a DuPont wire, and connect D13 to the "DIN" pin of JP15, and theconnection is successful.
71/160Here the primary focus lies in the processing functions associated with IR technology.Upon detection of a key value by the infrared receiver, a decision-making process istriggered. This particular key value can be exhibited via the serial port and monitoredusing the serial debugger. Through the specification of a key value, it becomes possibleto ascertain the corresponding RGB color for each numeral. Activating the respectivenumber will result in the illumination of the associated color. Furthermore, these keyvalues can be customized to regulate the RGB color spectrum or the quantity of RGBlights to align with specific user preferences.
72/160The buttons highlighted in the red box of the remote control image below has been setwith the specified function in the program.
Through this project, you will learn to use the mobile phone APP (ex. ArduinoBluetooth Controller) to use Bluetooth to connect with the Bluetooth module on theboard to realize remote opening of RGB. After downloading the program, connect tothe DuPont cable, connect to Bluetooth, use the mobile APP to connect to Bluetooth,send R, G, B, Y, W, O through the APP keyboard, and display five colors of red, green,blue, yellow, and white. The last one One is to turn off RGB. Note that the charactershere are all capitalized in English.73/160Lesson 19 Bluetooth control RGB19.1 Overview19.2 Connection descriptionConnect D13 of the single-chip microcomputer to the"DIN" pin of JP15 with a DuPont line, connect TX on thesingle-chip microcomputer to RX on JP32, and connectRX on the single-chip microcomputer to TX on JP32.After all connections are made, the connection issuccessful. Project wiring diagram:
74/16019.3 Code explanationThe initialization of the function and the function pin definition of the function havebeen discussed in the previous course, but they are all the same, so I won't repeatthem here. I mainly talk about Bluetooth processing functions. When the Bluetoothreceiver function receives the corresponding character, it will make a judgment. Thischaracter can be printed out through the serial port and viewed in the serial debugger.When the character value we specify is judged, we define the RGB color correspondingto each number. When the corresponding number is pressed, the corresponding colorwill light up. These keys can also be customized or use self-defined numbers to controlthe color of RGB or the number of RGB.
75/160
76/16019.4 Bluetooth remote controlLaunch the Bluetooth app and look for the HC-06 Bluetooth module that was recently set up. Onceconnected successfully, you will see the main interface for remote control.Equipped with bluetooth serial port assistant for remote control of car. First, turn onbluetooth and search for Bluetooth devices to find HC-06 connection. The defaultconnection pairing password is 1234.
77/160Choose the keyboard mode, then input the specified characters. Once you input "R",the IOT Training Kit matrix will illuminate in red, and the Bluetooth app will respondwith an "OK" to confirm our communication is successful. Experiment with enteringother characters to see various colors displayed.Congratulations! You have reached the end of this course.
78/160IOT Training KitESP826620210904.V1Course Two
79/160Lesson 20 ESP8266 Development board20.1 introduction:The ESP8266 is a Wi-Fi module ideal for Internet of Things and home automationprojects. This article is a beginner's guide to the ESP8266 development board.20.2 ESP8266 specificationsSDIO 2.0 UART11 b/g/n agreement Wi-FiDirect (P2P) soft AP IntegratesTCP/IP protocol stackBuilt-in low-power 32-bit CPUSPI
80/16020.3 ESP8266 versionESP8266 Development board pin schematic diagram:The ESP8266 is available in several versions (see figure below). In our opinion, the ESP-12E or more commonly known as THE ESP-12E NodeMCU suite is the most practicalversion available today.
81/16020.4 NodeMCU pin arrangement peripherals20.5 What pins are used in NODEMCU ESP8266?NodeMCU peripherals include17 universal I/O pinsSPII2CA serial port10 bit ADCGPIO16 is marked D0 HIGH at startup to wake up from deep sleepGPIO15 is marked D8 pull to GND: if we pull high, startup failsGPIO3 boo RX HIGHGPIO1 is marked as TX debug output at startup, if pulled down startup failsThe GPIO number does not match the label on the pin diagram. For example, D1corresponds to GPIO5, D2 corresponds to GPIO5Can be used as input/output pins without problemGPIO5 labeled D1 is commonly used as SCL (I2C)GPIO4 labeled D2 is commonly used as SDA (I2C)GPIO0 flagged as D3 connects to the FLASH button if pulled low startup failsGPIO2 marked AS D4 connected to the onboard LED, if pulled low - high atstartup, startup failsGPIO14 is labeled D5 SPI (SCLK) GPIO12 islabeledD6SPI(MISO) GPIO13islabeledD7SPI(MOSI) ADO is marked as AO The following are the pins that can beused, but you need to be careful because they can have unexpected behaviorprimarily at startup.
82/160Note:Pins called GPIO6 through GPIO11 connect to the flash chip in the ESP8266.Therefore, it is not recommended to use these pins for input/output functions.If you want to operate relays, GPIO4 and GPIO5 are the safest GPIO pins to use.It is recommended that pins labeled RX and ADO be used as outputs and not TX pinsas inputs.
84/160Lesson 21 Installing the ESP8266 Development Board inthe Arduino IDEThis tutorial shows how to install the ESP8266 development board in theArduino IDE, whether you are using Windows, Mac OS X, or Linux.Before starting this installation process, make sure you have the latest versionof the Arduino IDE installed on your computer. If not, uninstall it and reinstall it.Otherwise, it might not work.You can click on the link:https://www.ar d u i n o . c c / e n / s o f t w a re install the latestArduino IDE software.The ESP8266 community has created an add-on for the Arduino IDE that allowsyou to program ESP8266 using the Arduino IDE and its programming language.To install the ESP8266 board in your Arduino IDE, follow the instructions below:In your Arduino IDE, go to file > Preferences.21.1 Install the ESP8266 plug-in in the Arduino IDE
84/160Enter it in the Additional Boards Manager URLs fieldhttp://arduino.esp8266.com/stable/package_esp8266com_index.jsonAs shown in the figure below. Then, click the ok button:Note: If you already have ESP32 board urls, you can use commas to separate the urls,as shown below:https://dl.espressif.com/dl/package_esp32_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json
85/160Wait a few seconds to install.Open board Manage. Go to Tools Board Board Manager...Search for ESP8266 and press the install button of "ESP8266 by ESP8266Community" :→ →
86/160Upload a sketch21.2 Test the installationUpload the sketch to ESP-12ETo test the ESP8266 plug-in installation, let's see if we can make the LED blinkthrough the ESP8266 using the Arduino programming language.Plug your development board into your computer. Make sure you choose theright circuit board:You also need to select ports:
87/160}Then, copy the supplied code:int pin = 2;void setup() {// Initialize GPIO 2 as output.pinMode(pin, OUTPUT);}// The loop function runs over and over againvoid loop() {digitalWrite(pin,HIGH);delay(1000);digitalWrite(pin,LOW);delay(1000); //turn on the LED//Delay for a second//Turn off the LED by lowering the voltage//Delay for a secondClick the "Upload" button in the Arduino IDE and wait a few secondsuntil you see the "Upload Completed" message. It's in the lower leftcorner.
88/16021.3 Wiring DiagramWhen D4 is connected to the green LED pin in the traffic light module,the LED flashes.
89/160Lesson 22 ESP8266 NodeMCU WiFi Control TrafficLight ModuleIn this tutorial, you will learn how to use the ESP8266 NodeMCU boardto build an asynchronous Web server to control its output. The boardwill be programmed using the Arduino IDE and we will use theESPAsyncWebServer library.22.1 Asynchronous Network ServerTo build a Web server, we'll use the ESPAsyncWebServer library, which providesan easy way to build an asynchronous Web server.
90/16022.2 Schematic Diagram:Before continuing with the code, connect the three leds to the ESP8266. Weconnected the LED to GPIO 5, 4 and 2.
91/16022.3 Wiring DiagramInstallation library - ESP Exotic Web serverTo build a Web server, you need to install the following libraries.These libraries cannot be installed through the Arduino library manager,so you need to copy the library files to the Arduino installation libraryfolder. Or, in your Arduino IDE, you can goto Sketch > Include Library > Add .zip Library and select thelibrary you just downloaded.ESPAsyncWebServerESPAsyncTCPProject overview
93/160To better understand the code, let's take a look at how the Web server works.The Web Server contains a title "ESP Web Server" and three buttons(toggle switches) to control the three outputs. Each slider button has alabel indicating the GPIO output pin. You can easily remove/add moreoutput.When the slider is red, the output is on (its status is HIGH). If you switchthe slider, it will turn off the output (changing the state to LOW). Whenthe slider is gray, the output is off (its status is LOW). If youswitch the slider, it turns on the output (changing the state to HIGH).
94/160Let's see what happens when we toggle buttons. We will see an example ofGPIO 2. The other buttons work similarly.2. In the second example, when you toggle the button to turn off GPIO 2. Whenthis happens in/update? Output = 2 & status = 0 URL. Based on this URL, we changethe state of GPIO 2 to 0 (LOW) and turn off the LED.1. In the first case, you toggle the button to turn on GPIO 2. When this happens,will it update in /? Output = 2 & status = 1 URL. Based on this URL, we change thestate of GPIO 2 to 1 (HIGH) and turn on the LED.22.4 ESP asynchronous Web server code//#include <ESP8266WiFi.h>#include <ESPAsyncTCP.h>AsyncWebServer server(80);<!DOCTYPE HTML><html><head><title>ESP Web Server</title>#include <ESPAsyncWebServer.h>//const char* PARAM_INPUT_2 = "state";const char* PARAM_INPUT_1 = "output";// Library files that need to be installedconst char index_html[] PROGMEM = R"rawliteral(const char* password = "REPLACE_WITH_YOUR_PASSWORD";//Enter wifipasswordconst char* ssid = "REPLACE_WITH_YOUR_SSID";//Enter your wifi name<meta name="viewport" content="width=device-width, initial-scale=1">Create an AsyncWebServer object on port 80Replace with your network credentials
94/160<body></head><style ></style >%BUTTONPLAC EHOLDER %<h2>ESP Web Server</h2>p {font-size: 3.0rem;}h2 {font-size: 3.0rem;}.switch input {display: none}var xhr = new XMLHttpRequest();<link rel="icon" href="data:,"><script>function toggleCheckbox(element) {input:checked+.slider {background-color: #b30000}html {font-family: Arial; display: inline-block; text-align:center;}body {max-width: 600px; margin:0px auto; padding-bottom: 25px;}.switch {position: relative; display: inline-block; width: 120px;height: 68px}.slider {position: absolute; top: 0; left: 0; right: 0; bottom: 0;background-color: #ccc; border-radius: 6px}input:checked+.slider:before {-webkit-transform: translateX(52px);-ms-transform: translateX(52px); transform: translateX(52px)}.slider:before {position: absolute; content: ""; height: 52px; width:52px; left: 8px; bottom: 8px; background-color: #fff;-webkit-transition: .4s; transition: .4s; border-radius: 3px}
95/160}}</body></html></script >xhr .send();})rawliteral" ;//return String();return buttons;String buttons = "";//Serial.p rintln(va r);String outputState(int output){if(var == "BUTTONPLACEHOLDER"){String processor(const String& var){if(element.checked){ xhr.open("GET","/update?output="+element.id+"&state=1", true); }else { xhr.open("GET", "/update?output="+element.id+"&state=0",true); }buttons += "<h4>Output - GPIO 2</h4><label class=\"switch\"><inputtype=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"2\" " +outputState(2) + "><span class=\"slider\"></span></label>";buttons += "<h4>Output - GPIO 5</h4><label class=\"switch\"><inputtype=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"5\" " +outputState(5) + "><span class=\"slider\"></span></label>";buttons += "<h4>Output - GPIO 4</h4><label class=\"switch\"><inputtype=\"checkbox\" onchange=\"toggleCheckbox(this)\" id=\"4\" " +outputState(4) + "><span class=\"slider\"></span></label>";Replace placeholders in web pages with button sections
96/160}}}////else {void setup(){return "";delay(1000 );return "checked";pinMode(5, OUTPUT);pinMode(4, OUTPUT);pinMode(2, OUTPUT);Serial .begin (115200 );digitalWrite(5, LOW);digitalWrite(4, LOW);digitalWrite(2, LOW);WiFi.begin(ssid, password);if( digitalRead (output)){while (WiFi.status() != WL_CONNECTED) {Serial.println("Connecting to WiFi..");Serial port for debuggingConnect to a wireless network
97/160}//}});else {String inputMessage1;String inputMessage2;// Route for root / web pageSerial .println (WiFi. localIP());inputMessage1 = "No message sent";inputMessage2 = "No message sent";if (request->hasParam(PARAM_INPUT_1) &&request->hasParam(PARAM_INPUT_2)) {}// Send a GET request to<ESP_IP>/u pdate?out put=<inpu tMessage1> &state=<i nputMessa ge2>// GET input1 value on<ESP_IP>/u pdate?out put=<inpu tMessage1> &state=<i nputMessa ge2>request->send_P(200, "text/html", index_html, processor);server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){inputMessage1 = request->getParam(PARAM_INPUT_1)->value();inputMessage2 = request->getParam(PARAM_INPUT_2)->value();digitalWrite(inputMessage1.toInt(), inputMessage2.toInt());server.on("/update", HTTP_GET, [] (AsyncWebServerRequest *request) {ESP local IP address is displayed”
98/160});//Start serverSerial.print("GPIO: ");Serial. print(inputMessa ge1);Serial.print(" - Set to: ");server.begin();}void loop() {}Serial. println(inputMessa ge2 );request->send(200, "text/plain", "OK");Import libraries22.5 How the code worksSet up network credentialsIn this section, we explain how the code works.Insert your network credentials in the following variables so that ESP8266 canconnect to your local network.First, import the required libraries. You need to include wireless Internet access,ESPA sync network server and ESPA sync TCP library.#include <ESP8266WiFi.h>#include <ESPAsyncTCP.h>#include <ESPAsyncWebServer.h>const char* ssid = "REPLACE_WITH_YOUR_SSID";
99/160AsyncWebServer server(80);const char* PARAM_INPUT_1 = "output";const char* PARAM_INPUT_2 = "state";const char* password = "REPLACE_WITH_YOUR_PASSWORD";Build a web pageThe input parametersAsyncWebServer object=0All HTML text with styles and JavaScript is stored in index_HTML variable. Nowwe'll go through the HTML text and see what each section does.To check the parameters passed through the URL (GPIO number and its state),we create two variables, one for output and one for state.Keep in mind that ESP8266 receives requests like: / Update? Output =2& stateCreate an object on port 80 of the asynchronous Web server.The title is located at < title> And </tile> Tags. The title is exactly what it sounds like: thetitle of your document, which appears in the title bar of your Web browser. In this case, it isthe "ESP Web server."
100/160The following < meta >; Tabs make your web pages responsive in anybrowser (laptop, tablet, or smartphone).<link rel="icon" href="data:,"><meta name="viewport"content="width=device-width, initial-scale=1"><style> html {font-family: Arial; display: inline-block;text-align: center;}h2 {font-size: 3.0rem;}p {font-size: 3.0rem;}body {max-width: 600px; margin:0px auto;padding-bottom: 25px;}.switch {position: relative; display: inline-block;width: 120px; height: 68px}.switch input {display: none}.slider {position: absolute; top: 0; left: 0; right: 0;bottom: 0; background-color: #ccc; border-radius: 6px}.slider:before {position: absolute; content: ""; height:The next line blocks requests for web site ICONS. In this case, we don't have a websiteicon. A website icon is a website icon that appears next to the title of a Web browserTAB. If we don't add the following line, ESP will receive a request for FavIcon everytime we visit the Web server.In <style> </style> Between the tabs, we added some CSS to set the style ofthe page. We won't go into the details of how this CSS style works.