10 ESP32 Hacks for Wearables (With Code)
Updated
The ESP32 has features most beginner tutorials never mention, and several of them are perfect for things you wear. Here are ten I use all the time, each with a short code snippet and the parts to try it. All code is Arduino-framework C++, so it works in the Arduino IDE or PlatformIO.
New to ESP32? Start with my free ESP32 for Beginners: Wearable Electronics course, then come back here.
1. Turn conductive fabric into a button with the built-in touch pins
The classic ESP32 has 10 capacitive touch pins. Connect a patch of conductive fabric to one and you have a soft button with no extra parts. On the classic ESP32 the reading drops when you touch it; on the ESP32-S3 it rises. The ESP32-C3 has no touch pins at all.
const int TOUCH_PIN = 4; // T0 on the classic ESP32
const int THRESHOLD = 30; // print the values first, then set this
void setup() {
Serial.begin(115200);
}
void loop() {
int value = touchRead(TOUCH_PIN);
Serial.println(value);
if (value < THRESHOLD) {
// touched: change colour, start an animation...
}
delay(50);
}
Try it with: Silver Stretch Conductive Fabric, ESP32 30-Pin (USB-C), stainless steel thread to sew the connection.
2. Sleep until touched
A garment doesn't need to run all night. Put the ESP32 into deep sleep and let a fabric touch wake it up. Bare boards like the SuperMini sleep far more efficiently than dev boards with power LEDs and USB chips.
void onTouch() {}
void setup() {
touchAttachInterrupt(T0, onTouch, 30); // fabric on GPIO 4
esp_sleep_enable_touchpad_wakeup();
// run your light show here, then go back to sleep:
esp_deep_sleep_start();
}
void loop() {}
Try it with: 500 mAh LiPo battery, LiPo charging board.
3. Let two garments talk with ESP-NOW
ESP-NOW sends small messages directly between ESP32 boards, with no WiFi router. Matching outfits that change colour together, a glove that controls a jacket: this is how.
#include <WiFi.h>
#include <esp_now.h>
uint8_t everyone[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // broadcast
void setup() {
WiFi.mode(WIFI_STA);
esp_now_init();
esp_now_peer_info_t peer = {};
memcpy(peer.peer_addr, everyone, 6);
esp_now_add_peer(&peer);
}
void loop() {
uint8_t mode = 1; // the animation number to share
esp_now_send(everyone, &mode, 1);
delay(1000);
}
Try it with: two ESP32-C3 SuperMini boards (also in pink).
4. Power small LED builds from the 3V3 pin
For a handful of NeoPixels at modest brightness, you can power them straight from the ESP32's 3V3 pin. The LEDs and the data signal are then at the same voltage, so you skip the 5 V level-shifting problem entirely. I've run 60 in a row this way. Keep brightness low, and use 5 V for big or bright builds.
The full details are in Troubleshooting Common NeoPixel Problems.
Try it with: Neo Tester (8 LEDs), sewable pixel modules.
5. Warn before the battery dies
Two equal resistors in series from the battery's + to ground halve its voltage, which the ESP32 can safely read. Flash a colour when it gets low, before the LEDs start browning out mid-event.
const int BATT_PIN = 35; // use an ADC1 pin: ADC2 stops working when WiFi is on
void setup() {}
void loop() {
float volts = analogReadMilliVolts(BATT_PIN) * 2 / 1000.0;
if (volts < 3.4) {
// low battery: show a warning colour
}
delay(5000);
}
Try it with: Mini Resistor Kit, or skip the code with a Tiny Battery Level Indicator.
6. Control it from your phone
The ESP32 can make its own WiFi network and serve a web page. Join it from your phone and tap a link to change modes. No app, no internet needed.
#include <WiFi.h>
#include <WebServer.h>
WebServer server(80);
void setup() {
WiFi.softAP("MyJacket", "makemagic"); // password: 8+ characters
server.on("/on", []() {
// lights on
server.send(200, "text/plain", "on");
});
server.on("/off", []() {
// lights off
server.send(200, "text/plain", "off");
});
server.begin();
}
void loop() {
server.handleClient();
}
Join the MyJacket network, then visit 192.168.4.1/on in your phone's browser.
Try it with: the ESP32 OLED Workshop Kit, which sends messages from your phone to a tiny screen.
7. Plug in sensors with no soldering
STEMMA QT (also called Qwiic) cables carry I2C on a tiny 4-pin plug. Adafruit sensors with these ports chain together and connect in seconds. On a board without the port, use the cable with male header ends: SDA to GPIO 21, SCL to GPIO 22 on the classic ESP32.
#include <Adafruit_AHTX0.h>
Adafruit_AHTX0 aht;
void setup() {
Serial.begin(115200);
aht.begin();
}
void loop() {
sensors_event_t humidity, temp;
aht.getEvent(&humidity, &temp);
Serial.println(temp.temperature);
delay(1000);
}
Try it with: AHT20 temperature and humidity sensor, STEMMA QT to male headers cable.
8. Scan before you debug
When an I2C sensor "doesn't work", the first question is whether the ESP32 can see it at all. This scanner prints the address of everything on the bus. No address means a wiring problem, not a code problem.
#include <Wire.h>
void setup() {
Serial.begin(115200);
delay(1000);
Wire.begin();
for (uint8_t address = 1; address < 127; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) {
Serial.printf("Found a device at 0x%02X\n", address);
}
}
}
void loop() {}
On an ESP32-S3 in the Arduino IDE, set Tools > USB CDC On Boot to Enabled to see Serial output.
Try it with: BMI160 motion sensor, APDS9960 gesture sensor.
9. Tap a tag to switch modes
An RFID reader hidden in a sleeve or bag can recognise tags sewn into gloves, bracelets or cards. Tap one tag for a party mode, another for a calm mode. Each tag has its own ID, so every tag can trigger something different.
Try it with: RC522 RFID board and tags, RFID button tags, or the complete RFID + ESP32 Video Kit.
10. Use the onboard RGB LED as a status light
Many small ESP32 boards have an RGB pixel built in. Once a wearable is sewn up you can't see the Serial Monitor, so use that pixel to show what the code is doing: green for running, red for a sensor error. On the ESP32-S3 SuperMini it's on GPIO 48. My free CMozGlow library makes it one line.
#include <CMozGlow.h>
CMozGlow glow(1, 48); // 1 LED, the onboard pixel on the ESP32-S3 SuperMini
void setup() {
glow.begin();
glow.setEffect(8);
glow.setEffectColor(CMozGlow::Color(0, 255, 0)); // green = all good
}
void loop() {
glow.update();
}
Try it with: ESP32-S3 SuperMini.
Want the whole build, not just the hack?
My Video Kits include every part used in a CMozMaker build, so you can follow the video step by step. For the full foundations, from first upload to a battery-powered touch-reactive garment, watch the ESP32 for Beginners course. Stuck on something? Bring it to my Wednesday live stream.
Need more ideas? Spin the Maker-O-Matic 3000 project idea generator.