Lights
Dinosaur phone stand
A dinosaur that holds your phone, with a row of lights down its back. Tap its head for the next light effect.
- Easy
- about 40 min
- ESP32-C3
- 6 parts
- 6 wires
- 43 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
Each effect is a few lines that decide the colour of every LED from one counter that keeps going up. Once you see the trick you can invent your own.
What you learn
Animating LEDs from a frame counter, and stepping through modes with one input.
How it works
input
Touch sensor (head)
decides
ESP32-C3
output
LED stick
Powered with 5 V through the board's USB-C port.
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 6 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 6
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
dino-stand.ino
// Dinosaur phone stand
// Tap its head for the next light effect along its back.
#include <Adafruit_NeoPixel.h>
const int PIN_TOUCH_IO = 3;
const int PIN_STICK_DIN = 4;
const int LED_COUNT = 8;
Adafruit_NeoPixel stick(LED_COUNT, PIN_STICK_DIN, NEO_GRB + NEO_KHZ800);
int effect = 0; // 0 rainbow, 1 breathing green, 2 running dot, 3 off
bool wasTouched = false;
unsigned long frame = 0;
void setup() {
pinMode(PIN_TOUCH_IO, INPUT);
stick.begin();
stick.setBrightness(70);
stick.show();
}
void loop() {
bool touched = digitalRead(PIN_TOUCH_IO) == HIGH;
if (touched && !wasTouched) effect = (effect + 1) % 4;
wasTouched = touched;
frame++;
if (effect == 0) {
for (int i = 0; i < LED_COUNT; i++) {
stick.setPixelColor(i, stick.gamma32(stick.ColorHSV((uint16_t)(frame * 300 + i * 8192))));
}
} else if (effect == 1) {
float level = (sin(frame * 0.05f) + 1.0f) / 2.0f;
stick.fill(stick.Color(0, (uint8_t)(20 + level * 200), (uint8_t)(level * 40)));
} else if (effect == 2) {
stick.clear();
stick.setPixelColor((frame / 6) % LED_COUNT, stick.Color(255, 120, 0));
} else {
stick.clear();
}
stick.show();
delay(20);
}
Libraries
- Adafruit NeoPixel: 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”.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32C3 Dev Module (USB CDC On Boot: Enabled), then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.