ESP8266 – Serial Communication - The Engineering Projects
Maybe your like
David watson Electrical Engineer London , UK
ARDUINO
Arduino Library for Proteus Arduino Projects Arduino Tutorials
Raspberry Pi
Raspberry Pi Projects Raspberry Pi 0 Raspberry Pi 4 Raspberry Pi Pico
ESP32
ESP32 Projects ESP8266 Projects - Home
- Blog
- ESP8266 Projects
- ESP8266 – Serial Communication
Departments:- Electrical Engineering
- Electronics Engineering
- ESP8266
- Arduino C
- Arduino IDE


| Where To Buy? | ||||
|---|---|---|---|---|
| No. | Components | Distributor | Link To Buy | |
| 1 | ESP8266 | Amazon | Buy Now | |
Applications
The range of uses of serial communication is limited only by creativity. Here I will mention three more general scenarios and detail some applications within them.1. Communicating with computers
With a USB cable, we were able to connect the NodeMCU with a computer via Serial. Arduino IDE already gives us the first use. With Serial Monitor, we can send commands or debug the functioning of our code. But the integration with other software is pretty powerful. Imagine, for example, access control in which a circuit with ESP8266 reads an RFID card and sends it via Serial to a Permission Validation System. Or even an LED panel that receives a software display text.2. Communicating with microcontrollers
Probably the most common application. Whether to integrate into a preexisting circuit or to distribute functionality between microcontrollers. This integration can be done between different microcontrollers. As long as they operate with the same voltage (3.3V) or use a level converter. An application example is to integrate the ESP8266 wifi with the analog ports of an ATMEGA328 to build an IoT toxic gas sensor. We already know that the ESP8266's analog port is quite inefficient. Then it is possible to perform the analog reading on the ATMEGA328 and send the information to ESP8266 by Serial.3. Communicating with industrial machines
This, without a doubt, is the most interesting way to integrate industrial machinery with WEB systems. The older industrial equipment that allows some automation, provides RS232 or RS485 ports for integration with PLCs. In these cases, the commands are pretty plastered, but hopefully, well documented. The voltage level is 12V or 24V, but there are converters and logic levels to solve this. The industry 4.0 paradigm has been operating to make this kind of integration. Some PLCs are already developed with wifi modules. And on that account, circuits with the ESP8266 have the immense advantage of low cost. The vision behind this is to be able to remotely monitor or control an entire industrial plant. Tracking KPIs for predictive maintenance, doing recalibrations, and managing production.Main Functions
The Serial library has a good variety of functions for Serial communication, but most are for very specific uses. We will discuss the most common ones and may return to others in the future as needed by the projects.Serial.begin()
The first function to be used. It initializes Serial communication informing the data transfer speed (in bits per second) and, optionally, a configuration parameter. By default, Serial is configured to send data in 8-bit packets plus a terminator, not including parity. The best way to imagine this communication is to imagine a train, where each byte (8 bits) sent is a car, and the terminator is the connection between them. This standard is used in most devices, but if you need to integrate a device with another standard, the config parameter allows you to change the number of bits in the packet (from 5 to 8), the number of stop bits (1 or 2 ) and enable or disable parity (a packet integrity check). The speed uses some preset values. The fastest that remains stable for the ESP8266 is 115200 changes per second. So we could start with: Serial.begin(155200) The function below presents the same result, making the config parameter explicit. Serial.begin(115200, SERIAL_8N1)Serial.available()
The function returns an integer with the number of bytes available in the read buffer. The maximum of bytes in the buffer is 64. This function is very useful for monitoring incoming information. Value = Serial.available()Serial.read()
The function returns the most recent byte in the input buffer and removes it from the buffer. It is ideal if your communication is byte-to-byte. For example, if you are receiving input from a keyboard, the function would return the key you typed. It returns an integer with byte or -1 if no data is available.Serail.readString()
This function is best suited for reading strings. Like words. It is the equivalent of calling the read() function continuously until it reads all the information from the buffer. The function returns a string with the data.Serial.print() and Serial.println()
The two functions are very similar. It takes a value and sends it serially in ASCII format. It is also possible to define the numerical base before sending (binary, decimal...) and the number of decimal places. The function can be used either in the format: Serial.print(value) And the format: Serial.print(value, format) The table below presents some usage examples.
Serial Monitor
The Arduino IDE provides a very powerful tool for debugging and testing Serial communication. The Serial Monitor. The tool is pretty intuitive, but let's take a look at its fields.- Sending data: This allows us to send commands directly to the microcontroller
- Autoscroll: Very useful when we've already received enough information to fill the screen
- Terminator: Choose whether or not to include the new line and carry return characters at the end of the message before
- BaudRate: Defines the communication It must be the same as the microcontroller, or

Controlling and monitoring an LED
Let's make a simple code to control and monitor the NodeMCU LED from the Serial monitor. The code will monitor the Serial, and each time it receives the command “ON”, it will turn on the LED, when it receives “OFF”, it will turn off the LED when it receives “STATUS”, it will return the status of the LED in the Serial. We will create three functions to perform the actions.- turnOn() : To turn on the
- turnOff() : To turn off the
- statusLED() : To read the pin status and return information in the serial.




Syed Zain Nasir
syedzainnasir I am Syed Zain Nasir, the founder of The Engineering Projects (TEP). I am a programmer since 2009 before that I just search things, make small projects and now I am sharing my knowledge through this platform. I also work as a freelancer and did many projects related to programming and electrical circuitry. My Google Profile+ Follow Get Connected
Add A Comment
Post Comment Uploading .... Comments on ‘’ ESP8266 – Serial Communication ‘’ ( 0 ) Top PCB Design Service
Embedded Tools
Subscribe Now !!!
Learn Free Pro Tricks RSS YT FB Pin Receive Quality Tutorials Straight in yourInbox by submitting your Email ID below.Join Us !!!
Join Our Fb Groups !!!
ARDUINO 2K+ PROTEUS 3K+Tag » Arduino Esp8266 Serial Communication
-
Send Data From Arduino To NodeMCU And NodeMCU To Arduino...
-
Serial Communication Between Esp8266 And Arduino
-
Serial Communication Between Arduino And ESP8266
-
Sending Data From An Arduino To The ESP8266 Via Serial
-
Send Data From Arduino To NodeMCU And NodeMCU To ... - YouTube
-
Arduino To ESP8266 Data With Serial Communication ... - YouTube
-
How To Do Serial Communication Between Two Boards? | ArduinoJson 6
-
Serial Communication Between ESP8266 And Arduino - Iotguider
-
Serial Communication Arduino To NodeMcu - Stack Overflow
-
Issue With Communication Between ESP8266 And Arduino UNO
-
ESP8266 Serial Communication
-
Lesson 9- NodeMCU With Arduino UNO (UART) - SlideShare
-
Why Doesn't Serial Communication Work On Arduino Uno R3 And ...
-
Arduino To ESP8266 By Serial Communication | Martyn Currey