Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsRoll an electronic dice: press a button and a random number from 1 to 6 appears on a 7-segment display, complete with a rolling animation. Each digit is drawn by lighting a particular combination of the seven segments. Those combinations are stored in a two-dimensional array, so showing a number is simply a matter of walking through one row of that array. randomSeed(analogRead(A0)) reads electrical noise from an unconnected analog pin, which gives a different starting point every time the board is powered up, without it, the dice would roll the same sequence after every reset.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
220 ohm resistors: one in series with every LED
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_011_digital_dice.inoVerify & upload in Electrolarkint segPins[7] = {13, 12, 14, 27, 26, 25, 33};
int buttonPin = 32;
// Segment order: a b c d e f g
byte digits[7][7] =
{
{0, 0, 0, 0, 0, 0, 0}, // blank
{0, 1, 1, 0, 0, 0, 0}, // 1
{1, 1, 0, 1, 1, 0, 1}, // 2
{1, 1, 1, 1, 0, 0, 1}, // 3
{0, 1, 1, 0, 0, 1, 1}, // 4
{1, 0, 1, 1, 0, 1, 1}, // 5
{1, 0, 1, 1, 1, 1, 1} // 6
};
void showDigit(int n)
{
for (int i = 0; i < 7; i++)
{
digitalWrite(segPins[i], digits[n][i]);
}
}
void setup()
{
analogReadResolution(10); // ESP32 is 12-bit; use 0-1023 like the examples
for (int i = 0; i < 7; i++)
{
pinMode(segPins[i], OUTPUT);
}
pinMode(buttonPin, INPUT_PULLUP);
randomSeed(analogRead(A0));
showDigit(0);
}
void loop()
{
if (digitalRead(buttonPin) == LOW)
{
// Rolling animation
for (int i = 0; i < 15; i++)
{
showDigit(random(1, 7));
delay(80);
}
int result = random(1, 7);
showDigit(result);
delay(600);
}
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
Check each segment pin against the wiring table. The two middle pins (COM) both go to GND on a common-cathode display.
Each digit is drawn by lighting a particular combination of the seven segments. Those combinations are stored in a two-dimensional array, so showing a number is simply a matter of walking through one row of that array. randomSeed(analogRead(A0)) reads electrical noise from an unconnected analog pin, which gives a different starting point every time the board is powered up, without it, the dice would roll the same sequence after every reset.
Display stays blank until the button is pressed. Numbers flicker rapidly for about one second. A single number between 1 and 6 stays on screen.
Yes. It is project 11 of 120 in the Geekobot Titan Kit, in level 2 (Displays and games). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
8 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Carbon Film Resistor 1/4W 5% (Pack of 10), Tactile Push Button Switch, 7-Segment LED Display 0.56" and ESP32 38-Pin Expansion Board. On this page you can tick the parts you already have and add only the rest to your cart.
It is a beginner project and takes about 45 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (titan_kit_011_digital_dice.ino).
About ₹702 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Random number generation with random() and randomSeed(); 7-segment logic, which segments make which digit; Two-dimensional arrays; Reading a button with INPUT_PULLUP.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.