LEDs

If it ain’t broke, don’t fix it. As I wrote in a previous write-up, a clock turned out to be a great gift idea for a very special person, so I decided to make another for the same person a couple years later. To contrast the wooden, analog clock I made before, I decided to make one covered in LEDs. Same as before, my vision was to create a 12-point mandala. Although this clock has no hands, the 12 points still allow it to display time in a way that is reminiscent of an analog clock, as described in the Patterns section below.

In this post, I’ll walk through my design process from initial sketch through hardware development and programming. At the end, I have provided links to the design files and source code. I also used this project as an opportunity to learn KiCad and to learn and practice the philosophy of what makes a readable schematic, so I’ll mention that as I go on. As a disclaimer, I made this back in 2019, so some libraries etc might be out of date.

Initial Sketch

My first step was to sketch out what I wanted the clock to look like and what I wanted the system to look like. As I mentioned, I wanted to make a 12-point figure, so I used this website to sketch some rotationally symmetric shapes. I wanted at least a little more detail than a 12-point star, but I knew too much detail would not be possible to cover with LEDs, so I settled something with 6 big petals, 6 small petals, and a broken ring around the middle as shown below.

Part of my vision was to have all the LEDs on one side of the piece with no other electronics visible, for a clean look, so I next looked into how many LEDs I could cram onto the outline I made. I exported my outline into draw.io, and, using some squares set to common sizes of RGB LED modules, and assuming a ~6 inch wide piece, I took a guess at how many I could fit in the space, as shown in the image above. Although I guessed each twelfth of the shape could fit 12 LEDs, it turned out to be a squeeze once I started routing, so I later reduced it to 11.

As shown below, I next sketched a block diagram of what the electrical system would need: a single chain of LEDs snaking around the board, a microcontroller to send the patterns, some buttons, and a battery-powered RTC to avoid losing the time when the device was unplugged. For the microcontroller, I decided to use an ATMEGA328P-AU, the same as on an Arduino Nano, specifically so that I could flash it with the Arduino bootloader. I wanted the piece to be user-friendly including if the user wanted to add patterns or fix anything, and I figured this would be the most convenient way to allow this.

Initial draft of the electrical system for the clock, although I changed a couple things by the time I finished the schematics.

Based on some experimenting with an LED strip, I found this many LEDs to be super bright. As a result, I decided to power them with a fairly low voltage of 3.3V. This is actually below the minimum specified in the datasheet for the WS2813 (the LED I ended up using), but I found a large majority of the chips still worked at 3.3V, which was good enough for a one-off project. Lowering their maximum brightness also had the benefit of decreasing the step size of the brightness levels, making the patterns smoother. In addition, this allowed me to use the same 3.3V supply for the LEDs and all the logic chips on the board.

Schematics

With the big picture in mind, I started on the electronics. For the components themselves, some notable choices I settled on were:

  • WS2813 for the LEDs themselves — similar to WS2811 and WS2812 that I’ve used before, and they include a redundant data line so that, if one chip fails, the next chip in the chain still works.
  • DS3231M for the RTC — its crystal is internal to the IC itself along with a temperature sensor, which allows it to compensate for temperature drift, making it much more accurate than a regular RTC.
  • MPM3620A, an integrated buck converter module, for the 3.3V power supply on the board — I find modules like this to be super convenient for prototypes.

I also used an input-protection paradigm that I kind of like: a fuse followed by a transient-voltage-suppression (TVS) diode, as shown in the following snippet. The fuse (F2) protects the external power supply in case the LED clock has a short; it is sized to be big enough that it won’t blow in normal operation, but it will blow before the external power supply is damaged. On the other hand, the TVS diode (D3) protects the LED clock from the external power supply in the case of excess voltage being provided.

Modified snippet from the schematics

TVS diodes work by becoming much more conductive above a certain voltage, making it very hard for the external supply to raise the voltage past that threshold. A TVS diode is typically used for transient spikes in the external supply, but, as long as the TVS diode is rated for more current than the fuse, it will even protect against the user connecting a supply whose voltage is too high in this scheme.

