Practical 3 - ESP32 WiFi

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

BAIT2123 INTERNET OF THINGS Jul 2024

Practical 3

Set up the NodeMCU ESP32 embedded system.

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.

ESP32 comes with the following features:


- Processor: Features either a dual-core or a single-core Xtensa LX6 microprocessor, with
clock speeds ranging up to 240 MHz.
- Memory: Includes on-chip SRAM and varying amounts of flash memory for storing code.
- Wi-Fi: Supports 802.11 b/g/n Wi-Fi standards.
- Bluetooth: Dual-mode Bluetooth (Classic and Bluetooth Low Energy - BLE)
BAIT2123 INTERNET OF THINGS Jul 2024

- 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:

- USB-to-Serial Chip: For easy programming and communication with a computer.


- Power Regulator: To handle power input.
- Reset and Flash Buttons: For programming the ESP32
- Breadboard-friendly pin layout: For easy connections.
- Arduino Compatible: NodeMCU modules often come pre-flashed with NodeMCU
firmware, allowing programming with the Lua scripting language. They are also
compatible with the Arduino IDE.

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

Arduino Integrated Development Environment (IDE) Installation

* 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.

Download the Arduino IDE 2.3.2 installer from https://www.arduino.cc/en/software


1) Install Arduino IDE by:
* Click “Install” for Adafruit Industries LLC Ports,
Arduino USB Driver(s)
libusb-win32
Genuino USB Driver
Linino Ports
* Click “Close” when Completed.
BAIT2123 INTERNET OF THINGS Jul 2024

2) Load Arduino IDE

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

4) Tools > Board: "Arduino Uno" > Boards Manager... >


Search for "esp32"
Select "esp32 by Espressif systems" and click install
(See the progress bar and wait until download and installation done)
BAIT2123 INTERNET OF THINGS Jul 2024

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 1: Set up the NodeMCU ESP32 on two pieces of breadboard


* Take note that the width size of NodeMCU ESP32 pins are not able to fit into one breadboard.

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

- Network Connection: Connecting to a Wi-Fi network or establishing


other communication channels.
- One-Time Tasks: Any other actions that need to happen only once at the
beginning.
- Loop Function
- Execution: Runs repeatedly and indefinitely after the setup() function finishes.
- Purpose: Contains the main logic of your program:
- Reading Sensors: Get data from sensors attached to the ESP32.
- Processing Data: Perform calculations or make decisions based on
sensor readings.
- Controlling Outputs: Turn LEDs on/off, control motors, or send signals
to other components.
- Sending/Receiving Data: Communicate with other devices or services
over networks like Wi-Fi or Bluetooth.
- Periodic Tasks: Execute actions at regular intervals (e.g., checking for
updates, sending status messages).
- Responding to Events: React to button presses, sensor triggers, or
incoming network messages.
● Important Considerations:
- Non-Blocking Code: Avoid long delays or blocking operations in the loop()
function. Instead, use timers, interrupts, or task scheduling to ensure your code
remains responsive.
- Global Variables: Variables declared outside both setup() and loop() are
accessible from both functions.

Step 4: Modify the default *.ino code to the following codes:


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 8: Connect a new push button at pin D15


- One side of the push button connects to the NodeMCU ESP32 pin D15 and another side
of the push button connects to the common GND.

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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy