Practical 3 - ESP32 WiFi
Practical 3 - ESP32 WiFi
Practical 3 - ESP32 WiFi
Practical 3
Objective
Understand how to use NodeMCU ESP32 for setting up a simple IOT solution with WiFi
connection, push button and LED indicators.
Background
ESP32 Module
The ESP32 is a low-cost, feature-rich microcontroller ideal for building connected devices. At its
heart lies a powerful processor (either dual- or single-core) paired with built-in Wi-Fi and
Bluetooth capabilities. This makes the ESP32 perfect for the Internet of Things (IoT). It
includes numerous GPIO pins and peripherals such as touch sensors, temperature sensors,
and ADCs (analog-to-digital converters), enabling a vast range of projects. Designed for low
power consumption, the ESP32 is a popular choice for battery-powered applications.
- GPIO Pins: A range of General Purpose Input/Output pins for connecting sensors,
actuators, LEDs, displays, and other peripherals.
- Peripherals: Includes analog-to-digital converters (ADCs), digital-to-analog converters
(DACs), and more.
- Low Power Consumption: Designed for battery-powered applications and IoT devices.
We use the NodeMCU ESP32 module, which is a pre-made development board that houses the
ESP32 chip along with the essential supporting circuitry. It is an ESP-WROOM-32 module in
breadboard friendly form factor, we can develop our project by using this compact
microcontroller on a breadboard. ESP32 is the big brother of ESP8266. It makes using the
ESP32 much easier for beginners and rapid prototyping. This module typically includes:
Features:
● NodeMCU based on ESP-WROOM-32 module
● Based on ESP32 DEVKIT DOIT
● 30 GPIO Version
BAIT2123 INTERNET OF THINGS Jul 2024
● ESP32 is a dual-core 32-bit processor with built-in 2.4 GHz Wi-Fi and Bluetooth
● 4MByte flash memory
● 520KByte RAM
● 2.2 to 3.6V Operating voltage range
● In breadboard-friendly breakout
● USB micro B for power and Serial communication, use to load the program and serial
debugging too
Document/Tutorials:
● Github, NodeMCU ESP32 Dev firmware
● Getting Started with NodeMCU 32 board
● GPIO reference
● ESP-WROOM-32 Datasheet
● CP210x USB driver
* This software is installed in the laboratory PC, the following step of installation is for
students who wish to explore this using their own laptop / home PC only.
The Arduino IDE is the heart of the Arduino ecosystem. It's a free and
open-source software application that provides a streamlined way to
write code for Arduino boards and upload your programs to them. The
IDE features a simple text editor for code development, a message
area for feedback and errors, a text console for debugging, and a
convenient toolbar with buttons for common functions like compiling
and uploading code.
The Arduino IDE aims to simplify the process of working with Arduino
hardware. It uses a simplified version of C++, making it accessible for beginners. Additionally,
the IDE comes with a vast collection of built-in libraries and examples, covering everything from
basic input/output operations to controlling various sensors, motors, displays, and
communication modules. This rich library ecosystem accelerates development and makes
interacting with the physical world through Arduino boards remarkably straightforward.
3) File > Preference > Setting Tab > Additional Boards Manager URLs:
Copy and Paste the following:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_inde
x.json
5) Plug in NodeMCU ESP32 module, the USB will auto installed with "Silicon Labs CP210x USB
to UART Bridge (COMX)"
*If the Windows does not able to do “auto installation”, download the driver from here:
https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers?tab=downloads
CP210x Windows Drivers v6.7.6 9/4/2020 and install the driver
6) Create a new empty *.ino file to work on Arduino C programming. Make sure your Board
selection is correct with the following configuration:
Tool > Board: “NodeMCU-32S” / “ESP32 Dev Module” / “Node32” , Port: “COMX”
8) Click Sketch > Verify / Compile and Sketch > Upload to compile the empty code and upload
to the NodeMCU ESP32 module.
BAIT2123 INTERNET OF THINGS Jul 2024
Procedure
Step 2: Connect one LED with resistors on NodeMCU ESP32 pin D25
- Use 1 Blue LED and 1kΩ registers and connect them on Pin D25. Negative (-ve) pin of
the LED connects to the common GND.
- Connect the GND to NodeMCU ESP32 GND pin.
Step 3: In your new *.ino arduino project files, understand two default functions are used
for:
- Setup Function
- Execution: Runs only once when the ESP32 board powers up or resets.
- Purpose: Primarily used for initialization tasks:
- Pin Modes: Declaring whether pins are inputs, outputs, or used for
specific protocols (e.g., pinMode(LED_BUILTIN, OUTPUT);).
- Initial States: Setting initial pin states (e.g.,
digitalWrite(LED_BUILTIN, HIGH);).
- Serial Communication: Starting the serial monitor for debugging or
communication (e.g., Serial.begin(115200);).
- Library Initialization: Configuring and initializing any libraries you're
using (e.g., for Wi-Fi, sensors, displays).
BAIT2123 INTERNET OF THINGS Jul 2024
Step 5: Insert the code to use the LED for WiFi status indication:
- In the repeating procedure, e.g., connecting to WiFi, insert the code to toggle the
LED, and set the LED to true when the WiFi is successfully connected.
Step 6: Upload the compiled code to NodeMCU ESP32 Module and observe the result.
- Click Sketch > Verify / Compile and Sketch > Upload to compile the empty code and
upload to the NodeMCU ESP32 module.
- Check if the NodeMCU ESP32 module is connected to the WiFi connection.
* Open the Serial Monitor windows to observe the Serial.println outputs.
Step 7: Connect another LED with resistors on NodeMCU ESP32 pin D23
- Use 1 White LED and 1kΩ registers and connect them on Pin D23. Negative (-ve) pin of
the LED connects to the common GND.
- Double check the common GND (blue line) is connected together on the two pieces of
breadboard.
BAIT2123 INTERNET OF THINGS Jul 2024
Step 9: Insert and merge the following code with the existing WiFi connection code:
Step 10: Upload the compiled code to NodeMCU ESP32 Module and observe the result.
- Click Sketch > Verify / Compile and Sketch > Upload to compile the code and upload to
the NodeMCU ESP32 module.
- Check if the LED at PIN23 is responding to the push button or not.