Electronics

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.

Also known as the “Sketch as Fuck Lamp Dimmer” per my friend Eric, the design originating from this application note in general has the usual lamp dimmer topology: a zero detector, a timer, and a triac. These three components implement phase cutting, specifically the triac performs phase cutting on AC current from mains supplied to a load. The first two components, the zero detector and timer, are both implemented in a microcontroller, the subject of the application note.

However, this circuit is unusual in terms of its logic power supply, whose ground is not connected to the neutral of mains. Rather, the 5V node is connected to the hot wire of mains, and the 0V node is constructed 5 volts below that wire.

I designed my schematic in Eagle. Though not labeled, for space, the diode is a 1N4448, and the zener is a BTZ52C5V6T-TP.

I designed my schematic in Eagle. Though not labeled, for space, the diode is a 1N4448, and the zener is a BTZ52C5V6T-TP.

One consequence of this is that, while plugged into mains, the logic of this circuit cannot be connected to any logic that is grounded to the neutral of mains unless the signals have some isolation. For example, I couldn’t connect connect my PIC programmer to the circuit while the circuit was plugged into mains without something exploding! To get around this, I plugged my circuit into an isolation transformer prior to mains during the latter part of programming the circuit, after I had confirmed my circuit functioned correctly electrically. As discussed later, this design is necessary to achieve proper biasing in the circuit, and you can see this power supply in other circuits as well–for example the application note for another lamp dimmer from ST.

Amused by this application note, I decided to build my own programmable lamp dimmer circuit. There are a couple neat techniques I took to make this project, so I’ll go through them one by one.

Power Supply Component Sizing and Theory of Operation

The application note intends to point out the low power consumption of the PIC10F microcontroller. As an example, it suggests building a lamp dimmer whose logic power supply resembles a 5V linear zener regulator. The power supply schematic from Eagle is given below–the 5V and 0V nodes are the power supply for the microcontroller. Normally, a linear regulator is not appropriate for converting between such disparate voltages — 120V (rms) to 5V. The voltage change is implemented by dropping the difference in voltage across a resistor, the 22k resistor in this case. Really, the only advantages to this kind of circuit are the relatively low number of parts, the cheapness of those parts, and the small footprint of those parts. For example, a circuit of components of this size could be embedded in the plug of a lamp itself, perhaps as a feature or a prank.

This regulator converts mains 120VAC to 5V; mains is plugged into the connection indicated, with hot connected to the upper wire and neutral the lower wire.

To explain how this circuit works and how to size components, let me simplify it. First, let’s consider the AC input signal, which is a hot wire and a neutral wire whose voltages differ by a 120VAC sine wave. An oscilloscope reading I took of mains is shown below.

The resolution is 50V/div. Mains provides roughly a sinusoidal waveform.

The resolution is 50V/div. Mains provides roughly a sinusoidal waveform.

However, since what we intend to be the 5V node of the power supply is connected to hot, let’s instead consider the relationship between hot and neutral with hot as our reference voltage. This is still a sine wave, we’re just using neutral as our fixed reference, as shown in the following plot, where neutral is blue and hot is red.

Neutral is in blue and hot is in red.

Neutral is in blue and hot is in red.

The rectifier diode (the non-zener diode in the circuit) may make this circuit hard to understand for someone who understands a regular zener regulator, so let me replace it with an ideal diode with no diode drop–it conducts like a wire when it is forward biased and does not conduct when it is reverse biased. Then, the circuit is always one of the two circuits in the following image.

This image shows two circuit representations if the diode were replace by an ideal diode with 0V forward voltage. The 0V forward voltage is inaccurate and is close to 0.7V, but in the actual circuit, the zener diode compensates for this because it is not actually a 5V zener but close to 5.6V.

This image shows two circuit representations if the diode were replace by an ideal diode with 0V forward voltage. The 0V forward voltage is inaccurate and is close to 0.7V, but in the actual circuit, the zener diode compensates for this because it is not actually a 5V zener but close to 5.6V.

