
Why the ESP32?
I've been using the ESP32 in my field projects for a few years. When I first started, I was amazed at how much a single microcontroller could do. This board, the successor to the ESP8266, has Wi-Fi and Bluetooth on the same chip, and it's very reasonably priced for hobby projects. But these are the features that really stand out:
- Dual-core processor: Two cores at 240 MHz. One can handle communication while the other keeps reading sensors.
- Built-in Wi-Fi and Bluetooth: No external modules to deal with. You can connect straight to the network and send data.
- Number and variety of GPIOs: Many interfaces are available, including ADC, DAC, touch pins, SPI, I2C and UART.
- Low-power modes: Deep sleep makes life much easier for battery-powered projects.
Setting Up the Development Environment
I usually use PlatformIO because project management and library dependencies are tidier. For beginners, though, adding the board in the Arduino IDE is very simple: type esp32 into the Boards Manager and install the Espressif package. Then select "ESP32 Dev Module" and upload over USB.
On Windows you may need the CP210x or CH340 USB driver. If no port shows up when you plug in the board, check the driver first.
Pinout and Things to Watch Out For
The ESP32's pinout can be confusing at first glance. The point I pay most attention to: GPIO numbers are not the same as the physical pin numbers on the board. Always use the GPIO number in your code.
Another critical issue is the logic level. The ESP32 runs at 3.3V. If you connect a 5V sensor or relay without a level shifter, you can burn the pin. I once connected a sensor with a 5V output directly and ruined GPIO36.
- Input-only pins: GPIO 34, 35, 36 and 39 can only be used as inputs and have no pull-up/pull-down resistors. Don't use them as outputs.
- Boot-mode pins: GPIO0, GPIO2, GPIO5, GPIO12 and GPIO15 must be in a specific state during upload. Be careful if your circuit connects anything to these pins.
- ADC: It offers 12-bit resolution, but the noise is fairly high. For precise measurements an external ADC may make more sense.
First Project: Controlling an LED over Wi-Fi
The simplest IoT project is switching an LED on and off from a web page. I usually start with this one because it tests both the Wi-Fi connection and GPIO control.
For the circuit, an LED and a 220-ohm resistor are all you need. Connect the LED's long leg to GPIO2 and the short leg to GND through the resistor. Since GPIO2 is also wired to the built-in LED on most development boards, you can even try it without any wiring.
On the software side, the ESP32 runs a small web server. Once the board joins the network it prints its IP address to the serial monitor; open that address in your phone's browser and tap the /on or /off link to switch the LED. With the WebServer library in the Arduino IDE, this takes fewer than thirty lines:
- setup(): Set GPIO2 as an output, connect to the network with WiFi.begin(), define a handler for each of the two addresses and start the server.
- loop(): Just call server.handleClient(); the server takes care of incoming requests.
- Tip: Give the ESP32 a fixed IP in your router so the address doesn't change on every boot.
The Next Step: MQTT
A web server is fine for a single device, but as the number of devices grows, keeping track of every address gets hard. That's where MQTT comes in. Devices connect to a central broker; they publish sensor data to one topic and listen for commands on another. A Mosquitto broker running on a Raspberry Pi at home is more than enough for most projects. In my Smart Pot project, the measurements reach the home network exactly this way.
The nice thing about MQTT is that messages are small and a device can pick up where it left off after a dropped connection. A battery-powered sensor wakes up, publishes its reading and goes back into deep sleep, so it can run for months without a battery change.
Final Words
You don't need expensive equipment to get started with the ESP32: a board, a USB cable, a few LEDs and a sensor are enough. Light the LED first, then read a sensor, and finally send the data to a dashboard over MQTT. Each step lays the groundwork for the next. If you get stuck, feel free to get in touch.
ASILTECHSOFT