Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsBuild a clock that shows the time in binary: five LEDs for the hour and six for the minute, each one a single bit. Every whole number can be written as a sum of powers of two, and that is all binary is. The hour 13 is 8 + 4 + 1, so the LEDs worth 8, 4 and 1 light and the rest stay dark. bitRead(value, position) pulls out a single bit for you, bitRead(13, 3) returns 1 because the value-8 bit is set. Five bits reach 31, enough for hours 0 to 23; six bits reach 63, enough for minutes 0 to 59.
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
LEDs from the kit's red, green, yellow and blue packs
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_031_binary_clock_leds.inoVerify & upload in Electrolarkint hourPins[5] = {13, 12, 14, 27, 26}; // bits 4,3,2,1,0
int minutePins[6] = {25, 33, 32, 5, 23, 19};
int setHourBtn = 16;
int setMinuteBtn = 17;
int hours = 12;
int minutes = 0;
int seconds = 0;
unsigned long lastTick = 0;
void showBinary(int value, int pins[], int bits)
{
for (int i = 0; i < bits; i++)
{
int bitPosition = bits - 1 - i;
digitalWrite(pins[i], bitRead(value, bitPosition));
}
}
void setup()
{
for (int i = 0; i < 5; i++)
{
pinMode(hourPins[i], OUTPUT);
}
for (int i = 0; i < 6; i++)
{
pinMode(minutePins[i], OUTPUT);
}
pinMode(setHourBtn, INPUT_PULLUP);
pinMode(setMinuteBtn, INPUT_PULLUP);
Serial.begin(9600);
lastTick = millis();
}
void loop()
{
if (millis() - lastTick >= 1000)
{
lastTick = lastTick + 1000;
seconds = seconds + 1;
if (seconds >= 60)
{
seconds = 0;
minutes = minutes + 1;
}
if (minutes >= 60)
{
minutes = 0;
hours = hours + 1;
}
if (hours >= 24)
{
hours = 0;
}
Serial.print(hours);
Serial.print(":");
Serial.println(minutes);
}
if (digitalRead(setHourBtn) == LOW)
{
hours = (hours + 1) % 24;
delay(250);
}
if (digitalRead(setMinuteBtn) == LOW)
{
minutes = (minutes + 1) % 60;
seconds = 0;
delay(250);
}
showBinary(hours, hourPins, 5);
showBinary(minutes, minutePins, 6);
}
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.
Turn it round: the long leg (anode) goes to the GPIO side through the 220 ohm resistor, the short leg to GND.
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.
Every whole number can be written as a sum of powers of two, and that is all binary is. The hour 13 is 8 + 4 + 1, so the LEDs worth 8, 4 and 1 light and the rest stay dark. bitRead(value, position) pulls out a single bit for you, bitRead(13, 3) returns 1 because the value-8 bit is set. Five bits reach 31, enough for hours 0 to 23; six bits reach 63, enough for minutes 0 to 59.
At 13:05 the hour LEDs read 01101 and the minute LEDs read 000101. The minute pattern changes once a minute. Press the set buttons to advance the hour or minute.
Yes. It is project 31 of 120 in the Geekobot Titan Kit, in level 7 (Binary and code). 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), 11 × Through-Hole LED Pack (Pack of 10), Carbon Film Resistor 1/4W 5% (Pack of 10), 2 × Tactile Push Button Switch 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 intermediate project and takes about 45 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (titan_kit_031_binary_clock_leds.ino).
About ₹866 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Binary arithmetic and place value; Bitwise operations with bitRead(); Driving many outputs from an array and a loop; Keeping time with millis() without drifting.
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.