During the first half cycle of the plot of neutral above, when neutral is negative with respect to hot, the diode conducts, so current flows from hot through the zener, capacitor (until it charges), and system load. Then, the sum of these currents flow through the 22k resistor to neutral. Due to its conduction characteristics, the zener diode drops at most 5V, and so the capacitor charges up to this voltage. The zener was selected specifically to have a low required zener current (on the order of 1 mA).  The 22k resistor was sized to allow enough current for the system to run and the zener diode to zener while limiting the current to be less than the amount that would destroy the zener.

During the second half cycle, neutral is positive with respect to hot, to the diode is biased  in the opposite direction. Current still flows through the resistor, but in the opposite direction and back through the zener. However, current does not flow from mains through the capacitor or the rest of the system. Rather, the microcontroller draws current from the capacitor, and it slowly discharges. The capacitor was sized such that it could power the microcontroller for one half cycle without its voltage drooping significantly. The 330mfd capacitor chosen corresponds to a 10% droop. I later shrunk the capacitor, taking note that this particular controller actually runs on as low as 2V.

Notably, the resistor could actually be larger, as a 22k allows as much as 7mA, and at 22k, the resistor dissipates on the order of half a watt, more than ought to be dissipated by a quarter watt resistor. In my circuit, the resistor heats up considerably. In future versions, I’ll replace this with a larger resistor, such as 220k. The 22k size is an artifact from the size chosen in the original application note, which appears to be a typo. Equation 5 of the application note incorrectly comes to the conclusion that passing a 0.7mA current across a 110VAC drop requires a 22k resistance when actually this number is 220k. The application note also spreads the power dissipation across two quarter watt resistors.

Based on this explanation, we could imagine systems where it is not the case that logic 0V is disconnected to the neutral of mains. For example, we could rearrange the regulator such that the 0V node is connected to neutral and the 5V node passes through the 22k resistor to hot. However, then we would also have to place the triac below the load such that it is switching. As a result, we would be switch neutral rather than switching hot, which is undesirable because it breaks convention. Moreover, some two-terminal AC devices have their cases grounded to their neutral, so this is undesirable in terms of safety as well. Moreover, if one logic power rail (0V) is at the level of the triac, and the other is 5V above it, then we will be switching the triac in quadrants 1 and 4 rather than 2 and 3. Quadrant 4 of a triac consumes the most current, so we would prefer to avoid it. As a result, we construct a system where one logic rail (5v) is at the level of the triac, and the other is 5V below the triac.

Update: Zero Detector

Eric says I should write about the zero detector, too, so I’m adding a section here. He says:

cool
you didn’t talk much about the zero crossing detector which i think is almost as cool as the regulator
since you can’t just take 120 VAC and put it into a microcontroller pin
but they tapped it off the pre-capacitor regulator

Basically, the voltage at the node between the zener and rectifier alternates between slightly above +5V (due to the zener diode forward drop) and slightly below 0V (due to the rectifier forward drop). As a result, this a great node to use for zero crossing detection.

Etch Mask with Spray Paint and Laser

Left shows the copper traces while right includes an overlay of the components.

Left shows the copper traces while right includes an overlay of the components.

After designing the schematics and laying out my PCB in Eagle, I created my PCB. I used a mask technique described in a couple guide online, which I will redescribe here. First, I cut my copper clad sheet and cleaned it with acetone and steel wool. Then, I coated it in 2-3 coats of spray paint.

I first used green-painted copper clad sheet but later used white-painted sheet after I attempted to etch the former with some bunk etching solution.

I first used green-painted copper clad sheet but later used white-painted sheet after I attempted to etch the former with some bunk etching solution.

Next, I used a laser cutter to blast off the paint in areas I wanted to etch.

lazors

lazors

