Skip to main content
Top

2021 | Book

Electronics Projects with the ESP8266 and ESP32

Building Web Pages, Applications, and WiFi Enabled Devices

insite
SEARCH

About this book

Discover the powerful ESP8266 and ESP32 microcontrollers and their Wi-Fi communication. The ESP32 microcontroller features Bluetooth and BLE communication in addition to Wi-Fi. The book emphasizes practical projects and readers are guided through Wi-Fi and Bluetooth communication, mobile app design and build, ESP-NOW and LoRa communication, and signal generation.

Projects throughout the book utilize the Wi-Fi functionality and processing power of the ESP microcontrollers. Projects are built in the Arduino IDE, so you don't need to download other programming software. Mobile apps are now ubiquitous, making the app build projects of the book very relevant, as are the web page design projects.

In Electronics Projects with the ESP8266 and ESP32, you'll see how easy and practical it is to access information over the internet, develop web pages, build mobile apps to remotely control devices with speech recognition or incorporate Google Maps in a GPS route tracking app.

You will

· Build practical electronics projects with an ESP8266 or ESP32 microcontroller with Wi-Fi communication

· Use the Wi-Fi function of the ESP8266 and ESP32 to update web pages

· Communicate with your mobile phone or smart watch by Bluetooth Low Energy

· Transmit and receive information to control remote devices over the internet

· Understand the design and build of mobile apps for internet based applications

· Apply your computer programming skills in C++, JavaScript, AJAX and JSON

· Use WebSocket, MQTT brokers and IFTTT for fast two-way communication with webpages

Who This Book Is For

The target audience is for Makers and Tinkerers who want to build internet/intranet based applications with more powerful microcontrollers, such as the ESP8266 or ESP32. A level of C++ programming expertise with the Arduino IDE is assumed, although all sketches are fully described and comprehensively commented.

Table of Contents

