Motion alarm
A PIR sensor triggers a buzzer when someone moves.
- Digital input and output
- Timing with millis()
- Parts: PIR sensor, buzzer
Everything you need to go from "what is an ESP32?" to a working project: choosing a board, setting up, your first program, the electronics you actually need to know, and five easy first builds with complete step-by-step guides.
An ESP32 is a tiny, low-cost computer chip made by Espressif, built into a small circuit board you can plug into a computer. It runs one program that you write, over and over, and it has Wi-Fi and Bluetooth built in. You connect sensors, lights, motors and displays to its pins, and the program decides what to do with them.
People use it for smart-home devices, weather stations, plant monitors, alarms, LED displays, robots, cameras and anything else that needs a bit of logic and an internet connection. A typical board costs a few dollars.
| Arduino Uno | ESP32 | Raspberry Pi | |
|---|---|---|---|
| What it is | Simple microcontroller | Microcontroller with Wi-Fi and Bluetooth | Full Linux computer |
| Wi-Fi / Bluetooth | No (add-on needed) | Built in | Built in on most models |
| Speed | 16 MHz | Up to 240 MHz, often two cores | Over 1000 MHz, multiple cores |
| Pin voltage | 5V | 3.3V | 3.3V |
| Power use | Low | Low (deep sleep possible) | Much higher |
| Runs an operating system | No | No (runs your program directly) | Yes |
| Best for | Learning basics | Connected gadgets and sensors | Anything that needs a full computer |
The one thing to remember. ESP32 pins run at 3.3 volts. Many cheap parts are 5V. You will learn how to handle that, but never connect a 5V signal straight to an ESP32 pin.
There are many ESP32 chips and boards. For learning, get the classic ESP32 development board (often sold as "ESP32 DevKit V1" or "ESP-WROOM-32", with 30 or 38 pins). It has the most tutorials, the most pins, and the widest support, and every guide on this site works with it. You can move to newer chips later.
Not sure? See the ESP32 board comparison for every board in the Build Finder, with a "which should I pick?" table. If you want a screen for a smart-home panel, see the touch panel guide after you finish the basics.
A starter set is cheap. Everything below has a buy link. Required items first, then the optional parts each of the five projects uses, so you can buy them as you go.
Some links are affiliate links, so I may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases. Details. Buy buttons open a store search; check the product matches before you order.
Cheap tip: a "starter kit" that bundles a breadboard, wires, LEDs, resistors and buttons is often cheaper than buying each separately. Buy the ESP32 board separately so you choose the right one.
You will use the Arduino IDE, a free program for writing code and sending it to the board. (Despite the name, it works with ESP32 boards too.)
dialout group.If any step differs on your computer (menus change slightly between versions), the official Espressif installation guide has the current instructions.
Blink is the "Hello, world" of electronics: flash a light on and off. It proves your whole set-up works, and every project after this builds on the same idea.
Board unplugged from USB. An LED must always have a resistor in series (220 ohms is fine) or it can burn out. The LED also has a direction: the longer leg is positive.
Congratulations if it blinked! You have set up everything you need. If it did not, see Troubleshooting below before going further.
A solderless breadboard lets you build circuits by pushing wires and components into holes. Inside, the holes in each short column are connected together, so two things plugged into the same column are connected. The long rows along the edges (the rails) are usually used for power and ground.
| Kind | What it is | Example |
|---|---|---|
| Digital in/out | Just two states: HIGH (3.3V) or LOW (0V). | Button, PIR sensor, LED on/off, relay |
| Analog input | Measures a voltage and returns 0 to 4095. | Soil sensor, light sensor, dial |
| PWM output | Switches on and off very fast to fake an in-between level. | Dimming an LED, servo position |
| I2C | Two wires (SDA, SCL) shared by many chips, each with an address. | BME280, OLED displays |
| UART (serial) | Two wires (TX, RX) to talk to one device. | GPS, some radar and fingerprint sensors |
| SPI | Four wires, fast. Used for big displays and SD cards. | TFT displays, microSD |
An ESP32 has many pins, but not all are equal. This is the short, safe version for a classic ESP32 DevKit (pin names are the numbers after "GPIO"):
| Pins | Use |
|---|---|
| 4, 13, 14, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 32, 33 | Good all-round choices for buttons, LEDs, relays and sensors. |
| 32, 33, 34, 35, 36, 39 | Analog inputs that keep working with Wi-Fi on (ADC1). Pins 34, 35, 36 and 39 are input only. |
| 21 and 22 | The default I2C pins (SDA and SCL) for sensors and displays. |
| 0, 2, 12, 15 | "Strapping" pins that affect how the board starts. Avoid them, or connect only light loads, until you know what you are doing. |
| 6 to 11 | Connected to the board's flash memory. Never use these. |
| 1 and 3 | Used for the USB serial connection. Avoid. |
| 3V3, 5V (VIN), GND | Power pins. 3V3 powers 3.3V parts; 5V (VIN) comes from USB; GND is ground. |
Analog trap. On the classic ESP32, analog pins in the "ADC2" group (GPIO 0, 2, 4, 12 to 15, 25 to 27) stop working while Wi-Fi is on. For analog sensors in a Wi-Fi project, use GPIO 32 to 39.
An Arduino program is called a sketch, and it always has two parts:
setup() runs once when the board starts. Use it to set pin modes and connect to Wi-Fi.loop() runs forever afterwards. This is where the work happens.| You write | It means |
|---|---|
pinMode(4, OUTPUT); | Pin 4 will send signals out. (INPUT to read; INPUT_PULLUP for a button.) |
digitalWrite(4, HIGH); | Switch pin 4 on (3.3V). LOW is off. |
int v = digitalRead(27); | Read pin 27: 1 (HIGH) or 0 (LOW). |
int a = analogRead(34); | Read an analog value from 0 to 4095. |
delay(500); | Pause for 500 milliseconds. The board does nothing else meanwhile. |
Serial.println("Hi"); | Print a line to the Serial Monitor. Your best debugging tool. |
if (x > 10) { ... } | Only do this when the condition is true. |
const int LED_PIN = 4; | Give a name to a number so the code is readable and easy to change. |
delay() vs millis(). delay() is simple but freezes the program. millis() returns the time since power-on, so you can check "has 5 seconds passed?" while doing other things. The motion alarm guide shows how.
When code will not compile, read the first red error line. Common causes: a missing semicolon ;, a missing closing brace }, a library you have not installed, or the wrong board selected.
WiFi.begin("name", "password").| Problem | What to try |
|---|---|
| No port in the Tools menu | Try another USB cable (it must carry data) and port. Install the CH340 or CP210x driver. Unplug and replug. |
| "Failed to connect to ESP32" or "Wrong boot mode detected" | Hold the BOOT button from the moment the upload says "Connecting..." until it starts writing. Release it after. |
| Upload works but nothing happens | Press the EN (reset) button. Check the Serial Monitor is set to 115200 baud. |
| Garbled text in the Serial Monitor | The baud rate is wrong. Set it to 115200 to match Serial.begin(115200). |
| "Brownout detector was triggered" or random restarts | The board is not getting enough power. Use a different USB cable or port, and keep wires from motors and relays short. |
| "fatal error: WiFi.h: No such file" | The wrong board is selected. Choose ESP32 Dev Module under Tools, Board, esp32. |
| "Port busy" or "Access denied" | Another program (such as an open Serial Monitor in another window) is using the port. Close it. |
| A circuit does not work | Re-check every wire against the diagram. Confirm GND is connected. Check power with a multimeter. Read the part's labels: pin order varies. |
Each one introduces one new idea and has a complete guide with a parts list (with buy links), a wiring diagram, full code and troubleshooting. Do them in order.
A PIR sensor triggers a buzzer when someone moves.
Turn a low-voltage device on and off from a web page on your phone.
Show temperature, humidity and pressure on a web page.
A desk clock that sets itself from the internet.
Know when your plant needs water, on a web page, with an LED alert.
INPUT_PULLUP turns it on.