Displays
Wi-Fi alert screen
A desk screen that flashes a big warning sign and sounds a siren when you send it a message from your phone.
- Medium
- about 50 min
- ESP32-S3
- 7 parts
- 9 wires
- 104 lines of code
- Uses Wi-Fi
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
The board runs its own small web page. Any phone on the same Wi-Fi can open it, with no app and no account. Use it to call the family to dinner or to signal a classroom.
What you learn
Running a web server on a microcontroller, and reading what a form sends.
How it works
input
A phone on the same Wi-Fi
decides
ESP32-S3 · Wi-Fi
output
TFT 1.54 in
Buzzer
Powered with 5 V through the board's USB-C port.
It joins your home Wi-Fi. You type the network name and password into the sketch before uploading; they stay on the board.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 7 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 9
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
alert-screen.ino
// Wi-Fi alert screen
// Open the address shown on the screen from any phone on the same Wi-Fi and
// press a button: the screen flashes a warning and the buzzer sounds.
#include <WiFi.h>
#include <WebServer.h>
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
const char* WIFI_SSID = "YOUR_WIFI_NAME";
const char* WIFI_PASS = "YOUR_WIFI_PASSWORD";
const int PIN_TFT_SCL = 12;
const int PIN_TFT_SDA = 11;
const int PIN_TFT_RES = 14;
const int PIN_TFT_DC = 13;
const int PIN_TFT_CS = 10;
const int PIN_BUZZER_POS = 17;
Adafruit_ST7789 tft(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RES);
WebServer server(80);
bool alertOn = false;
String alertText = "";
unsigned long nextFlash = 0;
bool flashPhase = false;
const char PAGE[] PROGMEM = R"HTML(<!doctype html><meta name=viewport content="width=device-width,initial-scale=1">
<title>Alert screen</title><body style="font-family:sans-serif;max-width:24rem;margin:2rem auto;padding:0 1rem">
<h1>Alert screen</h1>
<form action=/alert><input name=text maxlength=18 placeholder="Message" style="font-size:1.2rem;width:100%;padding:.5rem">
<p><button style="font-size:1.2rem;padding:.6rem 1.2rem">Send alert</button></form>
<p><a href=/clear>Clear the alert</a></body>)HTML";
void drawIdle() {
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_GREEN);
tft.setTextSize(3);
tft.setCursor(30, 60);
tft.print("All clear");
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 150);
tft.print("Open in a browser:");
tft.setCursor(10, 180);
tft.print(WiFi.localIP());
}
void drawAlert(bool bright) {
uint16_t back = bright ? ST77XX_RED : ST77XX_BLACK;
uint16_t ink = bright ? ST77XX_WHITE : ST77XX_RED;
tft.fillScreen(back);
tft.fillTriangle(120, 20, 40, 150, 200, 150, ink);
tft.fillRect(113, 60, 14, 50, back);
tft.fillCircle(120, 130, 8, back);
tft.setTextColor(ink);
tft.setTextSize(2);
tft.setCursor(10, 190);
tft.print(alertText);
}
void setup() {
pinMode(PIN_BUZZER_POS, OUTPUT);
SPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
tft.init(240, 240);
tft.setRotation(2);
tft.fillScreen(ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(20, 110);
tft.print("Wi-Fi...");
WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_SSID, WIFI_PASS);
while (WiFi.status() != WL_CONNECTED) delay(250);
server.on("/", []() { server.send_P(200, "text/html", PAGE); });
server.on("/alert", []() {
alertText = server.hasArg("text") && server.arg("text").length() > 0 ? server.arg("text") : "ALERT";
alertOn = true;
nextFlash = 0;
server.sendHeader("Location", "/");
server.send(303);
});
server.on("/clear", []() {
alertOn = false;
noTone(PIN_BUZZER_POS);
drawIdle();
server.sendHeader("Location", "/");
server.send(303);
});
server.begin();
drawIdle();
}
void loop() {
server.handleClient();
if (alertOn && millis() >= nextFlash) {
flashPhase = !flashPhase;
drawAlert(flashPhase);
tone(PIN_BUZZER_POS, flashPhase ? 1800 : 1200, 350);
nextFlash = millis() + 500;
}
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit ST7735 and ST7789 Library: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Before uploading, type your Wi-Fi name and password into WIFI_SSID and WIFI_PASS at the top of the sketch.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.