Frontmatter
Chapter 1. Internet radio
Abstract
Internet radio is the continuous streaming of digital audio over the Internet. Digital audio, in MP3 format, is received by the ESP8266 or ESP32 microcontroller through a Wi-Fi connection. The ESP8266 or ESP32 microcontroller communicates with a VS1053 audio decoder by Serial Peripheral Interface (SPI), and the MP3-formatted data is decoded by an 18-bit digital to analog converter (DAC) to an audio signal that is amplified for a loudspeaker. ESP8266 and ESP32 microcontrollers have Wi-Fi functionality and sufficient processor speed for an Internet radio. Connection to the wireless local area network (WLAN) requires the Wi-Fi network SSID (Service Set Identifier) and password. The SSID is the WLAN name, and both the SSID and password are generally located on the base of the router.
Neil Cameron
Chapter 2. Intranet camera
Abstract
The ESP32-CAM module is based on the ESP32-S microcontroller and includes a 2M-pixel OV2640 camera and a micro-SD (Secure Digital) card slot. JPEG files of images are stored on the SD card or loaded to a web page or streamed to a web page on a computer, Android tablet, or mobile phone.
Neil Cameron
Chapter 3. International weather station
Abstract
International weather information is displayed on a touch screen where the user selects weather information for different cities and chooses between two screens of displayed information. Initially, this chapter describes displaying text and shapes on the screen, calibrating the touch function of the screen, and creating images by pressing the touch screen. Once sketches are developed to display information and utilize the touch function of the touch screen, the focus shifts to accessing international weather data from OpenWeatherMap.org and the reformatting of the OpenWeatherMap data to display on a touch screen.
Neil Cameron
Chapter 4. Internet clock
Abstract
Each LED (Light-Emitting Diode) in an RGB (Red Green Blue) LED strip or ring is individually addressed using only one microcontroller pin for all the LEDs in the strip or ring. The term WS2812 5050 RGB LED refers to a strip or ring consisting of RGB LEDs with a WS2812 controller chip incorporated in each LED, and 5050 refers to the LED dimensions of 5.0 × 5.0 mm. NeoPixel is the Adafruit brand name for individually addressable RGB LEDs.
Neil Cameron
Chapter 5. MP3 player
Abstract
The DFPlayer Mini MP3 player with built-in micro-SD card module is either used as a battery-powered stand-alone module with push-button controls or connected to a microcontroller for more comprehensive control features. The MP3 player has audio output channels for earphone or amplifier input (DAC R and DAC L) and for loudspeaker input (SPK1 and SPK2), UART Serial communication (RX and TX), and four control pins (IO1, IO2, ADKEY1, and ADKEY2) that are active LOW (see Figure 5-1). The BUSY pin is LOW when an audio file is playing, but otherwise HIGH. The MP3 has a music equalizer with six settings.
Neil Cameron
Chapter 6. Bluetooth speaker
Abstract
A Bluetooth speaker complements the Internet radio in Chapter 1, the MP3 player in Chapter 5, and the WS2812 5050 RGB LED strip that responds to sound in Chapter 4. The Bluetooth stereo audio receiver module with the PAM8403 class-D audio amplifier does not require an ESP8266 or ESP32 microcontroller, but the project merits incorporation in the book because it's fun and a straightforward build. After the Bluetooth stereo audio receiver module is switched on with the announcement "Bluetooth mode: the Bluetooth device is ready to pair," the mobile phone or Android tablet with Bluetooth communication is connected to the Bluetooth stereo audio receiver module, followed by another announcement "The Bluetooth device is connected successfully."
Neil Cameron
Chapter 7. Wireless local area network
Abstract
A wireless local area network (WLAN) is established with an ESP8266 or ESP32 microcontroller, such as on a LOLIN (WeMos) D1 mini or ESP32 DEVKIT DOIT development board, with networked devices requesting information from the microcontroller (see Figure 7-1). The WLAN does not have Internet access. The microcontroller is the access point (AP) for the WLAN, consisting of the microcontroller and up to four devices, and is termed a software-enabled access point or SoftAP. If the microcontroller is connected to an existing Wi-Fi network, then the microcontroller is in station (STA) mode. The WLAN client is the browser on a laptop, an Android tablet, or a mobile phone. The client connects to the WLAN by selecting the WLAN name and the access password with the browser opened at the URL (Uniform Resource Locator) of the WLAN-predefined IP (Internet Protocol) address.
Neil Cameron
Chapter 8. Updating a web page
Abstract
Devices connect to a wireless local area network (WLAN) with Wi-Fi communication (see Chapter 7 (Wireless local area network)). A router connected to an Internet Service Provider (ISP), through a telephone line using DSL (Digital Subscriber Line) technology, provides access to the Internet (see Figure 8-1). The Internet is formed by interconnected computer networks using the Internet Protocol suite, consisting of the Transmission Control Protocol and the Internet Protocol (TCP/IP), to globally link devices. The World Wide Web (WWW) identifies information resources by URLs (Uniform Resource Locators). The client or web browser, such as Google Chrome or Mozilla Firefox, sends an HTTP (HyperText Transfer Protocol) request to the server device hosting the resource to retrieve information at the web address defined by the URL. The server responds to the client HTTP request, and the client displays the requested web page information on the Android tablet or mobile phone. The client must request web page information from the server, as the server cannot impose updates on the client. The exception is WebSocket, as discussed in Chapter 9.
Neil Cameron
Chapter 9. WebSocket
Abstract
The WebSocket protocol (www.websocket.org) allows a two-way real-time conversation between the web server and client, through a standardized connection to allow both the server and the client to send data at any time. The client sends a request to the server to switch from an HTTP protocol to a WebSocket protocol; and if the server can host the WebSocket protocol, the HTTP connection is replaced with a WebSocket connection, but using the same port as HTTP.
Neil Cameron
Chapter 10. Build an app
Abstract
A mobile app, short for application, is a computer program for mobile devices, such as a mobile phone or Android tablet. Apps are available for mobile games, providing information, location and route finding, playing music, and controlling external devices. The MIT App Inventor provides the opportunity to design your own app, rather than using an app downloaded from Google Play Store. After completing the app design stage, the app is immediately available to download to an Android tablet or mobile phone.
Neil Cameron
Chapter 11. App database and Google Maps
Abstract
MIT App Inventor contains a database function for storing data within an app. Google Maps is accessible with MIT App Inventor, provided the Android tablet or mobile phone hosting the app has Internet access. This chapter outlines storing route data in an app database, with the app displaying route information using Google Maps. Building the app database and incorporation of Google Maps are the basis for Chapter 12 (GPS tracking app with Google Maps) to develop a GPS tracking app for the GPS module connected to an ESP8266 or ESP32 microcontroller.
Neil Cameron
Chapter 12. GPS tracking app with Google Maps
Abstract
In Chapter 11 (App database and Google Maps), an app was developed to display map locations using Google Maps on an Android tablet or mobile phone with Internet access. In this chapter, a GPS location app displays the position of a remotely located GPS module or the route taken by the GPS module using Google Maps. An nRF24L01 module, connected to an ESP8266 or ESP32 development board attached to the GPS module, transmits the GPS location to a receiving nRF24L01 module, attached to an ESP32 development board. The GPS location information is transmitted to the app on the Android tablet or mobile phone by the ESP32 microcontroller using Bluetooth communication. The GPS location is displayed on the app using Google Maps, with the Android tablet or mobile phone accessing Google Maps data from the World Wide Web through the Internet Service Provider (ISP) (see Figure 12-1). The transmission range of the nRF24L01 transceiver module of at least 1 km combined with the 10 m range of Bluetooth provides a degree of flexibility in the distance between the app user, the receiving nRF24L01 module, and the remotely positioned GPS module.
Neil Cameron
Chapter 13. USB OTG communication
Abstract
In Chapter 12 (GPS tracking app with Google Maps), data was transmitted to an app on an Android tablet or mobile phone by an ESP32 microcontroller with Bluetooth communication. In Chapter 10 (Build an app), an HC-05 Bluetooth module was connected to an ESP8266 development board to communicate with an app. If the device to transfer data to an app does not have Bluetooth functionality, then USB OTG (On-the-Go) communication connects the device with the app. In this chapter, the device without Bluetooth functionality is an Arduino Uno. An HC-05 Bluetooth module could be connected to the Arduino Uno for Bluetooth communication with the Android tablet or mobile phone, but this chapter focuses on USB OTG communication.
Neil Cameron
Chapter 14. ESP-NOW and LoRa communication
Abstract
Espressif Systems developed ESP-NOW to enable ESP8266 and ESP32 microcontrollers to communicate without requiring a Wi-Fi connection. ESP-NOW operates at 2.4 GHz, the same frequency as Wi-Fi and Bluetooth, with microcontrollers paired prior to communication. A microcontroller transmits and receives messages to and from several microcontrollers, with a network consisting of 20 microcontrollers without message encryption, but 10 microcontrollers with encryption. If power to a microcontroller is lost and then restored, the microcontroller automatically reconnects to the paired microcontroller. In practice, a transmission range of 250 m over open ground was achieved with two ESP32 microcontrollers.
Neil Cameron
Chapter 15. Radio frequency communication
Abstract
In telecommunications and signal processing, information is transferred on a radio carrier wave by either modulating the amplitude or the frequency of a radio carrier wave. Radio waves have frequencies between 20 kHz and 300 GHz, corresponding to wavelengths of 15 km to 1 mm, and travel at the speed of light. Radio waves with frequencies above 300 MHz are termed microwaves. For Radio Frequency (RF) communication with amplitude modulation (AM), the transmission amplitude is proportional to the signal amplitude, and the transmission frequency is constant (see Figure 15-1). Conversely, for frequency modulation (FM), the amplitude of the transmitted signal is constant, and the transmission frequency is proportional to the signal amplitude. AM is used for communication between two-way radios, citizens band radios, and VHF (very-high-frequency) aircraft radios. FM is used in telemetry and radio broadcasting of music, as FM has a higher signal-to-noise ratio than AM at the same transmission power.
Neil Cameron
Chapter 16. Signal generation
Abstract
Telecommunication uses digital signals to transfer information. For example, the instruction Serial.print("12AB") transmits the ASCII code for each character (see Figure 16-1) in binary format with the microcontroller UART (Universal Asynchronous Receiver Transmitter). ASCII (American Standard Code for Information Interchange) is an 8-bit character encoding standard for electronic communication, with the least significant bit (LSB) transmitted first. For example, the letter A has ASCII code of 65, which is B01000001 LSB or (1 × 26 + 1 × 20). The transmitted <S> and <T> bits are the start and stop bits.
Neil Cameron
Chapter 17. Signal generation with 555 timer IC
Abstract
In Chapter 16 (Signal generation), an ESP8266 or ESP32 microcontroller generated square wave signals with variable duty cycle or generated sine and triangular wave signals when combined with an AD9833 waveform generator module. Sine waves were also generated with the addition of an external DAC (digital to analog converter) MCP4725 module to the ESP8266 microcontroller or with the built-in DAC of the ESP32 microcontroller. In Chapter 5 (MP3 player), a microcontroller signaled an MP3 player module to play a track when movement triggered a passive infrared (PIR) sensor. Even though the signaling sketches often contained fewer than 20 lines of code, signal generation always required a microcontroller. Signal generation with a 555 timer integrated circuit (IC) is an alternative to requiring a microcontroller and provides insight into combining electronic components for an application. The 555 timer IC is incorporated in timer and signal generation applications ranging from pulse and sound generation, clocks, timers and alarm triggering, power control with PWM (pulse width modulation), or any application requiring time control. This chapter describes signal generation with the 555 timer IC to complement Chapter 16 (Signal generation). As an illustrative application, the MP3 player and PIR sensor example from Chapter 5 (MP3 player) is developed with the 555 timer IC.
Neil Cameron
Chapter 18. Measuring electricity
Abstract
Voltage, current, resistance, and capacitance are measured with a multimeter. Understanding the required circuitry and programming an ESP8266 or ESP32 microcontroller to measure voltage, current, resistance, capacitance, and inductance is a valuable exercise when studying electronics. A voltage divider and an analog to digital converter (ADC) are essential to measuring voltage, current, resistance, capacitance, and inductance, which are described prior to the measurement projects. For each project, connection of all components to a common ground defines the voltage reference point. If a project gives unusual results, then check that a common ground has been established.
Neil Cameron
Chapter 19. Rotary encoder control
Abstract
A rotary encoder detects rotation of the center shaft and is used to control machinery position and motor speed, audio volume, the cursor position on an LCD (Liquid Crystal Display) screen, or simply LED brightness. For example, in Chapter 1 (Internet radio), the radio station and volume were selected by turning a rotary encoder. The incremental rotary encoder has 20 positions, and the rotor is continuously rotated clockwise or anti-clockwise to increase or decrease a control variable. The rotary encoder has two pins, termed A or CLK (clock) and B or DT (data), and a common pin. As the rotary encoder rotor is turned, pins A and B each make contact with the common pin, which generates square waves, but as the pins are offset, the square waves are 90° out of phase (see Figure 19-1). The number of square wave pulses indicates the extent of the rotation, which is measured on either pin A or pin B.
Neil Cameron
Chapter 20. OTA and saving data to EEPROM, SPIFFS, and Excel
Abstract
The memory storage device for computers and microcontrollers is termed flash memory, which retains data when power is turned off. In contrast, data stored in RAM (random access memory) is lost when power is turned off. Flash memory is partitioned into several sections: application, OTA (over the air) updating, SPIFFS (Serial Peripheral Interface Flash File System), EEPROM (Electrically Erasable Programmable Read-Only Memory), Wi-Fi, and configuration information. A sketch is stored in application memory, and the variables created and manipulated in a sketch are stored in RAM. The opportunity to upload a sketch remotely with OTA and options for saving data in SPIFFS and EEPROM partitions of flash memory are outlined in this chapter. Saving data directly to a Microsoft Excel file, instead of using an SD card for data logging, is also described.
Neil Cameron
Chapter 21. Microcontrollers
Abstract
Several microcontrollers are used in the book, depending on the required function of the microcontroller. The LOLIN (WeMos) D1 mini board, based on the ESP8266 microcontroller, is used in applications requiring Wi-Fi connectivity. The ESP32 DEVKIT DOIT board, based on the ESP32 microcontroller, is ideal for applications requiring intense data processing with either Wi-Fi or Bluetooth connectivity. The ESP32-CAM board, which is based on the ESP32-S microcontroller, is the obvious choice for applications requiring both a camera and Wi-Fi functionality. The Arduino Pro Micro emulates a USB device, such as a keyboard, in applications that store data directly to a Microsoft Excel spreadsheet. The Arduino Uno and the smaller Arduino Nano, both based on the ATmega328P microcontroller, are appropriate for applications when Wi-Fi connectivity or high processing power is not required. Table 21-1 summarizes some of the properties of the microcontrollers, with further information available from www.arduino.cc/en/Main/Products or from www.espressif.com/en/products/devkits. The ESP8266 and ESP32 microcontrollers have significantly higher CPU frequencies, with more flash memory and RAM (random access memory) than the ATmega328P microcontroller. A sketch is stored in flash memory, while sketch variables are stored in RAM.
Neil Cameron
Chapter 22. ESP32 microcontroller features
Abstract
Features specific to the ESP32 microcontroller are described in this chapter. In Chapter 21 (Microcontrollers), differences in instructions for ESP8266 and ESP32 microcontrollers regarding features that are available to both microcontrollers were described. The ESP32 microcontroller has two cores, which are managed independently, Bluetooth communication and Bluetooth Low Energy (BLE) communication, four independent timers, a digital to analog converter (DAC) with capacitive touch sensors, and a Hall effect sensor. The ESP32 DEVKIT DOIT development board is illustrated in Figure 22-1.
Neil Cameron
Backmatter
Metadata
Title
Electronics Projects with the ESP8266 and ESP32
Author
Neil Cameron
Copyright Year
2021
Publisher
Apress
Electronic ISBN
978-1-4842-6336-5
Print ISBN
978-1-4842-6335-8
DOI
https://doi.org/10.1007/978-1-4842-6336-5

Premium Partner