What you'll build: make the on-board LED blink, list the Wi-Fi networks near you, then switch the LED on and off from your phone. No wiring needed · About 30 minutes.
Part 1 — Set up Arduino IDE (once only)
1
Install Arduino IDEDownload and install
Arduino IDE 2 for Windows, macOS or Linux.
2
Add the ESP32 board addressOpen
File → Preferences (macOS:
Arduino IDE → Settings). In
Additional boards manager URLs, paste:
https://espressif.github.io/arduino-esp32/package_esp32_index.jsonClick OK. (
Official install guide)
3
Install the ESP32 boards
Open Tools → Board → Boards Manager, search esp32, and install "esp32 by Espressif Systems". This can take a few minutes.
4
Choose the board
Go to Tools → Board → esp32 and pick LOLIN S2 Mini. Leave Tools → USB CDC On Boot on Enabled (the default) — this sends Serial messages over the USB-C port.
✓ Check: Tools → Board shows "LOLIN S2 Mini".
Part 2 — Upload your first sketch
5
Plug in and enter upload mode
Connect the board with a data USB-C cable (charge-only cables don't work). The first time, put it into upload mode: hold the 0 button, press and release RST, then release 0. A new port appears under Tools → Port — select it. The ESP32-S2 uses its own USB. If no port appears, use a data USB cable (not charge-only) and install the USB driver for your board.
6
Upload Example 1
Copy Example 1 into a new sketch and click Upload (→). When the IDE says it is done, press RST once to start your program. If the upload fails, set Tools → Upload Speed → 115200 and upload again.
▸ Example 1 — Blink the on-board LED
// ESP32-S2 Mini - Example 1: blink the on-board LED and print to the Serial Monitor
// Wiring: nothing to wire - the LED is on the board (GPIO15)
const int LED_PIN = 15; // on-board LED on GPIO15 (same as LED_BUILTIN)
const unsigned long BLINK_MS = 500; // ✏️ you can change this (milliseconds)
void setup() {
Serial.begin(115200); // speed must match the Serial Monitor
delay(1500); // give the built-in USB port time to connect
pinMode(LED_PIN, OUTPUT); // the LED pin is an output
Serial.println("OK - epartners.co.nz test");
}
void loop() {
digitalWrite(LED_PIN, HIGH); // LED on
Serial.println("LED on");
delay(BLINK_MS);
digitalWrite(LED_PIN, LOW); // LED off
Serial.println("LED off");
delay(BLINK_MS);
}
7
Open the Serial Monitor
After reset the port name can change — re-select it under Tools → Port, then open Tools → Serial Monitor and set the speed to 115200 baud (115200 is the "talking speed" set in the sketch).
✓ Check: The on-board LED blinks every half second, and the Serial Monitor prints "OK - epartners.co.nz test" once, then "LED on" / "LED off". If you miss the first line, press RST.
Next uploads: with "USB CDC On Boot" enabled, you can usually just click Upload. If the port disappears or the upload won't start, use the 0 + RST button method from step 5 again.
Part 3 — First Wi-Fi projects
8
Scan for Wi-Fi networks
Upload Example 2 and open the Serial Monitor (115200 baud). The board only uses 2.4 GHz Wi-Fi — 5 GHz-only networks will not appear.
▸ Example 2 — Wi-Fi scanner
// ESP32-S2 Mini - Example 2: list the Wi-Fi networks around you
// Wiring: nothing to wire
#include <WiFi.h>
void setup() {
Serial.begin(115200);
delay(1500); // give the built-in USB port time to connect
WiFi.mode(WIFI_STA); // station mode = join networks, don't create one
WiFi.disconnect();
Serial.println("OK - epartners.co.nz test");
}
void loop() {
Serial.println("Scanning...");
int count = WiFi.scanNetworks(); // returns how many networks were found
if (count == 0) {
Serial.println("No networks found");
} else {
for (int i = 0; i < count; i++) {
Serial.print(i + 1);
Serial.print(": ");
Serial.print(WiFi.SSID(i)); // network name
Serial.print(" (");
Serial.print(WiFi.RSSI(i)); // signal strength in dBm, closer to 0 = stronger
Serial.println(" dBm)");
}
}
WiFi.scanDelete(); // free the memory used by the scan
delay(10000); // ✏️ you can change this - wait 10 s before the next scan
}
✓ Check: Every 10 seconds you see a numbered list of nearby network names with their signal strength, e.g. "1: MyHomeWiFi (-52 dBm)".
9
Control the LED from your phone
In Example 3, type your Wi-Fi name and password on the two lines marked ✏️, then upload it. Keep your phone on the same Wi-Fi network.
▸ Example 3 — Web page LED switch
// ESP32-S2 Mini - Example 3: switch the on-board LED from your phone over Wi-Fi
// Wiring: nothing to wire - the LED is on the board (GPIO15)
#include <WiFi.h>
#include <WebServer.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME"; // ✏️ your 2.4 GHz Wi-Fi name
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD"; // ✏️ your Wi-Fi password
const int LED_PIN = 15; // on-board LED on GPIO15
WebServer server(80); // web server on port 80 (normal http)
bool ledOn = false;
void sendPage() {
String page = "<!DOCTYPE html><html><head>";
page += "<meta name='viewport' content='width=device-width, initial-scale=1'>";
page += "</head><body style='font-family:sans-serif; text-align:center;'>";
page += "<h1>ESP32-S2 Mini</h1><p>LED is ";
page += ledOn ? "ON" : "OFF";
page += "</p><p><a href='/on'><button>ON</button></a> ";
page += "<a href='/off'><button>OFF</button></a></p></body></html>";
server.send(200, "text/html", page);
}
void handleOn() { ledOn = true; digitalWrite(LED_PIN, HIGH); sendPage(); }
void handleOff() { ledOn = false; digitalWrite(LED_PIN, LOW); sendPage(); }
void setup() {
Serial.begin(115200);
delay(1500); // give the built-in USB port time to connect
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);
Serial.println("OK - epartners.co.nz test");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
Serial.print("Connecting to Wi-Fi");
int tries = 0;
while (WiFi.status() != WL_CONNECTED && tries < 40) { // wait up to 20 seconds
delay(500);
Serial.print(".");
tries++;
}
if (WiFi.status() != WL_CONNECTED) {
Serial.println();
Serial.println("Wi-Fi not connected - check the name and password");
return; // stop here; press RST to try again
}
Serial.println();
Serial.print("Open this address in your browser: http://");
Serial.println(WiFi.localIP());
server.on("/", sendPage); // home page
server.on("/on", handleOn); // LED on
server.on("/off", handleOff); // LED off
server.begin();
}
void loop() {
server.handleClient(); // answer browser requests
}
10
Open the web page
The Serial Monitor prints an address such as http://192.168.1.42. Type it into your phone or computer browser and tap ON or OFF.
✓ Check: The page shows "LED is ON" and the on-board LED lights; tap OFF and it goes out. If you see "Wi-Fi not connected", check the name and password, then press RST.
Prefer Python? Download the LOLIN_S2_MINI firmware from micropython.org and follow the install steps on that page, then use Thonny with the interpreter set to MicroPython (ESP32). CircuitPython firmware is on circuitpython.org.
Troubleshooting
| Problem |
Likely cause |
Fix |
| No port appears in Tools → Port |
Charge-only cable, or the board isn't in upload mode |
Use a data cable. Hold 0, press and release RST, release 0, then check the port list again |
| Upload fails or stops part-way |
Upload speed too high for the USB cable or USB chip |
Tools → Upload Speed → 115200, then upload again |
| Upload finished but nothing happens |
The board is still in upload mode |
Press RST once |
| Serial Monitor stays blank |
USB CDC On Boot is disabled, the port changed after reset, or wrong speed |
Tools → USB CDC On Boot → Enabled, re-select the port, set 115200 baud, press RST |
| Wi-Fi won't connect |
5 GHz network, or wrong name/password |
Use a 2.4 GHz network and check the spelling (it is case-sensitive) |
| Bluetooth sketch won't compile |
The ESP32-S2 has no Bluetooth |
Use an ESP32, ESP32-C3 or ESP32-S3 board for Bluetooth projects |
Try next: add a second button to the web page that makes the LED blink, or read a 3.3 V I2C sensor and show its value on the page.
Spotted a problem in this tutorial? Email support@epartners.co.nz and we'll check it and update the tutorial.