Introduction to ESP32 — Comparison with Arduino UNO and Servo Sweep Example
ESP32 is a powerful Wi-Fi + Bluetooth microcontroller, ideal for IoT projects. Below you’ll find key facts, a comparison with Arduino UNO, and a practical example of controlling a servo motor (sweep) using ESP32.
What ESP32 Looks Like and Key Features
- Dual-core 32-bit processor (Xtensa) @ 160–240 MHz
- Built-in Wi-Fi and Bluetooth
- Plenty of GPIO pins with PWM, ADC, DAC, I2C, SPI, UART support
- More RAM/Flash memory compared to Arduino UNO
- Popular development boards: ESP32 DevKitC, NodeMCU-32S
ESP32 vs Arduino UNO
| Feature | ESP32 | Arduino UNO |
|---|---|---|
| CPU | 32-bit Dual-core, up to 240 MHz | 8-bit AVR, 16 MHz |
| Wi-Fi / Bluetooth | Yes | No (requires extra module) |
| RAM / Flash | hundreds of KB / MB | 2 KB SRAM / 32 KB Flash |
| GPIO | ~34 (depends on module) | 14 digital + 6 analog |
| Best for | IoT, wireless devices, complex projects | Learning, simple projects |
Where ESP32 is Used
- Smart devices (home automation)
- IoT sensors and gateways
- Robotics with wireless control
- Audio and multimedia projects (thanks to fast CPU)
Powering and Servo Connection Notes
- ESP32 uses 3.3V logic. Most servo signal pins are compatible, but power usually requires 5V.
- Do not power the servo directly from ESP32’s 3.3V pin — use an external 5V supply if the servo draws significant current.
- Always connect servo GND to ESP32 GND.
- Add a capacitor (100–470 µF) across 5V and GND near the servo to reduce voltage drops under load.
Basic Wiring (servo connection)
- Servo signal → GPIO pin (e.g., GPIO 18)
- Servo VCC → external +5V supply
- Servo GND → common ground with ESP32
Example — Servo Sweep with ESP32
This example uses the ESP32Servo library. Connect servo signal to GPIO 18, VCC to 5V (external), and GND common with ESP32.
// ESP32 Servo Sweep — using ESP32Servo library
#include <ESP32Servo.h>
Servo myServo;
const int servoPin = 18; // example: GPIO18
void setup() {
myServo.attach(servoPin);
}
void loop() {
// sweep from 0 to 180 degrees
for (int pos = 0; pos <= 180; pos += 1) {
myServo.write(pos);
delay(15);
}
// and back from 180 to 0
for (int pos = 180; pos >= 0; pos -= 1) {
myServo.write(pos);
delay(15);
}
}
Extra Tips
- If the servo jitters, check power supply and add a capacitor near VCC/GND.
- For multiple servos, use external power and ensure common ground.
- For advanced projects, use ESP32 hardware timers or PWM driver libraries.
Read more about servo motors here: Introduction to Servo Motors
Where is ESP32 used?
The ESP32 is an extremely versatile microcontroller, widely used in various projects ranging from hobby electronics to professional IoT solutions. With its built-in Wi-Fi and Bluetooth modules, it enables wireless communication and internet connectivity without extra hardware. This makes it perfect for projects that require remote control, data collection, or automation.
Examples of ESP32 applications
- IoT Projects – ESP32 is often used in smart home systems to monitor temperature, humidity, or light levels. For example, with a DHT22 sensor, it can track room climate and automatically control ventilation or AC units over the internet.
- Robotics – thanks to PWM support and multiple GPIO pins, ESP32 can control servo and DC motors. You can build an autonomous car or a robot controlled via Wi-Fi or Bluetooth connection with a smartphone.
- Wearable Devices – due to its compact size and low power consumption, ESP32 is widely used in smartwatches and fitness trackers. For instance, it can measure heart rate using a sensor and send the data to a mobile app.
- Audio Applications – ESP32 supports digital audio interfaces, making it suitable for projects such as internet radio stations or wireless speakers. With the addition of a small display, you can even build your own internet streaming radio receiver.
- Industrial Applications – in industrial environments, ESP32 is used for remote monitoring of machines and process automation. For example, it can collect data from sensors about motor operation and send it to a cloud platform for predictive maintenance.
These are just a few examples. On the upcoming pages, we will provide detailed tutorials and practical ESP32-based projects that you can try out yourself.
Preparing the Arduino IDE for ESP32 Projects
This module continues the Introduction to ESP32 and gives practical, step‑by‑step guidance for preparing the Arduino IDE so you can start building ESP32 projects (including the servo sweep example shown earlier). It’s written as a short, web‑friendly article with clear actions, recommendations and a compact starter checklist.
1. Install the ESP32 Arduino Core (Board Manager)
The Arduino Core for ESP32 enables the IDE to compile and upload sketches to ESP32 boards. It is not the firmware of the chip — it’s the toolchain and libraries used by the IDE.
- Open File → Preferences in Arduino IDE.
- In Additional Boards Manager URLs add:
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json - Open Tools → Board → Boards Manager…, search ESP32, find esp32 by Espressif Systems and install. Choose version 3.3.1 if you want the recommended stable release.
2. Select Board and Port
- Go to Tools → Board and pick an appropriate entry (e.g. ESP32 Dev Module or your specific model).
- Connect the board via USB and select the correct Port in Tools → Port.
- If upload fails, try different USB cable or set upload speed to
115200in the Tools menu.
3. Install Recommended Libraries (Library Manager)
Some libraries are not bundled with the ESP32 core and should be installed from the Arduino Library Manager (Sketch → Include Library → Manage Libraries…):
- ESP32Servo — servo control adapted for ESP32.
#include <ESP32Servo.h> - ArduinoJson — JSON parsing for REST / IoT communication.
#include <ArduinoJson.h> - Adafruit Unified Sensor + DHT sensor library — for temperature/humidity sensors.
#include <DHT.h> - Adafruit GFX + Adafruit SSD1306 — for common OLED displays.
#include <Adafruit_SSD1306.h> - EEPROM — storing small values across resets.
#include <EEPROM.h> - AsyncTCP and ESPAsyncWebServer — for responsive web servers (install from GitHub if not in Library Manager).
4. Useful Built‑in Headers (no extra install)
The ESP32 core already exposes these APIs — include them directly in your sketches:
#include <WiFi.h>
#include <HTTPClient.h>
#include <Wire.h> // I2C
#include <SPI.h> // SPI
#include <Preferences.h> // non-volatile key-value storage (better than EEPROM for many uses)
5. Power & Wiring Best Practices
- ESP32 logic is 3.3V. Most servo control signals are compatible with 3.3V logic, but the servo power line is usually +5V.
- Use a dedicated external 5V supply for servos that draw more than a few hundred mA. Connect servo GND to ESP32 GND.
- Add a decoupling capacitor (100–470 μF) across the servo power rails to reduce voltage droops when the servo starts.
- If a servo jitters, first check power and ground wiring before changing code or libraries.
6. Quick Checklist for a New ESP32 Project
- Install ESP32 core (version 3.3.1 recommended).
- Select exact board and port in Tools.
- Install these libraries in Library Manager: ESP32Servo, ArduinoJson, Adafruit Unified Sensor, DHT sensor, Adafruit GFX, Adafruit SSD1306.
- Wire the hardware with proper power supply & common ground.
- Open an example (File → Examples) to verify upload and Serial Monitor communication.
7. Small Starter Sketch (includes & note)
This tiny header shows the typical includes you’ll use in many ESP32 projects. Make sure the indicated libraries are installed:
#include <ESP32Servo.h> // install via Library Manager
#include <WiFi.h> // builtin
#include <HTTPClient.h> // builtin
#include <ArduinoJson.h> // install via Library Manager
// rest of your sketch ...
8. Extra Tips & Troubleshooting
- Use the Examples provided by each library to learn API usage quickly.
- If a library doesn’t appear in Library Manager, search GitHub and follow the author’s install instructions (some libs like ESPAsyncWebServer require manual install).
- When copy/pasting code from Arduino UNO examples, double‑check pin numbers and voltage assumptions — ESP32 pins and voltages differ.
- Prefer Preferences (built into ESP32 core) over raw EEPROM for structured persistent storage.
9. Recommended Starter Library Bundle
Install these right away to avoid interruptions later:
- ESP32Servo
- ArduinoJson
- Adafruit Unified Sensor
- DHT sensor library
- Adafruit GFX + Adafruit SSD1306
- Preferences / EEPROM (built-in)
With this module in place next to the earlier introduction, readers will have a compact, practical reference to prepare their environment and avoid the most common pitfalls when starting ESP32 projects in Arduino IDE.
If you want, I can also create a downloadable checklist (PDF) or a slightly shorter "Quick Start" card to place above the example. Tell me which you prefer.
10. USB Drivers & Troubleshooting (Windows)
Sometimes Windows doesn't automatically install the USB‑to‑Serial driver for your ESP32 board. Common symptoms include: no COM port shown in Tools → Port, Device Manager showing entries under Other devices such as CP2102 USB to UART..., or only an ECP Printer Port appearing.
Which drivers you may need
- CP210x (Silicon Labs) — common on many ESP32 dev boards (look for a small chip marked CP2102/CP210x on the board).
- CH340 / CH341 (WCH) — common on low‑cost or clone boards.
Install from EXE (easy)
- If the ZIP you downloaded contains an installer (e.g.
CP210xVCPInstaller_x64.exe), right‑click it and choose Run as administrator. - Follow the install wizard, then unplug and replug the board.
Manual install (ZIP with no EXE)
- Extract the ZIP to a simple folder, e.g.
C:\CP210x_Driver\. - Open Device Manager. Find the device under Other devices (e.g. "CP2102 USB to UART...").
- Right‑click the device → Update driver → Browse my computer for drivers.
- Point to the extracted folder and make sure Include subfolders is checked, then click Next.
- If Windows warns the driver is unsigned, choose Install anyway (only if you downloaded the driver from a trusted source such as Silicon Labs or WCH).
Verify successful install
- Device Manager → Ports (COM & LPT) should show
CP210x USB to UART Bridge (COMx)orUSB‑SERIAL CH340 (COMx). - Arduino IDE → Tools → Port should now list the COM port for your board.
If it still doesn't work
- Try a different USB cable — many cables are power‑only and don't carry data.
- Try a different USB port on the PC (avoid USB hubs).
- Restart Windows after driver installation.
- During upload, if automatic bootloader entry fails, press and hold the board's BOOT button while clicking Upload.
- On macOS / Linux check terminals:
ls /dev/tty.*orls /dev/ttyUSB*to find the device.
This section helps users diagnose and fix the most common cause of “no port” problems when connecting an ESP32 to Arduino IDE. If you want, I can add illustrated step‑by‑step screenshots for Windows driver installation or generate a downloadable PDF quick‑start checklist.
11. Parts of the ESP32‑D Board (what each part does)
This short reference describes the physical parts you’ll find on a typical ESP32‑D development board and what each part does — useful for beginners and helpful when wiring or troubleshooting.
- ESP32 module (ESP‑WROOM‑32 / ESP32‑D) — the system‑on‑chip module containing the Xtensa CPU cores, Wi‑Fi/Bluetooth radios and the SPI flash. This is where your sketch runs.
- USB‑to‑Serial converter (CP2102 / CH340) — translates USB to UART so the PC can upload sketches and open a Serial Monitor. If this chip lacks a driver, Windows will not show a COM port.
- USB connector (Micro‑USB / USB‑C) — supplies 5V from the host and carries serial data. Use a data‑capable cable (not power‑only) for uploads.
- Voltage regulator (5V → 3.3V) — steps down USB 5V to a stable 3.3V that powers the ESP32 core and many peripherals. The 3.3V pin is the logic rail for GPIOs.
- SPI Flash chip — external flash memory that stores your program, filesystem (SPIFFS/LittleFS) and other persistent data.
- EN / RESET pin (sometimes labeled RST) — when pulled low, resets the ESP32. Useful for manual restart and recovering from some faults.
- BOOT (GPIO0) button — used to enter the bootloader mode on some boards (hold while uploading if auto‑reset fails).
- Power LED — shows that the board is powered. If this lights but no COM port appears, the USB‑to‑Serial driver may be missing.
- User LED(s) — one or more LEDs connected to GPIOs for quick testing and status indicators (commonly tied to GPIO2 or other pins).
- Header pins / GPIOs — rows of pins exposing: digital I/O, ADC inputs, DAC outputs, PWM (LEDC), I2C (SDA/SCL), SPI (MOSI/MISO/SCLK), UART (TX/RX), touch pins and more. Check your board’s pinout for safe GPIO choices.
- VIN / 5V pin — an input that accepts an external 5V supply (not all boards expose VIN). Use it to power the board when USB is not used.
- 3V3 pin — the regulated 3.3V output from the onboard regulator (can power small sensors).
- GND pins — ground reference; always connect all grounds together (ESP32, servo power supply, sensors).
- Antenna / U.FL connector — either a PCB/ceramic antenna or an external antenna connector. Proper antenna placement affects Wi‑Fi range.
- Strapping resistors & boot pins — small resistors that set default boot mode; certain pins must be in the correct state during reset for normal boot (e.g. GPIO0, GPIO2, GPIO15 on some variants).
Important electrical notes
- ESP32 GPIOs are 3.3V logic. Do not apply 5V to GPIO pins — use level shifters where needed.
- Power servos from an external 5V supply and always connect the external supply ground to the ESP32 GND.
- When using ADC pins, avoid voltages above 3.3V and consult the board documentation for recommended ADC pins and voltage dividers.
ESP32-D Pinout – Description and Functions
The ESP32-D (ESP32-WROOM-32 on DevKit V1 board) has two rows of pins (left and right side of the module). Each pin can have multiple functions, such as digital input/output, PWM, ADC, DAC, touch sensor, I2C, SPI, or UART. Some pins are input-only, while others are reserved and should not be used. Below is a detailed pinout reference.
Left Side Pins
| Pin # | Label | Type | Description |
|---|---|---|---|
| 1 | 3V3 | Power | 3.3V power output |
| 2 | EN | Input | Reset/Enable pin |
| 3 | VP (GPIO36) | Input only, ADC1 | Analog input, no digital output |
| 4 | VN (GPIO39) | Input only, ADC1 | Analog input |
| 5 | GPIO34 | Input only, ADC1 | Analog input |
| 6 | GPIO35 | Input only, ADC1 | Analog input |
| 7 | GPIO32 | I/O, ADC1, Touch | Digital I/O, PWM, touch sensor |
| 8 | GPIO33 | I/O, ADC1, Touch | Digital I/O, PWM, touch sensor |
| 9 | GPIO25 | I/O, ADC2, DAC1 | Digital I/O, PWM, DAC output |
| 10 | GPIO26 | I/O, ADC2, DAC2 | Digital I/O, PWM, DAC output |
| 11 | GPIO27 | I/O, ADC2, Touch | Digital I/O, PWM, touch sensor |
| 12 | GPIO14 | I/O, ADC2, Touch, HSPI CLK | Often used as SPI clock |
| 13 | GPIO12 | I/O, ADC2, Touch | Used in boot mode, caution required |
| 14 | GPIO13 | I/O, ADC2, Touch | General purpose I/O |
| 15 | GND | Power | Ground |
| 16 | GPIO9 | Reserved | Internal flash, do not use |
| 17 | GPIO10 | Reserved | Internal flash, do not use |
| 18 | GPIO11 | Reserved | Internal flash, do not use |
| 19 | 5V | Power | 5V input (from USB or external) |
Right Side Pins
| Pin # | Label | Type | Description |
|---|---|---|---|
| 1 | GND | Power | Ground |
| 2 | GPIO23 | I/O, VSPI MOSI | Digital I/O, PWM, SPI MOSI |
| 3 | GPIO22 | I/O, I2C SCL | Digital I/O, I2C clock |
| 4 | GPIO1 (TX0) | I/O, UART TX | Default UART transmit |
| 5 | GPIO3 (RX0) | I/O, UART RX | Default UART receive |
| 6 | GPIO21 | I/O, I2C SDA | Digital I/O, I2C data |
| 7 | GPIO19 | I/O, VSPI MISO | Digital I/O, SPI MISO |
| 8 | GPIO18 | I/O, VSPI SCK | Digital I/O, SPI clock |
| 9 | GPIO5 | I/O, VSPI CS | Digital I/O, SPI chip select |
| 10 | GPIO17 | I/O, UART2 TX | Digital I/O, UART transmit |
| 11 | GPIO16 | I/O, UART2 RX | Digital I/O, UART receive |
| 12 | GPIO4 | I/O, ADC2, Touch | Digital I/O, PWM, touch sensor |
| 13 | GPIO0 | I/O, ADC2, Touch, BOOT | Boot mode selection pin |
| 14 | GPIO2 | I/O, ADC2, Touch | Digital I/O, PWM, touch sensor |
| 15 | GPIO15 | I/O, ADC2, Touch | General purpose I/O |
| 16 | GPIO8 | Reserved | Internal flash, do not use |
| 17 | GPIO7 | Reserved | Internal flash, do not use |
| 18 | GPIO6 | Reserved | Internal flash, do not use |
| 19 | GND | Power | Ground |
Additional Notes
- Input-only pins: GPIO36, GPIO39, GPIO34, GPIO35
- Boot pins: GPIO0, GPIO2, GPIO12 affect boot mode – use with caution
- Reserved pins: GPIO6–11 (used for internal flash, do not connect)
- General-purpose pins: Most other GPIOs can be used as PWM, UART, I2C, SPI, etc.

