Electronics for Building Things · Lesson 19 · Connectivity

Getting on Wi-Fi

The first step in making a gadget you can reach from anywhere in the house.

This track is the REPORT arrow from Lesson 18's SENSE → DECIDE → ACT → REPORT loop — and the reason you chose an ESP32 in the first place. It starts here: getting your board onto your home network so it can talk to your phone, a server, or Home Assistant.

The one win You understand how an ESP32 joins your Wi-Fi network and gets an address other devices can reach it at — and you know the gotchas that trip up every beginner.

Two Wi-Fi modes

(It can even do both at once, but start with station mode.)

What the code does

You don't need to memorize syntax, but recognize the shape — every Wi-Fi sketch follows it (Random Nerd Tutorials: ESP32 Wi-Fi functions):

  1. Set station mode and call WiFi.begin(ssid, password) with your network name and password.
  2. Wait in a short loop until WiFi.status() reports WL_CONNECTED — joining takes a moment.
  3. Read WiFi.localIP() — the IP address your gadget was given.

The IP address: your gadget's house number

When the ESP32 joins, your router hands it an IP address (e.g. 192.168.1.42) — its address on your local network. Other devices in your house reach it at that number. (Next lesson, you'll type it into a browser to control the gadget.)

Tip Router-assigned IPs can change. For something you'll connect to often, set a static IP (or a DHCP reservation in your router), or give the board a hostname and reach it by name (more in Lesson 20).

The gotchas that waste hours

Read these now, thank yourself later

Check yourself

Read this next (primary source) Random Nerd Tutorials — Getting Started with the ESP32, then ESP32 Wi-Fi Functions for the connection code.
I'm your teacher — ask me anything. If your ESP32 won't connect, tell me what you see — nine times in ten it's the 2.4 GHz issue or a typo in the credentials, and I can help you spot it.

See also: Glossary · Connectivity cheat-sheet · Rules of thumb