Quick answer: to build an LED face keychain you control from your phone, connect an 8×8 LED matrix with a MAX7219 driver to an ESP32-C3 SuperMini (DIN to GPIO 5, CS to GPIO 6, CLK to GPIO 7) and upload the sketch below. The ESP32-C3 starts its own Wi-Fi network called FaceKey-XXXX. Join it with your phone, open http://192.168.4.1, and tap a face or draw your own. A protected LiPo cell, a TP4056 charger and a 3D-printed case turn it into a keychain.
This is a product-style project: you design something, build it and carry it around. The keychain shows eight faces on 64 red LEDs and blinks now and then so it looks alive. No app and no internet are needed, because the keychain is its own tiny Wi-Fi hotspot and web server. You design the case too, or print our ready-made STL files.
What you need
- Breadboard, jumper wires, a 10 kΩ resistor and a USB cable from the EEMENTOR ESP32 IoT Starter Kit, for the prototype
- ESP32-C3 SuperMini board (not in the kit)
- 8×8 LED matrix module with a MAX7219, the 32 × 32 mm type with the chip underneath (not in the kit)
- TP4056 USB-C charger module with protection (DW01A chip, pads B+, B−, OUT+, OUT−) (not in the kit)
- An EEMENTOR 3.7 V LiPo pouch cell of about 300 mAh, no bigger than 5.5 × 20 × 36 mm (such as the 320 mAh LP552036). The cells come as loose pouch cells, so ask an adult to fit a JST lead or use a cell that already has wire leads and a protection circuit; never solder directly onto the cell.
- A mini slide switch, a 6 × 6 mm push button, a 4.3 kΩ SMD resistor and a Schottky diode such as a 1N5819 or SS14 (not in the kit)
- Soldering iron, digital calipers, a 3D printer, foam tape and hot glue
New to the ESP32? Start with Set up the ESP32 in the Arduino IDE.
LiPo safety: read this first. A LiPo pouch stores a lot of energy. Only use it through the TP4056 module with protection, which cuts the power if the cell is overcharged, run flat or shorted. Never puncture, bend or squash the cell, and never solder onto the cell itself. Charge it only through the TP4056 and never leave it charging alone. A diode in the power path stops USB power from the ESP32-C3 reaching the battery. If it gets warm, unplug it; if it swells or smells, stop using it and recycle it. Insulate every bare pad with tape or heat-shrink. Do the battery steps with an adult.
Step 1: Sketch your idea and measure the parts
Every product starts on paper. Sketch the keychain from the front, side and back, marking the window, charging socket, switch, button and loop. Then measure every part with digital calipers, including anything that sticks out.
Our honest result: we hoped for about 45 × 38 × 14 mm, but the matrix module alone is 32 × 32 × 12 mm, and the ESP32-C3, TP4056 and cell need space too. So our case is 43 × 70 × 16 mm plus the loop. Making it smaller is a great next challenge.
Step 2: Build it on the breadboard first
Prototype before you solder. Power everything from USB for now: on USB, the 5V pin carries 5 V from the cable, which suits the matrix.

