Binary Email Lights

[This is a guest post written by Zach.]

Six unread emails!

I’ve been using a Raspberry Pi as a desktop for a while now and it has been working great, but one annoying thing was that I had to turn on both my monitors (in case the mouse is in the wrong one) when I wanted to check my email, so I thought to make a light box to tell me if I had an email. Also, flashing lights are always cool.

I, with my dad, built a display box with three LEDs so it can show up to seven emails in binary.


The hardware side of this project was pleasingly simple because the Raspberry Pi has built in GPIO pins.

What we used:

LEDs, resistors, ethernet cable, heat shrink, header pin connectors, small, sturdy cardboard box, and hot glue (lots).


We set up the LEDs and resistors like in this Pi Hut tutorial with a common ground, and hot glued them into the box. We used a length of ethernet cable to connect between the Raspberry Pi and the LED unit. We connected the ethernet cable to the Raspberry Pi via 3 GPIO pins and one ground that were all right beside each other with the header pin connectors as shown. I have a nice case that leaves the GPIO pins accessible.


We wrote the software in two pieces; one that got the number of unread emails and one that lit up the lights to show it; breaking it into smaller problems to solve and test.

Email Checker

We followed Google’s Gmail Quickstart example, which was very easy to read and use. We changed the example a bit, to make it:

  • get the number of unread emails instead of a list of labels
  • write the output to a file instead of printing it
  • repeat in a 30-second loop

LED Binary Display Driver

This part of the system:

  • reads the content of the file and turns it into an integer
  • works out which lights to turn on and turns them on
  • deals with the special case of there being more than seven unread emails by flashing all three lights
  • repeats in a one-second loop

Race Condition

Surprisingly, the display driver program occasionally read the file while it was empty and then crashed. We knew this was a possibility, but thought it wouldn’t actually happen. We fudged our way round it by the display driver retrying after two seconds if this happens.


Play with the slider:



Future work

  • Automatically start the two programs when the Raspberry Pi is booted up.


The code is available here.