Connect to your ESP32: Wi-Fi first
Your ESP32 makes its own Wi-Fi network and serves a dashboard. Connect to it, predict when the automatic light alert will turn on, and check whether the real LED agrees. Today the numbers come from the sketch, not a sensor.
What you are building Build and explain a classroom campus light alert. The board reads an input, decides whether to alert, and shows its decision on an LED. Demonstrate what it actually does; you are not installing a system on campus.
In-class practice. Your existing homework and deadlines stay the same.
Download the ESP32 sketch with LED controls (ZIP) Illustrated Wi-Fi handout (Word) Wire the light sensor (classic ESP32) Windows appendix: unzip with 7-Zip
1. Check the LED circuit
Do thisSave a copy of your earlier code. Unplug the board before touching the wires. On the classroom’s classic ESP32, have your teacher check the LED circuit below before powering it. Other ESP32 models need a separate pin check.
- GPIO25 output
- 330 Ω resistor
- LED: long leg (+) in, short leg (−) out
- GND on the same board
Why it worksThe 330 Ω resistor limits the current. Check which LED leg is positive and which is negative before you power up.
CheckIf you don’t have a checked LED circuit, set LED_PIN = -1 for a dashboard-only test. You can still see what the board is doing, but you can’t test whether an LED lights.
2. Upload the sample sketch
Do thisUnzip the download. In Arduino IDE, open G9WiFiDashboard.ino from the extracted folder, with AlertLogic.h beside it. If you’re on Windows, see the 7-Zip guide at the end.
CheckLeave USE_SENSOR = false. Set a short group label, not a student name. Use the class-only Wi-Fi password from your teacher instead of the public demo password.
Choose the board and port your teacher approved, then upload.
3. Join your board’s Wi-Fi
Do thisOpen Serial Monitor at 115200 baud. Press the board’s reset button if you missed the startup lines. The Wi-Fi name ends in six characters from your board’s MAC address. That helps you find your board even if another group uses the same label.
- ESP32 starts Wi-FiSerial Monitor shows “Join:” and “Open”.
- Laptop or phone joinsPick the exact Wi-Fi name after “Join:”.
- Browser opens the dashboardType the http:// address printed after “Open”.
Why it worksFollow classroom Wi-Fi rules. If your laptop or phone says “No internet,” stay connected. The board is hosting the page itself; it doesn’t need the school network.
CheckEnter the full printed address in your browser’s address bar. Use http://, not https://. Look for SAMPLE DATA.
4. Why 1600 gives two results
Do thisWatch the Automatic light alert. The sketch changes the sample every six seconds: 2400, 1600, 900, 1600, then repeats. Before each change, predict ON or OFF.
Why it worksBelow 1400 turns the alert ON. Above 1800 turns it OFF. From 1400 through 1800, including both limits, it keeps its previous state.
| Reading | Alert | Reason |
|---|---|---|
| 2400 | OFF | Above 1800: switches OFF. |
| 1600 | OFF | Keeps OFF from 2400. |
| 900 | ON | Below 1400: switches ON. |
| 1600 | ON | Keeps ON from 900. |
CheckCompare your prediction with the table. Keeping the last state between two thresholds is called hysteresis. It stops the alert flipping back and forth when readings hover in the middle.
5. Test manual LED control
This step needs the new sketch with LED controls. If your page has no LED On, LED Off or Return to Auto buttons, upload the ZIP linked above. In Auto, compare the page’s LED output with the real LED. What does each show when the alert turns on?
- Click LED On. Wait until the automatic alert shows OFF: the real LED should stay lit.
- Click LED Off. Wait until the automatic alert shows ON: the real LED should stay dark.
- Click Return to Auto. The LED should immediately follow the current automatic alert; you don’t have to wait for the next sample.
6. Record what you actually saw
Why it worksThe dashboard reports what the board told the LED to do. Only looking at the real LED tells you whether it lit.
Do thisIf you have a second browser connected to the same board, check whether both show the same mode. Unplug the board and watch for STALE: the last value is no longer live.
CheckMark anything you couldn’t check NOT TESTED.
Later: measure with a sensor
The example numbers and thresholds are not measurements or calibration. Once your teacher checks the circuit with the power off, use the wiring diagram and calibration lesson to collect real readings and choose thresholds. On the classic ESP32, use the approved 3.3 V light sensor divider on ADC1 GPIO34. Never feed 5 V into the input or swap to GPIO0 or an ADC2 pin while Wi-Fi is in use. Save the sample and sensor sketches separately. ADC counts aren’t lux, and readings near the upper limit can stop rising.
No board or local Wi-Fi allowed? Use the browser simulation to practise predictions. Label the results SIMULATION. They don’t show that you connected to a real board.
Wire the light sensor (classic ESP32)
Unplug USB before wiring. Use 3V3, not 5V. Check that your board exposes GPIO34 before proceeding.
- LDR
- Photoresistor (LDR)
- 10 kΩ
- Fixed resistor
- Put the two photoresistor legs in separate connected groups on the breadboard. Either leg can face 3V3.
- Make one junction. Connect the free photoresistor leg, one end of the 10 kΩ resistor and the GPIO34 jumper to the same connected group of holes.
- Connect the remaining photoresistor leg to 3V3 and the remaining 10 kΩ resistor leg to GND. Leave the LED on GPIO25 with its own 330 Ω resistor.
Resistor colour bands
Five-band resistors
The last band often has a larger gap before it. Start at the other end. The last band tells you the tolerance (how far the resistance can vary). Brown means ±1%, but the last band can be a different colour.
- 10 kΩ For the light sensor divider Brown, black, black, red, then the tolerance band
- 330 Ω For the LED Orange, orange, black, black, then the tolerance band
Both drawings show a brown last band as an example (±1%).
Not sure which end to read? Unplug USB and take the resistor out of the circuit. Use a multimeter in Ω mode to check for about 10 kΩ or 330 Ω.
Four-band reference
These are four-band examples (±5%). Start at the end opposite the gold band. Read toward gold.
- 10 kΩ For the light sensor divider Brown, black, orange, gold
- 330 Ω For the LED Orange, orange, brown, gold
What the resistors do
10 kΩ helps the ESP32 measure light
The ESP32 reads voltage, not resistance. The light sensor connects the measuring point to 3V3. The 10 kΩ resistor connects that same point to GND. Together they form a voltage divider, which gives GPIO34 a voltage it can read.
With this wiring, brighter light lowers the sensor’s resistance and raises the voltage at GPIO34. Cover the sensor and the voltage falls. Try it below and watch the numbers change in Serial Monitor.
330 Ω protects the LED
This resistor limits the current through the LED and the ESP32 pin. It can go on either side of the LED, as long as the same current passes through both.
Test the sensor in Serial Monitor
After your teacher checks the wiring, paste this into a new Arduino sketch and upload it. Open Serial Monitor at 115200 baud. Cover the sensor, uncover it, and compare the two readings. These are ADC counts, not lux.
Sketch copied. Sketch selected. Press Ctrl+C or Cmd+C to copy it.// Grade 9: test the photoresistor on a classic ESP32.
#include <Arduino.h>
#if !defined(CONFIG_IDF_TARGET_ESP32)
#error This sketch uses GPIO34 on the classic ESP32.
#endif
const int SENSOR_PIN = 34; // Wire the divider junction here.
void setup() {
Serial.begin(115200);
pinMode(SENSOR_PIN, INPUT);
analogReadResolution(12);
analogSetPinAttenuation(SENSOR_PIN, ADC_11db);
}
void loop() {
int reading = analogRead(SENSOR_PIN);
Serial.println(reading);
delay(250);
} Save this test as a separate sketch. When the readings change reliably, go back to your Wi-Fi dashboard sketch and enable sensor mode.
Make the LED respond to light
Use the same wiring. Paste this into a new Arduino sketch. The LED stays on in the darkest range, blinks fast in dim light, blinks slowly in brighter light, and turns off in the brightest range.
Sketch copied. Sketch selected. Press Ctrl+C or Cmd+C to copy it.#include <Arduino.h>
#if !defined(CONFIG_IDF_TARGET_ESP32)
#error This sketch uses GPIO34 on the classic ESP32.
#endif
const int SENSOR_PIN = 34;
const int LED_PIN = 25;
const int DARK = 800;
const int DIM = 1400;
const int BRIGHT = 2200;
unsigned long lastPrint = 0;
void setup() {
Serial.begin(115200);
pinMode(SENSOR_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
analogReadResolution(12);
analogSetPinAttenuation(SENSOR_PIN, ADC_11db);
}
void loop() {
const int light = analogRead(SENSOR_PIN);
const unsigned long now = millis();
const char* mode;
bool ledOn;
if (light < DARK) {
mode = "ON";
ledOn = true;
} else if (light < DIM) {
mode = "FAST BLINK";
ledOn = now % 300 < 150;
} else if (light < BRIGHT) {
mode = "SLOW BLINK";
ledOn = now % 1000 < 500;
} else {
mode = "OFF";
ledOn = false;
}
digitalWrite(LED_PIN, ledOn ? HIGH : LOW);
if (now - lastPrint >= 250) {
lastPrint = now;
Serial.print("Light: ");
Serial.print(light);
Serial.print(" Mode: ");
Serial.println(mode);
}
} The three thresholds (800, 1400, 2200) are starting values. Read your own numbers in Serial Monitor at 115200 baud, then adjust the thresholds from lowest to highest. This sketch does not use Wi-Fi.
After your teacher checks the unpowered circuit, enable sensor mode by setting USE_SENSOR = true and re-uploading. Open the dashboard, select Return to Auto, then cover and uncover the sensor. Record both readings before choosing thresholds. The example thresholds are not calibrated for your room.
If your wiring is not ready, leave USE_SENSOR = false and keep using sample data.
Windows appendix: unzip with 7-Zip
-
Find the ZIP
Open File Explorer (Windows key + E), go to Downloads, and find the ZIP from this lesson.
G9WiFiDashboard-controls.zip -
Extract to its own folder
Right-click the ZIP and open 7-Zip. On Windows 11, if 7-Zip is missing from the first menu, choose Show more options, then 7-Zip. Choose the option that extracts into the folder shown below, not Extract Here. If 7-Zip still isn’t there, ask your teacher before installing anything.
-
Open the extracted sketch
Open the new folder, then the G9WiFiDashboard folder inside it. You should see G9WiFiDashboard.ino and AlertLogic.h together. Open the .ino from this folder, not from inside the ZIP.
- Downloads
G9WiFiDashboard-controlsG9WiFiDashboardG9WiFiDashboard.inoAlertLogic.h