| From | To (ESP32-C3 SuperMini) |
|---|---|
| Matrix VCC | 5V |
| Matrix GND | GND |
| Matrix DIN | GPIO 5 |
| Matrix CS (sometimes LOAD) | GPIO 6 |
| Matrix CLK | GPIO 7 |
| Push button, one leg | GPIO 3 |
| Push button, other leg | GND |
| 10 kΩ resistor | between GPIO 3 and 3V3 |
| Later, in the keychain: TP4056 OUT+ → slide switch → Schottky diode (band towards the board) | 5V (and OUT− to GND) |
| Later, in the keychain: matrix VCC | moves to the slide switch output, before the diode |
Only GPIO 0 to 5 can wake the ESP32-C3 from deep sleep, so the button is on GPIO 3, with the resistor holding it high.
Step 3: Upload the sketch
In the Arduino IDE, choose ESP32C3 Dev Module and set Tools → USB CDC On Boot → Enabled. No extra libraries are needed: the sketch drives the MAX7219 itself with shiftOut(). If uploading fails, hold BOOT, tap RESET, release BOOT and retry. Change AP_PASSWORD first (8+ characters) so only your friends can change your face.
// FaceKey: an LED face keychain you control from your phone (EEMENTOR STEM)
// Board: ESP32-C3 SuperMini -> Arduino IDE board "ESP32C3 Dev Module", USB CDC On Boot: Enabled
// The keychain makes its own Wi-Fi network. Join it with your phone and open http://192.168.4.1
#include <WiFi.h>
#include <WebServer.h>
#include <DNSServer.h>
#include <Preferences.h>
#include <esp_sleep.h>
#include <driver/gpio.h>
// ---------- settings you can change ----------
const char* AP_PASSWORD = "smile1234"; // at least 8 characters
const unsigned long WIFI_OFF_AFTER = 3UL * 60 * 1000; // no phone for 3 min: Wi-Fi off, face stays on
const unsigned long SLEEP_AFTER = 10UL * 60 * 1000; // nothing for 10 min: deep sleep (0 = never)
const int ROTATION = 0; // 0, 1, 2 or 3 quarter turns, if your faces look sideways
const bool MIRROR = false; // true if your faces look back to front
// ---------- pins ----------
const int PIN_DIN = 5; // MAX7219 DIN
const int PIN_CLK = 7; // MAX7219 CLK
const int PIN_CS = 6; // MAX7219 CS (sometimes labelled LOAD)
const int PIN_BUTTON = 3; // push button to GND (GPIO 0 to 5 can wake the C3)
// ---------- the faces: 8 rows each, top row first, left LED = highest bit ----------
// Each face has two frames: frame B is shown for a moment when the animation is on.
struct Face { const char* name; uint8_t a[8]; uint8_t b[8]; };
const Face FACES[] = {
{ "Happy", {0x00, 0x66, 0x66, 0x00, 0x81, 0x42, 0x3C, 0x00}, {0x00, 0x00, 0x66, 0x00, 0x81, 0x42, 0x3C, 0x00} },
{ "Sad", {0x00, 0x66, 0x66, 0x00, 0x00, 0x3C, 0x42, 0x81}, {0x00, 0x00, 0x66, 0x00, 0x00, 0x3C, 0x42, 0x81} },
{ "Wink", {0x00, 0x60, 0x66, 0x00, 0x81, 0x42, 0x3C, 0x00}, {0x00, 0x66, 0x66, 0x00, 0x81, 0x42, 0x3C, 0x00} },
{ "Surprised", {0x00, 0x66, 0x66, 0x00, 0x18, 0x24, 0x24, 0x18}, {0x00, 0x00, 0x66, 0x00, 0x18, 0x24, 0x24, 0x18} },
{ "Heart", {0x00, 0x66, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, 0x00}, {0x00, 0x00, 0x24, 0x7E, 0x3C, 0x18, 0x00, 0x00} },
{ "Sleepy", {0x00, 0x00, 0xE7, 0x00, 0x00, 0x18, 0x18, 0x00}, {0x00, 0x00, 0xE7, 0x00, 0x18, 0x24, 0x18, 0x00} },
{ "Angry", {0xC3, 0x24, 0x00, 0x66, 0x00, 0x3C, 0x42, 0x00}, {0xC3, 0x24, 0x00, 0x00, 0x00, 0x3C, 0x42, 0x00} },
{ "Laugh", {0x00, 0x66, 0x66, 0x00, 0xFF, 0x81, 0x42, 0x3C}, {0x00, 0x00, 0x66, 0x00, 0xFF, 0x81, 0x42, 0x3C} },
};
const int BUILT_IN = sizeof(FACES) / sizeof(FACES[0]); // 8 built-in faces
const int SLOTS = 4; // 4 faces you draw yourself
const int DRAWING = 255; // "showing the drawing grid, not saved yet"
// ---------- the phone page (index.html), stored in flash ----------
const char PAGE[] PROGMEM = R"rawliteral(<!DOCTYPE html>
<html lang="en"><head><meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-title" content="FaceKey">
<meta name="theme-color" content="#1B3A7B">
<title>FaceKey</title>
<style>
body{margin:0;font-family:system-ui,sans-serif;background:#F6F8FC;color:#1B3A7B}
header{background:#1B3A7B;color:#fff;padding:14px 18px;font-weight:700;font-size:20px}
header small{font-weight:400;opacity:.8;font-size:14px;margin-left:6px}
section{background:#fff;margin:12px;padding:12px 14px;border-radius:14px;box-shadow:0 2px 8px rgba(27,58,123,.08)}
h2{font-size:16px;margin:0 0 10px}
.faces{display:grid;grid-template-columns:repeat(4,1fr);gap:8px}
.face{border:2px solid #DCE3EF;border-radius:10px;background:#fff;padding:6px 2px;font-size:12px;color:#1B3A7B}
.face canvas{display:block;margin:0 auto 4px;width:48px;height:48px}
.face.on{border-color:#DE544A;background:#FFF1F0}
.face:disabled{opacity:.35}
.grid{display:grid;grid-template-columns:repeat(8,1fr);gap:4px;max-width:320px;margin:0 auto;touch-action:none}
.grid div{aspect-ratio:1;border-radius:50%;background:#2A1416}
.grid div.on{background:#FF3B30;box-shadow:0 0 8px #FF3B30}
.row{display:flex;gap:8px;margin-top:10px;flex-wrap:wrap}
button.b{flex:1;padding:10px 6px;border:0;border-radius:10px;background:#E9EDF3;color:#1B3A7B;font-size:14px}
button.save{background:#DE544A;color:#fff}
label{display:flex;align-items:center;gap:10px;margin:6px 0}
input[type=range]{flex:1}
#msg{text-align:center;color:#6B7280;font-size:13px;min-height:18px}
</style></head><body>
<header>FaceKey <small id="id"></small></header>
<section><h2>Faces</h2><div class="faces" id="faces"></div></section>
<section><h2>Draw your own</h2><div class="grid" id="grid"></div>
<div class="row"><button class="b" id="clear">Clear</button><button class="b" id="invert">Invert</button><button class="b" id="copy">Copy current</button></div>
<div class="row" id="slots"></div></section>
<section><h2>Settings</h2>
<label>Brightness <input type="range" id="bright" min="0" max="15"></label>
<label><input type="checkbox" id="anim"> Blink animation</label></section>
<p id="msg"></p>
<script>
// codec start
function hexToFace(hex) {
if (!/^[0-9a-fA-F]{16}$/.test(hex)) return null;
const rows = [];
for (let r = 0; r < 8; r++) rows.push(parseInt(hex.substr(r * 2, 2), 16));
return rows;
}
function faceToHex(rows) {
return rows.map(function (b) { return (b & 255).toString(16).padStart(2, '0'); }).join('').toUpperCase();
}
function getPixel(rows, r, c) { return (rows[r] >> (7 - c)) & 1; }
function setPixel(rows, r, c, on) {
const mask = 1 << (7 - c);
rows[r] = on ? (rows[r] | mask) : (rows[r] & ~mask & 255);
}
// codec end
let S = null, draw = [0, 0, 0, 0, 0, 0, 0, 0], sendTimer = 0, painting = -1;
const $ = function (id) { return document.getElementById(id); };
function say(t) { $('msg').textContent = t; }
function api(url) {
return fetch(url).then(function (r) { return r.json(); })
.then(function (s) { S = s; show(); say(''); return true; })
.catch(function () { say('Not connected. Join the ' + (S ? S.id : 'FaceKey') + ' Wi-Fi.'); return false; });
}
function paint(cv, rows) {
const g = cv.getContext('2d'); cv.width = cv.height = 48;
g.fillStyle = '#1A0E10'; g.fillRect(0, 0, 48, 48);
for (let r = 0; r < 8; r++) for (let c = 0; c < 8; c++) {
g.fillStyle = getPixel(rows, r, c) ? '#FF3B30' : '#3A2224';
g.beginPath(); g.arc(c * 6 + 3, r * 6 + 3, 2.4, 0, 7); g.fill();
}
}
function show() {
$('id').textContent = S.id;
const box = $('faces');
if (box.children.length !== S.names.length) {
box.innerHTML = '';
S.names.forEach(function (n, i) {
const b = document.createElement('button');
b.className = 'face'; b.innerHTML = '<canvas></canvas>' + n;
b.onclick = function () { api('/api/face?i=' + i); };
box.appendChild(b);
});
}
S.names.forEach(function (n, i) {
const b = box.children[i], rows = hexToFace(S.faces[i]);
paint(b.firstChild, rows);
b.classList.toggle('on', i === S.face);
b.disabled = i >= S.builtIn && faceToHex(rows) === '0000000000000000';
});
$('bright').value = S.bright;
$('anim').checked = S.anim;
}
function drawGrid() {
const cells = $('grid').children;
for (let i = 0; i < 64; i++) cells[i].classList.toggle('on', !!getPixel(draw, i >> 3, i & 7));
}
function changed() {
drawGrid();
clearTimeout(sendTimer);
sendTimer = setTimeout(function () { api('/api/draw?b=' + faceToHex(draw)); }, 120);
}
function cellAt(e) {
const el = document.elementFromPoint(e.clientX, e.clientY);
return el && el.parentNode === $('grid') ? +el.dataset.i : -1;
}
for (let i = 0; i < 64; i++) { const d = document.createElement('div'); d.dataset.i = i; $('grid').appendChild(d); }
$('grid').addEventListener('pointerdown', function (e) {
const i = cellAt(e); if (i < 0) return;
painting = getPixel(draw, i >> 3, i & 7) ? 0 : 1;
setPixel(draw, i >> 3, i & 7, painting); changed();
});
$('grid').addEventListener('pointermove', function (e) {
const i = cellAt(e); if (painting < 0 || i < 0) return;
if (getPixel(draw, i >> 3, i & 7) !== painting) { setPixel(draw, i >> 3, i & 7, painting); changed(); }
});
window.addEventListener('pointerup', function () { painting = -1; });
$('clear').onclick = function () { draw = [0, 0, 0, 0, 0, 0, 0, 0]; changed(); };
$('invert').onclick = function () { draw = draw.map(function (b) { return ~b & 255; }); changed(); };
$('copy').onclick = function () { if (S) { draw = hexToFace(S.shown); drawGrid(); } };
for (let k = 0; k < 4; k++) {
const b = document.createElement('button'); b.className = 'b save'; b.textContent = 'Save ' + (k + 1);
b.onclick = function () { api('/api/save?slot=' + k + '&b=' + faceToHex(draw)).then(function (ok) { if (ok) say('Saved as My face ' + (k + 1)); }); };
$('slots').appendChild(b);
}
$('bright').onchange = function () { api('/api/bright?v=' + this.value); };
$('anim').onchange = function () { api('/api/anim?on=' + (this.checked ? 1 : 0)); };
drawGrid();
api('/api/state');
</script></body></html>)rawliteral";
WebServer server(80);
DNSServer dns;
Preferences prefs;
char apName[20];
uint8_t custom[SLOTS][8]; // the faces you saved (all zero = empty slot)
uint8_t drawing[8]; // what the drawing grid on the phone shows
uint8_t shown[8]; // what the matrix shows right now
int face = 0; // 0-7 built-in, 8-11 your own, 255 = drawing
int brightness = 2; // 0 (dim) to 15 (bright)
bool animate = true;
bool wifiOn = false;
unsigned long lastPhone = 0, lastUse = 0, lastBlink = 0;
// codec start
// A face travels between the phone and the keychain as 16 hex characters, two per row,
// for example "0066660081423C00" is the happy face.
int hexDigit(char c) {
if (c >= '0' && c <= '9') return c - '0';
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
return -1;
}
bool hexToFace(const char* hex, uint8_t rows[8]) {
for (int i = 0; i < 16; i++) if (hexDigit(hex[i]) < 0) return false; // must be 16 hex digits
if (hex[16] != '\0') return false;
for (int r = 0; r < 8; r++) rows[r] = hexDigit(hex[r * 2]) * 16 + hexDigit(hex[r * 2 + 1]);
return true;
}
void faceToHex(const uint8_t rows[8], char hex[17]) {
const char* digits = "0123456789ABCDEF";
for (int r = 0; r < 8; r++) {
hex[r * 2] = digits[rows[r] >> 4];
hex[r * 2 + 1] = digits[rows[r] & 15];
}
hex[16] = '\0';
}
// For faces you draw yourself, the blink frame squeezes rows 1 to 3 (the eyes) into one line on row 2.
void blinkFrame(const uint8_t in[8], uint8_t out[8]) {
for (int r = 0; r < 8; r++) out[r] = in[r];
out[2] = in[1] | in[2] | in[3];
out[1] = 0;
out[3] = 0;
}
// codec end
// ---------- MAX7219: two bytes per command, register then value ----------
void maxSend(uint8_t reg, uint8_t value) {
digitalWrite(PIN_CS, LOW);
shiftOut(PIN_DIN, PIN_CLK, MSBFIRST, reg);
shiftOut(PIN_DIN, PIN_CLK, MSBFIRST, value);
digitalWrite(PIN_CS, HIGH); // the chip copies the command when CS goes high
}
void maxBegin() {
maxSend(0x0F, 0); // display test off
maxSend(0x09, 0); // no digit decoding: we send raw LED patterns
maxSend(0x0B, 7); // scan all 8 rows
maxSend(0x0A, brightness); // brightness 0-15
maxSend(0x0C, 1); // wake up from shutdown
}
void showRows(const uint8_t rows[8]) {
uint8_t out[8] = {0};
for (int r = 0; r < 8; r++) for (int c = 0; c < 8; c++) {
if (!((rows[r] >> (7 - c)) & 1)) continue;
int x = MIRROR ? 7 - c : c, y = r;
for (int t = 0; t < ROTATION; t++) { int nx = 7 - y; y = x; x = nx; } // turn a quarter clockwise
out[y] |= 0x80 >> x;
}
for (int r = 0; r < 8; r++) maxSend(r + 1, out[r]); // rows are registers 1 to 8
}
// ---------- faces ----------
const uint8_t* faceRows(int i) {
if (i < BUILT_IN) return FACES[i].a;
if (i < BUILT_IN + SLOTS) return custom[i - BUILT_IN];
return drawing;
}
bool isEmpty(const uint8_t rows[8]) {
for (int r = 0; r < 8; r++) if (rows[r]) return false;
return true;
}
void showFace(int i, bool save) {
face = i;
memcpy(shown, faceRows(i), 8);
showRows(shown);
if (save && face != DRAWING && prefs.getUChar("face", 0) != face) prefs.putUChar("face", face);
}
void blinkIfTime() {
if (!animate || millis() - lastBlink < 4000) return;
lastBlink = millis();
uint8_t b[8];
if (face < BUILT_IN) memcpy(b, FACES[face].b, 8);
else blinkFrame(shown, b);
showRows(b);
delay(face == 4 ? 300 : 150); // the heart beats a little slower
showRows(shown);
}
void nextFace() {
int i = face;
for (int n = 0; n < BUILT_IN + SLOTS; n++) {
i = (i + 1) % (BUILT_IN + SLOTS);
if (!isEmpty(faceRows(i))) break; // skip empty slots
}
showFace(i, true);
}
// ---------- web page and API ----------
void sendState() {
lastPhone = lastUse = millis();
char hex[17];
String j = "{\"id\":\"" + String(apName) + "\",\"builtIn\":" + BUILT_IN + ",\"face\":" + face;
j += ",\"bright\":" + String(brightness) + ",\"anim\":" + (animate ? "true" : "false");
faceToHex(shown, hex);
j += ",\"shown\":\"" + String(hex) + "\",\"names\":[";
for (int i = 0; i < BUILT_IN + SLOTS; i++) {
if (i) j += ",";
j += i < BUILT_IN ? "\"" + String(FACES[i].name) + "\"" : "\"My face " + String(i - BUILT_IN + 1) + "\"";
}
j += "],\"faces\":[";
for (int i = 0; i < BUILT_IN + SLOTS; i++) {
faceToHex(faceRows(i), hex);
j += (i ? ",\"" : "\"") + String(hex) + "\"";
}
j += "]}";
server.send(200, "application/json", j);
}
void handlePage() {
lastPhone = lastUse = millis();
server.send_P(200, "text/html", PAGE);
}
void handleFace() {
int i = server.arg("i").toInt();
if (i >= 0 && i < BUILT_IN + SLOTS) showFace(i, true);
sendState();
}
void handleDraw() {
if (hexToFace(server.arg("b").c_str(), drawing)) showFace(DRAWING, false);
sendState();
}
void handleSave() {
int k = server.arg("slot").toInt();
uint8_t rows[8];
if (k >= 0 && k < SLOTS && hexToFace(server.arg("b").c_str(), rows)) {
memcpy(custom[k], rows, 8);
char key[3] = {'c', char('0' + k), 0};
prefs.putBytes(key, rows, 8); // saved in flash: survives power off
showFace(BUILT_IN + k, true);
}
sendState();
}
void handleBright() {
brightness = constrain(server.arg("v").toInt(), 0, 15);
maxSend(0x0A, brightness);
prefs.putUChar("bright", brightness);
sendState();
}
void handleAnim() {
animate = server.arg("on") == "1";
prefs.putBool("anim", animate);
sendState();
}
// Phones test for internet on special addresses. Sending them to our page makes the phone
// show a "sign in to network" pop-up that opens the FaceKey page.
void handleOther() {
server.sendHeader("Location", "http://192.168.4.1/");
server.send(302, "text/plain", "");
}
void wifiStart() {
WiFi.mode(WIFI_AP);
WiFi.softAP(apName, AP_PASSWORD);
WiFi.setTxPower(WIFI_POWER_8_5dBm); // the phone is close; lower power saves battery
dns.start(53, "*", WiFi.softAPIP()); // every web address points to the keychain
server.begin();
wifiOn = true;
lastPhone = millis();
Serial.printf("Wi-Fi %s on, open http://%s\n", apName, WiFi.softAPIP().toString().c_str());
}
void wifiStop() {
server.stop();
dns.stop();
WiFi.softAPdisconnect(true);
WiFi.mode(WIFI_OFF);
wifiOn = false;
Serial.println("Wi-Fi off to save battery. Press the button to turn it on again.");
}
void goToSleep() {
Serial.println("Going to sleep. Press the button to wake up.");
maxSend(0x0C, 0); // matrix off (shutdown mode)
if (wifiOn) wifiStop();
while (digitalRead(PIN_BUTTON) == LOW) delay(10); // wait until the button is let go
delay(50);
gpio_hold_en((gpio_num_t)PIN_CS); // keep CS high while asleep so the matrix ignores noise
gpio_deep_sleep_hold_en();
esp_deep_sleep_enable_gpio_wakeup(1ULL << PIN_BUTTON, ESP_GPIO_WAKEUP_GPIO_LOW);
esp_deep_sleep_start();
}
void setup() {
Serial.begin(115200);
gpio_hold_dis((gpio_num_t)PIN_CS);
pinMode(PIN_DIN, OUTPUT);
pinMode(PIN_CLK, OUTPUT);
pinMode(PIN_CS, OUTPUT);
digitalWrite(PIN_CS, HIGH);
pinMode(PIN_BUTTON, INPUT_PULLUP);
while (digitalRead(PIN_BUTTON) == LOW) delay(10); // the press that woke us up is not a face change
prefs.begin("facekey", false);
brightness = prefs.getUChar("bright", 2);
animate = prefs.getBool("anim", true);
for (int k = 0; k < SLOTS; k++) {
char key[3] = {'c', char('0' + k), 0};
if (prefs.getBytes(key, custom[k], 8) != 8) memset(custom[k], 0, 8);
}
int saved = prefs.getUChar("face", 0);
if (saved >= BUILT_IN + SLOTS || isEmpty(faceRows(saved))) saved = 0;
maxBegin();
showFace(saved, false);
uint64_t mac = ESP.getEfuseMac();
snprintf(apName, sizeof(apName), "FaceKey-%04X", (unsigned)((mac >> 32) & 0xFFFF));
server.on("/", handlePage);
server.on("/api/state", sendState);
server.on("/api/face", handleFace);
server.on("/api/draw", handleDraw);
server.on("/api/save", handleSave);
server.on("/api/bright", handleBright);
server.on("/api/anim", handleAnim);
server.onNotFound(handleOther);
wifiStart();
lastUse = millis();
}
void loop() {
if (wifiOn) {
dns.processNextRequest();
server.handleClient();
}
// the button: short press = next face (and Wi-Fi back on if it was off), hold 1.5 s = sleep now
if (digitalRead(PIN_BUTTON) == LOW) {
unsigned long down = millis();
delay(30); // ignore contact bounce
while (digitalRead(PIN_BUTTON) == LOW) {
if (millis() - down > 1500) goToSleep();
delay(10);
}
if (millis() - down > 30) {
lastUse = millis();
if (!wifiOn) wifiStart();
nextFace();
}
}
blinkIfTime();
if (wifiOn && millis() - lastPhone > WIFI_OFF_AFTER) wifiStop();
if (SLEEP_AFTER && millis() - lastUse > SLEEP_AFTER) goToSleep();
delay(2);
}The matrix shows a smiley and the Serial Monitor (115200 baud) prints the network name, such as FaceKey-1A2B. If the face is sideways or back to front, change ROTATION or MIRROR: modules aren't all wired the same way round.
Step 4: Connect your phone and add it to the home screen
- Open your phone's Wi-Fi settings and join FaceKey-XXXX with your password.
- Most phones pop up a "sign in" page showing FaceKey. If not, open http://192.168.4.1.
- Tap a face. The keychain changes within a moment.
To make it feel like an app, open the address in the normal browser. iPhone: Safari → Share → Add to Home Screen. Android: Chrome → ⋮ → Add to Home screen. It only works while you're on the keychain's Wi-Fi; if the phone warns about no internet, stay connected.

Step 5: Draw your own faces
Tap or drag on the grid under Draw your own; the keychain copies it straight away. Tap Save 1 to Save 4 to store it in flash memory with the Preferences library, so it survives power off. Copy current loads the keychain's face into the grid. A short button press steps through all faces.

Step 6: Add the charger and the battery
First, make charging safe. Most TP4056 modules charge at 1 A, set by a 1.2 kΩ resistor marked R3 or "122". Our 320 mAh cell should be charged at 0.3 A or less. The datasheet gives the current as about 1200 ÷ the resistor value, so replace R3 with 4.3 kΩ for about 0.28 A. Check your cell's maximum charging current, and ask an adult to help with the tiny resistor.
Then solder: cell red → B+, black → B−, OUT+ → slide switch middle pin → Schottky diode → ESP32-C3 5V, OUT− → GND. The diode's band (cathode) faces the 5V pin. Move the matrix VCC to the switch output, before the diode, so its current skips the diode. Solder short wires to the matrix's IN pads, and heat-shrink the diode.
Why the diode? The SuperMini's 5V pin is joined to its USB socket, so plugging in USB with the switch on would push 5 V backwards into the cell. The diode only lets current flow towards the board. Charge only through the TP4056, with the switch off so it can tell when the cell is full.
Step 7: Design the case in Tinkercad
Open Tinkercad, the free 3D design tool in your browser, and build the case from simple shapes, with the front lying on the workplane:
- Box: 43 × 70 × 14.4 mm (plus a 1.6 mm back cover makes 16 mm).
- Round: set Radius to 5 in the shape panel.
- Hollow: add a 39 × 66 × 14.4 mm box, make it a Hole, raise it 1.4 mm and centre it with Align: 2 mm walls, a 1.4 mm front and an open back.
- Window: a 31 × 31 mm hole through the front, centred, 51.6 mm from the bottom edge to its centre: 1 mm smaller than the matrix, so a lip holds it.
- Holes: a 12.4 × 6.4 mm rounded USB-C slot in the bottom, a 5 × 2.4 mm switch slot and a 4 mm button hole, placed from your measurements.
- Loop: a 4 mm thick Tube on top, then select all and Group.
The back cover is a 43 × 70 × 1.6 mm box with radius 5 and small tabs that fit inside the walls. Export STLs, print, test the fit and adjust: that loop is how product designers work.

Step 8: Print and assemble
Print your design or our STL files from the 3D printing box. Test once more with the case open, then assemble it as the box explains and add a keyring.

Battery life: what to expect
These are estimates from datasheets, not lab measurements, and assume only about two thirds of the cell is usable (see Power below). Measure yours with a multimeter on mA, in series with the switch.
| Mode | Current (estimate) | Time on 320 mAh |
|---|---|---|
| Wi-Fi on, brightness 2 | about 100–140 mA | about 1½ hours |
| Wi-Fi off, face showing | about 30–50 mA | about 4–7 hours |
| Deep sleep, matrix off | under 1 mA | about 2 weeks |
Wi-Fi is the hungry part: in hotspot mode the radio keeps listening, about 84 mA for receiving in the ESP32-C3 datasheet. Each lit LED is on 1/8 of the time, shortened again by the brightness, so a smiley needs about 12 mA at brightness 2 but nearly 80 mA at 15. So the sketch turns Wi-Fi off after 3 minutes without your phone and sleeps after 10. Switch off for the day: the power LED glows even in sleep.
How it works
The matrix. The MAX7219 stores one byte per row and scans the LEDs too fast to see. The sketch sends a register and a value with shiftOut(): registers 1 to 8 are rows, 0x0A is brightness, 0x0C is on/off.
The faces. In each row byte the left LED is the highest bit, so 0x66 (01100110) is two eyes. A face travels as 16 hex characters, like 0066660081423C00 for happy, with the same encoding in the C++ and the JavaScript.
The Wi-Fi page. WiFi.softAP() makes a hotspot at 192.168.4.1, and the page is stored in the sketch as PAGE. Each tap calls an address like /api/face?i=3, and the sketch replies with its state as JSON. The DNS server sends every web name to the keychain, so the phone's internet check lands on the page and the "sign in" pop-up appears.
Power. The cell gives 4.2 V full and about 3.7 V most of the time. On the way it loses about 0.3 V in our Schottky diode, a few tenths more in the SuperMini's own diode and about 0.1 V in its regulator (usually an ME6211). So the 3.3 V supply sags once the cell is below about 4.0 V, and reaches the ESP32-C3's 3.0 V minimum at roughly 3.6 to 3.7 V. The leftover charge is the price of the safety diode. The protection chip cuts off at 2.4 V.
A design compromise. The MAX7219 datasheet asks for a 4.0 to 5.5 V supply and a logic "high" of at least 3.5 V; on battery it gets 3.0 to 4.2 V and 3.3 V signals, outside those promises. We still power it from the battery, because a fully lit matrix can draw over 300 mA, more than the 3.3 V regulator can spare next to Wi-Fi. That's why you test on battery on the breadboard.
Common errors and fixes
- The matrix stays dark: check VCC, GND, DIN, CS and CLK, and use the module's IN side, where DIN is.
-
The face is sideways, upside down or back to front: change
ROTATION(0 to 3) orMIRRORat the top of the sketch. - Random dots or flicker on battery, but fine on USB: your module doesn't like the low voltage (see the design compromise above). Charge the cell and try again; if it still glitches, this module isn't reliable at battery voltage, and a different module or a small 5 V boost converter is needed.
- FaceKey isn't in the Wi-Fi list: press the button in case Wi-Fi switched off, and keep the phone close; makers often report weak Wi-Fi on SuperMini boards.
- The page doesn't open: type http://192.168.4.1 (http, not https) and turn off mobile data if the phone keeps leaving the network.
- It won't wake from sleep: the button must be on GPIO 3 (any of GPIO 0 to 5 works) with the 10 kΩ pull-up to 3V3.
FAQ
Do I need an app to control the LED keychain?
No. The ESP32-C3 serves its own web page over its own Wi-Fi, so any iPhone or Android browser works. Add the page to your home screen to open it like an app.
Does the keychain need internet or my home Wi-Fi?
No. The keychain is its own hotspot and your phone joins it directly, so it works anywhere.
How long does the battery last?
With a 320 mAh cell, roughly 1½ hours with Wi-Fi on, 4–7 hours with only the face showing and about 2 weeks asleep. The diodes mean it stops while the cell still has some charge left. These are estimates, so measure yours.
Can I use an ESP32 board from the starter kit instead of the ESP32-C3?
Yes, on the breadboard: change the pin numbers and put the button on a pin that can wake the board. The kit board is too big for a keychain, which is why the build uses the SuperMini.
Why does the LiPo cell need a protected charger?
A LiPo can be damaged or even catch fire if it is overcharged, run flat or shorted. The TP4056 with a DW01A chip charges to 4.2 V and cuts the power if something goes wrong.