Finally, I etched the board like normal and used acetone to remove the paint.

Here's the circuit I finally etched, with white spray paint mask.

Here’s the circuit I finally etched, with white spray paint mask.

After I etched the board and acetoned off the paint, I drilled holes in the PCB.

After I etched the board and acetoned off the paint, I drilled holes in the PCB.

After etching, I populated the board, debugged it, powered it on, and programmed it. Don't touch this! Mains is exposed here in bare copper. I plan to encase this for safety.

After etching, I populated the board, debugged it, powered it on, and programmed it. Don’t touch this! Mains is exposed here in bare copper. I plan to encase this for safety.

Software and Debugging

Next, I debugged and programmed the system. The microcontroller pin connected to the circuit through a 22k resistor is for zero crossing detection. I was hoping to use the sleep function of the microcontroller to put the microcontroller in a low power state until a change was detected on this pin, indicating zero crossing, but I realized the microcontroller had no memory between resets, so I could not implement this while also implementing a fade effect, which requires a counter that passes its state cycle after cycle. Instead, I just looped my program until a change was detected on the pin.

 

For simplicity, I designed with entirely through-hole components, except for my zener because I could not find low enough current zener that was through-hole. The two black wires were temporarily attached for debugging.

For simplicity, I designed with entirely through-hole components, except for my zener because I could not find low enough current zener that was through-hole. The two black wires were temporarily attached for debugging.

As indicated before, debugging was difficult because I could only measure differential measurements with my grounded oscilloscope. Initially, this proved to be ineffective because the oscilloscope could not provide volt-scale resolution on differential measurements while reading 120V measurements. I attempted to use a high voltage differential probe, but this also proved ineffective for measurements on the order of volts. Ultimately, I connected my circuit to mains through an isolation transformer, allowing me to probe the 0V and 5V nodes directly.

This oscilloscope reading shows two signals of different scales. Red is neutral measured relative to hot, at 50V/div. Yellow is the 5V power supply, measured at 20mV/div. Yellow has a ripple roughly 30mV peak to peak. During one half cycle, the capacitor recharges, and during the other, it discharges.

This oscilloscope reading shows two signals of different scales. Red is neutral measured relative to hot, at 50V/div. Yellow is the 5V power supply, measured at 20mV/div. Yellow has a ripple roughly 30mV peak to peak. During one half cycle, the capacitor recharges, and during the other, it discharges.

Check it out in action!

You can see in the video above that I shrunk the capacitor per my above note about sizing.

Ever wanted to be a robot? Become 0.02% more cyborg with Electronics Facepainting!

Becca G. demonstrates being a cyborg.

Becca G. demonstrates being a cyborg.

I initially had this idea when I heard about a new printer that could print on a variety of materials (c/o Hack a Day). The printer works by printing traces with silver nitrate solution, which precipitates onto the substrate when a second chemical, ascorbic acid, is added. Right off hand, these chemicals struck me as not particularly bad for humans beyond their staining and being mild skin irritants. This gave me the idea to apply them to people. Their risks were minor for the sake of art.

Unfortunately, silver nitrate solution is rather expensive; taking this into account, I searched for an alternative chemical for skin-based circuit traces. The next idea I found was a gallium-based ink, tested in a 2013 research paper I found online by Yu et al. at Tsinghua University. The LEDs on a hand in one of their pictures inspired me, but again gallium was too expensive for my purposes.

A researcher demonstrates  a circuit made with gallium paint, c/o Yu et al.

A researcher demonstrates a circuit made with gallium paint, c/o Yu et al.

There are a variety of sources online for how to mix your own conductive paint, conductive rubber, or conductive glue. Most involving mixing the non-conductive version of the substance with graphite powder and produce relatively high resistance products.

