Meet the ESP32
The ESP32 is a low-cost microcontroller from Espressif that pairs a dual-core 32-bit processor with built-in WiFi and Bluetooth radios. Unlike a classic Arduino Uno, which needs an add-on shield to reach a network, the ESP32 has connectivity baked into the chip, making it the default choice for Internet-of-Things projects. Crucially, you can program it with the familiar Arduino IDE by installing the ESP32 board support package, so your existing knowledge of setup(), loop(), digitalWrite(), and libraries carries straight over. It runs at up to 240 MHz with hundreds of kilobytes of RAM, dwarfing the Uno's 16 MHz and 2 KB.
Cricket analogy: The ESP32 is an all-rounder like Ben Stokes: it bats, bowls, and fields (compute, WiFi, Bluetooth) where the Uno is a specialist needing help.
Connecting to a WiFi Network
In station mode, the ESP32 joins an existing WiFi access point just like a phone or laptop. The WiFi library handles this: call WiFi.begin(ssid, password), then poll WiFi.status() until it returns WL_CONNECTED. Once connected, WiFi.localIP() reports the address the router assigned via DHCP. The ESP32 can also run in access-point mode, creating its own network so you can connect to it directly for configuration, or in a combined mode doing both. Connecting is asynchronous, so a well-written sketch waits in a short loop rather than assuming the link is instant.
Cricket analogy: Waiting on WiFi.status() until WL_CONNECTED is like a batter watching for the umpire's raised finger before running, not assuming the call.
#include <WiFi.h>
const char* ssid = "MyNetwork";
const char* password = "secretpass";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected! IP: ");
Serial.println(WiFi.localIP());
}
void loop() {}The ESP32 supports only 2.4 GHz WiFi, not 5 GHz. If your router broadcasts a combined band under one name and the board won't connect, try creating a dedicated 2.4 GHz SSID or splitting the bands in your router settings.
Making HTTP Requests
Once online, the ESP32 becomes a genuine internet client. The HTTPClient library wraps the low-level socket work so you can call an API in a few lines: create an HTTPClient, call http.begin(url), fire http.GET() or http.POST(payload), read the status code, and pull the response body with http.getString(). This is how a sensor node uploads readings to a cloud dashboard or fetches a configuration value. For encrypted endpoints the WiFiClientSecure class adds TLS, though certificate validation and the extra memory it needs are real considerations on a constrained device.
Cricket analogy: An HTTP GET fetching data is like a fielder relaying the current score from the scoreboard back to the captain on request.
#include <WiFi.h>
#include <HTTPClient.h>
void uploadReading(float temp) {
if (WiFi.status() != WL_CONNECTED) return;
HTTPClient http;
http.begin("http://example.com/api/readings");
http.addHeader("Content-Type", "application/json");
String body = "{\"temperature\":" + String(temp) + "}";
int code = http.POST(body);
if (code > 0) {
Serial.printf("HTTP %d\n", code);
Serial.println(http.getString());
} else {
Serial.printf("POST failed: %s\n", http.errorToString(code).c_str());
}
http.end(); // free resources
}Never hard-code WiFi passwords or API keys directly in sketches you plan to share or commit publicly. Anyone reading the source can read your credentials. Store secrets in a separate untracked header, use the ESP32's non-volatile storage, or provision them at runtime through access-point configuration.
Pins, Power, and Gotchas
The ESP32 runs on 3.3 V logic, not 5 V, so wiring a 5 V sensor output straight to a GPIO can damage the pin. Some GPIOs are input-only or are tied to boot behavior and must be left alone at startup. The chip also supports deep-sleep modes that drop current to microamps, essential for battery projects, waking on a timer or an external pin. Keeping the radio on is power-hungry, so a common pattern is to connect, transmit a reading, then sleep, rather than staying online continuously. These constraints reward planning your pin map and power strategy before soldering.
Cricket analogy: Respecting 3.3 V limits and reserved boot pins is like knowing which balls to leave outside off-stump rather than playing every one.
- The ESP32 is a fast dual-core microcontroller with built-in WiFi and Bluetooth, programmable via the Arduino IDE.
- Install the ESP32 board package to reuse familiar setup()/loop() and library workflows.
- Use WiFi.begin() and poll WiFi.status() until WL_CONNECTED; WiFi.localIP() shows the DHCP address.
- The ESP32 supports only 2.4 GHz WiFi and runs on 3.3 V logic.
- The HTTPClient library makes GET/POST requests to APIs; WiFiClientSecure adds TLS.
- Never hard-code credentials in shared sketches; store secrets safely.
- Deep-sleep modes cut current to microamps, enabling battery-powered connect-transmit-sleep designs.
Practice what you learned
1. What makes the ESP32 especially suited to IoT projects compared to an Arduino Uno?
2. After calling WiFi.begin(ssid, password), how should a robust sketch confirm connection?
3. Which WiFi band does the ESP32 support?
4. Which library provides a high-level way to make GET and POST requests on the ESP32?
5. Why must you be careful wiring a 5 V sensor to an ESP32 GPIO?
Was this page helpful?
You May Also Like
Bluetooth Communication with Arduino
How to add wireless links to Arduino projects using Classic Bluetooth serial modules like the HC-05 and Bluetooth Low Energy on the ESP32, including pairing and data exchange.
Arduino and IoT Projects
How to turn an Arduino into a connected Internet-of-Things device using Wi-Fi boards, MQTT publish/subscribe messaging, cloud dashboards, and sensible security practices.
Power Management and Sleep Modes
Learn how to slash an Arduino's current draw from milliamps to microamps using the AVR sleep modes, watchdog timers, and interrupt-driven wake-ups for battery-powered projects.
Serial Communication Basics
Use the Serial library to send data between Arduino and a computer for debugging, monitoring sensors, and receiving commands.
Related Reading
Related Study Notes in Programming
Browse all study notesApache Spark Study Notes
Programming · 30 topics
ProgrammingApache Flink Study Notes
Programming · 30 topics
ProgrammingHadoop Study Notes
Programming · 30 topics
ProgrammingSnowflake Study Notes
Programming · 30 topics
ProgrammingApache Airflow Study Notes
Programming · 30 topics
Programmingdbt (Data Build Tool) Study Notes
Programming · 30 topics