In my case, I used a positive temperature coefficient (PTC) resistor as the fuse. When PTCs heat up from high current, their resistance shoots up, acting like an open circuit, but they conduct again when they cool down. As a result, they act like an automatically-resetting fuse, which is more user-friendly than a regular fuse.

I think I’ve seen this scheme in automotive designs, and I also saw it is used on the Ruggeduino (see Method #1 discussion on this page).

Anyway, you can read through my full schematics attached at the end of this post. In the course of bringing up the board, I noticed a couple errors in the design, so I actually updated the schematics to point them out. I was able to work around all of them for this iteration, but you would want to fix them before reusing the relevant parts of this design.

Schematic Philosophy

In the course of making the schematics, I spent a good deal of time thinking about what makes a good / readable / useful schematic — here is one article I liked on the subject. Let me know your opinions on what makes a good schematic. Making schematics is an art and requires inspiration.

My schematics are done in the hierarchical style (i.e. starting with a top-level page), and some practices I mostly followed were:

  • Each page reads left-to-right: inputs on the left, outputs on the right.
  • Each major integrated circuit gets its own page.
  • Comments are succinct but answer the questions people would have when looking at the schematics.

One thing I didn’t like about KiCad (at least the version I used) was how it handled re-using schematic sheets (i.e. what Altium calls “multi-channel design”). In my case, I didn’t want to draw out all 132 LEDs, so I drew one twelfth of them on a sheet. Then, I created 12 duplicates of that sheet in a higher-level sheet. KiCad was able to do this just find, the only downside is that the exported PDF includes 12 pages that are almost exactly the same except for incremented part designators. I feel like there ought to be a more user-friendly way to tell the reader that the circuit is repeated 12 times without actually printing 12 near-duplicate pages. For example, there could be a single page with placeholders for the designators along with a table of the 12 different designators used in each copy of the circuit.

Layout

As for the layout, I took my sketch from before, re-drew cleanly it in a Solidworks sketch, and exported the DXF to import in KiCad. I routed the whole thing on 2 layers, which made the board quick to manufacture and less expensive than a 4-layer board. This worked fine except for the USB lines, which ended up only working intermittently, I presume because I didn’t know much about controlled impedance or return paths at this point. In the end, I tried a bunch of USB cables and eventually found one that worked reliably.

Routing is always my favorite part of PCBA design, and this project was especially was fun given the 60 degree angles instead of the usual 90 and 45 degree angles. I rotated several components to 60 degrees to fit on the arms, and I did a lot of free-angle routing in the narrow regions of the arms. Unfortunately, KiCad also didn’t have good support for re-using routing (again, “multi-channel design”), so I ended up routing one arm’s worth of LEDs, then writing a Python script to copy the routing to the rest of the arms. Tediously, my script had to modify the text of the layout file directly because the version of KiCad I was using didn’t support scripting within the program itself, but maybe you can do this kind of thing from within KiCad now.

I did the routing once for the LEDs and then copied it 5 times, rotated 60 degrees each time, as shown above. Afterwards, I made minor changes (e.g. to the via placement) based on what components were on the back side of the board.

When I was picking components, I was careful to pick only surface-mount components because I knew one side of the board would be covered in LEDs, leaving no room for leads. However, for the PTC fuses, I could only find through-hole parts of appropriate amperage. As a result, you’ll notice I got creative with a new surface-mount footprint for these parts.

Anyway, KiCad, like other EE CAD software, provides some neat 3D renders of your PCBA, so here’s a look at the finished design:

Manufacture and Assembly

After I laid out the circuit, I had the PCB manufactured by PCBWay, and I installed the components myself. As noted in the schematic errata, I ran into a couple issues as I assembled and tested each portion of the circuit, but I was able to work around all the issues. For the microcontroller in particular, I had trouble flashing the Arduino bootloader and ended up just desoldering the chip from an actual Arduino and using that.

After I installed everything, I also whipped up some 3D-printed standoffs for the board, pictured below.

Software

As far as the software is concerned, this board is an Arduino connected to an LED strip, as mentioned earlier. As a result, the source code is an Arduino project, and it consists of one file for the main loop, one file for the LED patterns, and a couple auxiliary files. Some libraries I used include SoftPWM (for animating the power LED), RTCLib (for the RTC), and Bounce2 (for debouncing the buttons).

For the LED patterns themselves, I wanted to make it easy to highlight the layers of the geometry: the big petals, the little petals, the ring, the outline, etc. I accomplished this by listing the LEDs that made up each of these groups. For example, the middle ring consists of 24 of the LEDs in the entire chain: the 3rd, the 4th, the 17th, the 18th, etc. Then, when I wrote patterns, I could iterate over all the LEDs in one group and apply one color, and iterate over a different group with a different color.

All the patterns are implemented as functions that generate a frame based on the current time. For example, if I wanted a pattern that switches the LEDs on and off each second, I would write a function that checks if the current time is an even second (in which case it turns the LEDs on), or an odd second (in which case it turns the LEDs off) rather than writing a function that calls delay(1 second) repeatedly.

One challenge of generating these frames is that the RTC only provides the current time to the nearest second, which would make for very slow and stuttery patterns. To get around this, I implemented a function that estimates current time to the nearest millisecond. It does this by checking how much time has elapsed on the microcontroller’s internal clock since the last change in the seconds’ value of the RTC time. Long-term, the microcontroller’s internal clock accumulates much more drift than the RTC, but it works great for getting sub-second resolution like this. This is in the file now_ms.ino.

Each pattern function also is passed the current brightness level (0-10) as a guide for how bright to make the frame. In the main loop, one button adjusts this brightness level, and the other button changes what pattern is displayed.

Patterns

If you’ve read this far, you’re probably interested in what the patterns are, and how to read the time off of any of them! Here’s a table. Some of the patterns convey the time while some are just aesthetic. I felt like, since anyone can just check their phone for the time, it was more important that each pattern be beautiful or interesting than be a strictly useful timepiece.

PatternDescription
Analog ClockShows the time like an analog clock: the innermost ring of LEDs is the point of the hour hand, the middle ring is the point of the minute hand, and the outer ring is the point of the second hand.
Rainbow CycleA rainbow cycle moving one direction over all the LEDs paired with a white pulse moving the opposite direction over the big petals
LavaRed and white pulses that move over the entire chain of LEDs
Rainbow Fade + HeartbeatThe entire piece fades through the rainbow every 24 hours while the middle ring pulses white every 3 seconds.
SparkleRandom white flashes over the entire chain of LEDs

The following video shows each of these patterns.

Files

Here are the schematics, CAD files, and software for reference. Enjoy!

In case you haven’t had enough of rooms lit up with LED strips, here’s another! This is an old project, but I thought it might be helpful to anyone who wanted to do something similar: LED lights controlled wirelessly via nrf24l01 radio modules.

Excuse the breaks in the panorama; humans are still working on panorama technology.

The effect is similar to the room lights I put up in my apartment in Boston (link to post). However, the first place I lived when I moved to San Francisco a couple years ago had some cool rafters in the ceiling, and I wanted to illuminate each of them in sync but without hanging too many wires. So, instead of using a Raspberry Pi to control the strips, I made several strips, each controlled by an Arduino with a radio module. I sent commands to all strips at once using a separate module acting as a remote control.

My favorite pattern was this red, pulsing pattern.

As I mentioned, I used nrf24l01 radio modules, which I find to be really convenient for adding wireless capabilities to a project. The controller for each strip ended up looking like this:

As before, I used 12V, triplet-addressable, WS2811-based LED strips since they’re really cheap yet still allow you to make patterns with spatial motion. A 12V supply powers both the strip and the Arduino (which regulates it down to power the radio). For anyone who would like to replicate this, here’s the wiring that I used between the Arduino and the nrf24l01 module.

As for the software, the source code is on Github here. I used the Adafruit Neopixel library and a nRF24L01 library that can be found here.

In the source code, two Arduino sketches are provided. One sketch is for the light strip controller, and one is for the remote control. The light strip controller advances through a cycle of a few simple patterns whenever it receives a message over radio. The remote control sends a single message when it starts up, so pressing the reset button is sufficient to change the pattern. I powered the remote control Arduino with a USB battery bank so it was portable. I didn’t take a lot of time to make sure the setup works just right, so I’m providing this code more as a reference than as something that will work off-the-shelf.

With that, I’ll leave you with some media for how it turned out.

The molding and curved ceilings of San Francisco Victorians turns out to be great for LED diffusion.
I love how the spindly arms of this old-fashioned chandelier complement the vibe of the LED lighting.

I’ve slowly been acquiring blacklight-reactive props, with the latest being a slinky I bought from Slinky Josh at Ignight. Disappointed that everywhere in the world isn’t flooded with blacklight, I decided to take matters into my own hands–er, wrists. I present my blacklight LED wristbands:

(I’m just an amateur slinky and contact ball, but I hope you like the effect)

Overview

Here’s a diagram of the parts in this build.

This setup includes (1) 12V battery pack, (2) male-male coupler, (3) 12V dimmer, (4) splitter, (5) wires long enough to go down my arms, and (6) wrist bands

The LED strips are 12V blacklight LED strips, with 8 strips on each wristband. Each strip itself is composed of segments, where each segment has 3 LEDs and a resistor in series. I found 3 segments was a good circumference to wrap around my wrists, so in total each wristband had 72 LEDs. Before buying the battery, I hooked up my LED strips to a voltage source and found that the draw for that many LEDs would be about 850mA.

For the battery, I found a USB battery pack that had a 12V output. I liked the option of using a USB battery pack rather than using a hobby lipo because I feel like USB battery packs look less sketchy to security if I want to take these into a club or something.

Materials

If you want to build your own, here are the materials I used.

  • blacklight led strip (link)
  • 12V dimmer (link)
  • battery (link)
  • splitter (mine came with the battery)
  • power connectors (link)
  • male-male coupler (link) (or you can make your own from the connectors)
  • speaker cable
  • hookup wire
  • rectangle of fabric
  • sew-on velcro (picked some up from Mendel’s)
  • thread, solder, hot glue

Assembly

This sketch shows the LEDs on one side and matching pieces of velcro on either end. The fabric extends beyond the LED strip on one end, which is the end where I put the scratchy velcro.

First, I cut out rectangles of fabric wide for the number of LED strips I wanted and long enough to wrap around my wrist with a little extra for the velcro. Then, I hemmed the edge and then sewed on the velcro. This step took a while because I hand-sewed it, but it would be fast to machine sew.

Next, I stuck the LED strips to the fabric, loosely affixed with the adhesive on the back of the strips. I noticed that the LED strips had sections with copper on the sides but no copper running through the middle, so I took advantage of this and sewed straight through the LED strip.

Is sewing through LED strips sketchy?

Next, I soldered together all the strips using short pieces of wire to connect all the ground pads and all the 12V pads. Besides the hand sewing, this step took the second longest, partially because it was hard to pin everything down. If I were making a lot of these, it might be worth it to make a tiny PCB with connected ground and 12V pads that just acts as a backing to solder the strips to.

I used the helping hands to hold the wire and also pin down the wristband as I was soldering.

The strips are soldered together in parallel here, with all the 12V pads together and all the ground pads together.

Anyway, after soldering everything, I used some thread to secure the wires to the fabric, and then I coated all the connections in  hot glue, to cover the exposed copper and for strain relief. I also  soldered on the long wires and female power connectors.

Final assembled wristband

Here’s the front and back of the final product.

Added bonus: the lens flare makes my hands shoot lasers.

Here’s a follow up to my previous post on room lighting with LED strips. I noticed my closet was a little dingey and I still had another two meters of LED strip leftover from my previous order, so I installed them inside my closet. My closet at the time had 3 doors, so I added some limit switches to detect when each door was opened, and I connected the limit switches and LED strip to an Arduino and a power supply.

In retrospect, I bet I could generate the timing signal for the LED strip with just some 7400 series ICs, and it might be fun, but I wanted to provide for animation in the future — say, fade-in and fade-out, or illuminating just certain sections of the closet at a time.

Anyway, I threw on some code with the Bounce2 and Adafruit NeoPixel libraries and got it running. Here’s a video of the lights turning on and off as I open and close the doors.

 

I recently completely encircled my room with LED strips; in this post, I’ll outline how I set everything up.

Here's a panorama of the LED strip that forms a full loop around my room.

Here’s a panorama of the LED strip that forms a full loop around my room. The rainbow effect is a result of the entire strip fading through several colors in the time that it took to take the panorama. However, this strip is also addressable in triplets.

First of all, I used some low-LED-count strips with WS2811 driver chips, addressable in groups of 3 LEDs. Nowadays, you can buy very LED-dense strips that are truly individually addressable, but I knew that the triplet-addressable format was common a few years ago and conjectured that there would still be a few of these strips for sale on the cheap as manufacturers tried to sell off their remaining supply. I was right! I bought 16 feet of LED strip and ended up using most of it. I used the rest to illuminate my closet, which I’ll describe in a later post.

First, I set up the electronics, largely based on Adafruit’s guide here. The electronics consisted of a single several-meter LED strip, a 12V power supply, and a Raspberry Pi to control the strip. The Pi uses 3.3V logic levels while the WS2811 drivers on the strip use 5v to 12V, so I integrated a level shifter (the 74AHCT125) into the cable between the Pi and the strip, as shown below. I got a 12V power supply from re-use.

Check out my dead bug soldering.

Check out my dead bug soldering.

After I set up the electronics, I mounted the strip to my wall. I was hoping to be able to use the adhesive backing on the strip, but it proved woefully ineffective, falling down after a couple hours. So, I temporarily reinforced the strip with masking tape and then developed some mounts to hold down the strips, as can be seen in the following pictures.

I could find similar LED strip clips online, but only with screw-sized holes. I wanted to use small nails for drywall, so I design and printed a nail version: rendering on the left, in place on the right.

I could find similar LED strip clips online, but only with screw-sized holes. I wanted to use small nails for drywall, so I design and printed a nail version: rendering on the left, in place on the right.

After mounting the strip on two walls, I realized that the other two walls in my room were actually concrete beams at the height of the ceiling. I can't nail into concrete, so I whipped up a new version of the clip with a large pad for a command strip.

After mounting the strip on two walls, I realized that the other two walls in my room were actually concrete beams at the height of the ceiling. I can’t nail into concrete, so I whipped up a new version of the clip with a large pad for a command strip.

One problem occurred when I attempted to use the strips to illuminate my room with white light at maximum power: the color at the end of the strip would be much dimmer and redder in color than at the start the strip. I didn’t take a multimeter to it, but I expect the voltage at the end of the strip was drooping signficantly even while the beginning was at 12V due to the accumulated resistance over the length of the strip.

At this corner of the room, the strip starts (on the right) and ends (on the left).

At this corner of the room, the strip starts (on the right) and ends (on the left).

I mostly resolved this by linking the power lines from the end of the strip to the power lines at the beginning of the strip in the corner where they met.

After applying the fix, the discoloration in the start/end corner (on the right) is nonexistent, and the discoloration on the far corner (bottom left) is minimal.

After applying the fix, the discoloration in the start/end corner (on the right) is nonexistent, and the discoloration on the far corner (bottom left) is minimal.

Subsequently, there was still a slight discoloration in the middle of the strip, in the corner of the room farthest from the beginning (and end) of the strip, but I resolved this (not pictured) by slightly dimming all the LEDs and then compensating the LEDs by a linear factor based on their distance from the start/end corner.

I run various effects on my strip that are only achievably with addressable (groups of) LEDs–theatre chase patterns, racing blobs of color, etc–but one of my favorites is simply running the same color on every LED and fading through the rainbow. This produces an effect on my other decorations, seen below, reminiscent of what I’ve heard called RGB Art. Here’s a gallery of RGB Art by artist duo Carnovsky.