However, I settled on Bare Conductive, which makes a non-toxic, reasonably priced conductive ink. Some of their initial videos suggest their product is skin-safe and intended for skin, but they appear to have gone back on this since the Bare Conductive MSDS now recommends against skin contact and any mention of skin is absent from their website. The MSDS warns that it “may cause skin sensitization” due to an allergy to the Diazolidinyl urea in the paint. Maybe they’re also worried about people attaching volts to their skin and zapping themselves.

Anyway, I went with their earlier advice since I had already decided I was fine dealing with mild dermatitis. I ordered a batch for the East Campus Bad Ideas Festival, though I ended up not using it until later. When it arrived, my friend Becca G. and I played around with various techniques before demonstrating it at a party and later MIT Campus Preview Weekend.

This is the first circuit I painted on my arm. I added details with eyeliner.

This is the first circuit I painted on my arm. I added details with eyeliner.

I used Bare Conductive for connections and strands of wire for long traces.

I used Bare Conductive for connections and strands of wire for long traces.

This close up shows the strand of wire as well as the slip of paper I inserted under the LED to make up for my sloppy connection work.

This close up shows the strand of wire as well as the slip of paper I inserted under the LED to make up for my sloppy connection work.

We decorated and annotated the circuits with black, metallic, and neon eye liner pencils. Here are some pics of Becca and me before a party.

RoboBECCA 9000

RoboBECCA 9000

My other arm is robotic.

My other arm is robotic.

One thing we noticed immediately was that the conductive ink, while conductive, still had quite a bit of resistance. It turns out the ink is OK for electrical connections and great for making resistors in the 100Ω to 10kΩ range, but pretty bad for making regular traces longer than an inch. As a compromise, I pulled some single strands out of some stranded wire and used these for long traces, securing it with the paint, which I treated like glue or solder.

Mostly, we just painted LED circuits, but I tried a few others. Here’s an oscillator on some paper that didn’t end up working, and I never got a change to debug it further before I cleaned up. That said, I’ve constructed this circuit on a breadboard and artificially added a couple hundred ohms of resistance at every electrical connection to simulate the resistance of the paint at joints, and it worked great, so I suspect this circuit could be successful with some tweaking.

Works on paper (top right corner), but doesn't work on this paper

Works on paper (top right corner), but doesn’t work on this paper

One problem I had was the fragility of the circuits–it was important to avoid accidentally brushing your skin against any rough surfaces. In the future, I’d like to try using clear liquid latex to secure some of these circuits.

If there’s interest in this, I can post some step-by-steps on how to make your own Electronics Facepainting.

This isn’t a project that I came up with, but it’s the final lab project for MIT’s introduction to circuits class (6.002), and I thought it was a neat project that brought all the phenomena we studied over the semester as well as encouraging modular circuit design, so I wanted to share it with you. The project was to build a music playing system, as shown in the following block diagram. A memory unit was given to us, but we built a clock, a DAC, an active low pass filter, and a small amplifier.

This block diagram of the music player was taken from the 6.002 OCW website.

This block diagram of the music player was taken from the 6.002 OCW website.

The clock was simply a square wave generator made with a Schmitt trigger. The DAC required a set of resistors with certain relative values, so I made a python script to select a set of resistors. The script looked at the set of all standard resistor values in the lab to which I had access as well as the combinations of those values in series and parallel, and it sorted those by total error. From the results, I selected a set that had mostly single resistors rather than combinations, for ease of assembly. You can see the pile in the middle of the breadboard.

I built this part first. It contains the timer, counter, memory, and DAC.

I built this part first. It contains the timer, counter, memory, and DAC.

I tested each module after I built it.

The signal from the memory had high frequency noise due to being discretized.

The signal from the memory had high frequency noise due to being discretized.

The low pass filter smoothed the noise out.

The low pass filter smoothed the noise out.

Here, the amplifier scales a sine wave.

Here, the amplifier scales a sine wave.

I added a low pass filter and amplifier at the bottom of the breadboard..

I added a low pass filter and amplifier at the bottom of the breadboard.