If you build a free PCB we’ll send you another one! Blog about it, post a picture on Flicker, whatever – we’ll send you a coupon code for the free PCB drawer.
If you build a free PCB we’ll send you another one! Blog about it, post a picture on Flicker, whatever – we’ll send you a coupon code for the free PCB drawer.
Two days from now, most people in the United States will be celebrating Independence Day, and starting back in 1777 people celebrated by setting off fireworks. I considered writing about how to remotely set off fireworks – this allows a safer working distance, and a method to automate a show. If you’d rather learn about that stuff, the Walt Disney Company has interesting patents on the topic, and we have already covered one method in the past.
Common sparkler courtesy of Wikipedia
I have instead decided to write about how to make your own sparklers and the technology behind them. Sparklers are legal in many places, but I cannot speak to the legality of making them yourself. If you decide to DIY, make sure to do it somewere legal. SparkFun doesn’t recommend trying this at home.
While sparklers aren’t the worlds most impressive fireworks, the formulation can be tweaked slightly, or even used as is to make stars for use in ‘real’ fireworks.
Fireworks are made up of oxidizers, fuels, coloring agents, color enhancers, binders, and additives.
To burn rapidly enough or to explode, fireworks must contain their own oxidizer. An oxidizer is a substance that has the ability to oxidize other compounds. Oxidization really only means that the substance looses electrons & increases its oxidation state. The name is due to the fact that oxygen was the first known oxidizing agent, but other chemicals like H2O2, MnO4-, F2, Cl2, & Br2 are all common oxidizers.
The material that burns or oxidizes is the fuel. The reaction between the oxidizer and fuel produces heat and often hot gases such as CO2.
There are two sources of light emission in flame: black body radiation and electron excitation. Black body radiation can only produce red, orange, yellow, and white. Think hot metal such as a range burner. Other colors are obtained through electron excitation. As an atom absorbs thermal energy, orbital electrons are pushed into higher energy orbits. Electrons in the excited states are said to be in higher energy bandgaps. This is an unstable state. The electrons have a tendency to return to a stable orbit, releasing heat or photons in the process. The energy bandgap crossed determines the color of the light emitted. Low energy gaps produce reds, while higher energy gaps produce blues or violets. Coloring agents provide the atoms that release light through electron excitation.
Color enhancers are most commonly chlorine donors. The most common color enhancers are Saran resin, Parlon, and PVC. Stable metal ions burn to form oxides or hydroxides. The chlorine donors form HCl when heated. These oxides and hydroxides combine with the HCl to form metal chlorides. These chlorides enhance volatility and light emission. They provide deeper colors. These chlorinate hydrocarbons also serve as fuels.
Binders are used for exactly what one might guess they are used for – to bind the formulation together. The main binder in this formulation is the dextrin. Dextrin has two roles in this mixture. It is both a binder and a fuel. The dry binder must first be partially dissolved in a solvent before it can bind the formulation. The solvent used varies based on the other chemicals in the mix. Some chemicals will react with the water used in this example.
Sulfur is an ignition promoter. As mixed in it is found as S8. In this form it is safe to store with the oxidizer. When heated it easily breaks down into S2 and S3, which react easily with the KNO3, starting a chain reaction igniting the harder-to-ignite compounds.
Other additives found in fireworks are used to prevent caking. Some are used to buffer or adjust the pH to prevent premature breakdown of compounds. Sometimes metals are covered in a protective coating of wax or oil. None of these additives are used primarily for the reaction, and are mostly stabilizers.
I’m covering a popular formulation that can be found all over and may be attributed to Allen F. Clark, who holds patents in the firework industry from the very beginning of the the 20th century.
Formulation, parts by mass. Bind with a 25% ABV solution
Potassium nitrate ( KNO3 ) is an oxidant, or oxidizer. It contains 47.5% oxygen by mass. Pretty obvious to see that with potassium nitrate being the main ingredient and it being nearly ½ oxygen, it’s a main source of oxygen in the reaction.
Barium nitrate ( Ba(NO3)2 ) is also an oxidizer. It contains 36.7% oxygen by mass, and is thus also a major oxidizer in this formulation. Barium compounds produce yellow-green flames, so this sort of acts as a coloring agent too. Unfortunately the BaO formed in decomposition acts as a black body radiator and emits a yellow-white. To get a better green, a chlorine donor is needed to create BaCl, which gives a better green.
Barium is toxic and must be disposed of carefully. It’s best to create insoluble barium sulfate ( BaSO4 ). Mix any leftover barium compounds with Epsom salts in water for a few days to form the barium sulfate.
As stated in the previous section, sulfur is an important ignition promoter, and a fuel.
Airfloat charcoal is a term for very finely ground charcoal. Being finely ground, airfloat charcoal has lots of surface area and reacts fast. It serves as a fuel.
Antimony sulfide ( Sb2S3 ), also known as antimony trisulfide, is another fuel and ignition promoter. Use caution when using this since antimony is fairly toxic. Wearing a face mask or respirator is a good idea in general when working with these powders.
Aluminum is yet another fuel. Due to black body radiation, it burns yellow or white.
Dextrin is the final fuel source, but is mostly included as a binder. It comes in the form of a light yellow powder and must be mixed with water to be effective as a binder. Dextrin is insoluble in alcohol, so make sure you keep your water/alcohol solution below 30%. This formulation calls for 25% alcohol. The exact type of alcohol isn’t important. You can water down Everclear, or even rubbing alcohol. The alcohol helps with wetting and also speeds the drying of the binder.
Dextrin is produced by heating corn starch in the oven at 400˚F. Stir every 15 minutes or so until the corn starch starts to yellow or brown. This should take about 90 minutes.
The list of required supplies is fairly short.
To properly mix the chemicals, it’s best to use a mixing screen. You could steal a screen off of your neighbor’s house, but for better results you should make your own. At your local hardware store or online, find some brass or stainless steel screen around 200 mesh. You could also use aluminum screen, but the main concern is that the screen you use is non-sparking. You can use 1 by 2’s or 1 by 4’s to make a wooden frame to stretch the screen over. Fix the sides together and affix the screen with non-sparking nails or staples. Brass or copper will work great. The wood will form a tray to contain the powders while you shake the mixture through the screen. You might want to seal the wooden frame with polyurethane if you plan on reusing your screen.
1-½″ PVC pipe Courtesy of The Home Depot
A dipping tube can be made from 1.5 inch PVC pipe with an end cap. Make the tube about an inch longer than you plan to make the sticks. Attach the end cap with standard PVC glue and allow to fully cure before using. The day before making the sparklers would work great.
A drying rack can be made from just about anything, including a 2 by 4. Drill a bunch of holes wide enough to fit the skewers or wire, and deep enough to hold them stable. Place the holes far enough apart that you can add wet skewers without disturbing the others; ½″ or so should be fine.
Carefully mix together the chemicals and pour into your screen. Gently work the mixture through the screen into a collection container. Be careful not to grind the chemicals through the screen. The ignition promoters make the compound more sensitive to energy sources such as friction. A brush is a good idea to help work the mixture through the screen.
Slowly stir in your water/alcohol solution. Keep adding more until the mixture becomes syrupy. You will want it thin enough to be pourable, but thick enough that it will leave decent layers during dipping.
Drying sparklers Courtesy of skylighter.com
Fill the dipping tube to about a ½″ from the top. You will likely need a funnel. One by one, dip the skewers or wire into the dipping tube. Place them into the drying rack for at least an hour or so, and up to a day. If your sparklers look as bad as those in the picture above, then you have not added enough water to the binder. To fix them, roll them on some paper to smooth them out when they are just dry enough not to stick to the paper.
Repeat this process until you build up to the desired thickness. The closer to the final few layers you get, the longer you will want to let the previous layers dry. Wait a full day between the last few layers. When the last layer is added let dry for about four days.
You will likely want to apply a protective coating to the finished product. A nitrocellulose lacquer or more PVC cement will work. This coating will promote smoother burning and prevent the fire from jumping down the sparkler.
As discussed in the section on chemicals, various chemicals produce varying colors. The given formulation relies mostly on black body radiation for color and will be mostly a yellow-white. Try mixing in other metal salts. Try mixing in color enhancers such as potassium perchlorate ( KClO4 ). Before adding other chemicals make sure to do your research. You don’t want to create any self-igniting or toxic compounds. Don’t be this guy!
So far on Logic Noise, we’ve built up a bunch of sound-making voices and played around with sequencing them. The few times that we’ve combined voices together, we’ve done so using the simplest possible passive mixer — a bunch of resistors. And while that can work, we’ve mostly just gotten lucky. In this session, we’ll take our system’s output a little bit more seriously and build up an active mixer and simple stereo headphone driver circuit.
For this, we’ll need some kind of amplification, and our old friend, the 4069UB, will be doing all of the heavy lifting. Honestly, this week’s circuitry is just an elaboration of the buffer amplifiers and variable overdrive circuits we looked at before. To keep things interesting we’ll explore ping-pong stereo effects, and eventually (of course) put the panning under logic-level control, which is ridiculous and mostly a pretext to introduce another useful switch IC, the 4066 quad switch.
At the very end of the article is a parts list for essentially everything we’ve done so far. If you’ve been following along and just want to make a one-time order from an electronics supply house, check it out.
If you’re wondering why the delay in putting out this issue of Logic Noise, it’s partly because I’ve built up a PCB that incorporates essentially everything we’ve done so far into a powerhouse of a quasi-modular Logic Noise demo — The Klangorium. The idea was to take the material from each Logic Noise column so far and build out the board that makes experimenting with each one easy.
Everything’s open and documented, and it’s essentially modular so you can feel free to take as much or as little out of the project as you’d like. Maybe you’d like to hard-wire the cymbal circuit, or maybe you’d like to swap some of the parts around. Copy ours or build your own. If you do, let us know!
OK, enough intro babble, let’s dig in.
We perceive compression waves in the air as sound when they reach our ears. We make these compressions by pushing and pulling a speaker cone back and forth. And to make the cone move, we need to get current to flow one way and then the other through the speaker’s magnet windings.
Why the return to fundamentals? Because it’s important to think of the voltages and currents that we want to amplify as being bi-polar, oscillating around some central voltage level. When the signal voltage is higher than neutral, current flows one way and the cone gets pushed. When the signal is lower, current flows the other way and the cone is pulled. The neutral voltage around which we’ll oscillate is called a DC bias (or level) voltage.
In the course of Logic Noise we’ve ignored DC bias voltage whenever possible, but in mixing several signals together, we can’t do that anymore, because signals only add up correctly if they’re generated with respect to the same bias voltage.
We’ve gotten away without blocking DC voltages before because our square wave and triangle wave signals were biased around VCC/2, just like an amplifier with feedback built from a 4069UB inverter is. It all worked fine until we introduced the drum and cymbals circuits, which are so strange that they don’t really even have a well-defined DC level.
Blocking DC voltage is simply done by passing the signal through a capacitor. How large? Large enough that combined with the input resistance of the next stage in the audio chain, it doesn’t cut too much into our low frequency components. In the case of the 4069UB output amplifier stage, a 1 microfarad capacitor will do nicely.
So for now, let’s assume that we first pull the DC level off of any signals that we’d like to mix together, noting that we can “get away with it” for full-swing square waves. Now it’s time to get down to the mixing.
“Passive mixer” is a two-dollar name for combining signals together by passing them through resistors. The higher the resistor value, all other things equal, the quieter the contribution to the overall mix.
It’s the simplest way to add a few signals together, and you should play around with passive mixing anyway, just to get the feel for it. The key to making a passive mixer work is using relatively large resistors for all of the mix inputs.
The downside of the simple passive mixer is that because all of the signals combine at the junction, one signal can influence the others. Essentially, each input signal can pull the junction’s voltage higher or lower than the neutral voltage, and this can feed back out to the other “inputs” through their input resistor. Passive resistor mixers are tremendously simple, but they don’t isolate the signal sources well from each other.
The trick to active mixing is adding negative feedback. Otherwise, it’s just the same circuit as the passive mixer, but it’s a whole lot better.
Remember from the session on filters that the inverter acts as if it were trying to zero out any net incoming signal current that shows up on the input pin; the logic is that if the voltage on the input rises up above the switching point, the output goes low and fights it back down again through the feedback path.
How much resistance is present in the feedback determines how hard the inverter needs to work to cancel out the input signal. More feedback resistance leads to larger voltage swings on the inverter’s output, which end up as louder tones in our headphones, so the feedback path is a great place to add in a master volume control knob.
In the passive mixer example, when one input was high, it raised the voltage at the junction which could then flow “backwards” to the other connected circuits through their input resistors. In an active mixer, when one input is high the inverter cancels it out by lowering the overall mixed output voltage until the input to the inverter sits at its neutral point again. By the negative feedback mechanism, the junction of all the summing resistors is held at a constant midpoint voltage, and none of the inputs can affect each other. Only the output voltage swings around.
Here we see the need to remove the DC level from the input signals — the 4069UB will do whatever it can to hold its input at roughly VCC/2 by pushing current through the feedback loop. A 1uF capacitor before each input resistor will take care of that.
Beyond isolating the inputs from one another, we can also control the gain of an active mixer by changing the value of the feedback resistor. This gives us a simple place to insert a master volume control just by replacing the feedback resistor with a potentiometer. The convenience of a master volume knob should not be underestimated.
If you’re mixing signals, and you have electricity at your disposal, you almost always want an active mixer.
The main function of a mixer is to make a bunch of sounds with different volume levels play nicely together. For instance, the square wave output of a 40106 oscillator swings fully from GND to VCC, while the (unbuffered) triangle wave coming from the input of the same oscillator is a lot quieter. The bass drum circuit is also by nature fairly quiet, and the output of the VCA that gave the cymbal its percussive envelope swing only a few volts. Aesthetically, you’ll want to tweak the volume of each different sound source.
A studio’s mixing console is dominated by an impressive array of faders that fine-tune the volumes of the individual tracks. But before we end up investing in hundreds of dollars of fancy potentiometers, let’s see how far we can get with a bunch of one-cent resistors.
Let’s think about this like an engineer for a second. We want around one volt peak-to-peak of output signal, either for line-level inputs or for headphones. That means that if we’re seeing 9V peak-to-peak square waves, we’ll want to cut them down by about a factor of ten. On the other hand, the one or two volts peak-to-peak that we get out of the low-level signals can plausibly be run through with simple unity-gain buffering. (Bear in mind, this is all before the global output volume control knob.)
If we’re using a 100k potentiometer for the variable feedback resistance (and overall volume), this means that we can use something around 1M Ohm for the high-volume digital signals to knock the amplitude down by at least a factor of ten. Using a 100k Ohm resistor for the quieter signals means that they’ll pass through with unity gain when the channel’s volume knob is turned up to maximum. Of course, you can tweak these values to fit your exact preferences by picking different resistor values.
So round up a bunch of noise-making devices and pick some input resistor values that make them sound good together. (Remembering to remove the DC level with a capacitor if necessary.) If the end result works, nobody will know that you didn’t spend hundreds or thousands on a mixing board.
We saw DC bias issues on the input side, and DC bias raises its ugly head again on the output. Our amplifier’s output is centered around VCC/2, but for headphones (or other speakers) we ideally want no current to flow at this neutral voltage level. This suggests two solutions. First is to create a constant “virtual ground” voltage level at VCC/2 and feed the headphones with our signal and the virtual ground. The other is to strip the DC bias off of the signal and connect the downstream headphones or amplifier to real ground.
The clever way to create a virtual ground at the 4069UB’s neutral voltage (roughly VCC/2) is to set up an inverter with negative feedback as usual but with no input signal. The output of this inverter will be constant and exactly at the inverter’s switching midpoint, so we can use this voltage as the symmetric voltage midpoint that we need for the headphone’s “ground” connection. In the circuit here, a big (100uF) capacitor keeps the VCC/2 level steady. If you’re only going to be driving headphones, or if you’ll only be running the circuit on batteries, this is the hi-fi way to go.
The virtual ground solution runs into trouble when our circuit and the amplifier share a ground connection, as can happen when both are powered by (switching) AC adapters. Then the output’s virtual ground (around VCC/2, remember) gets connected directly to actual ground, and that’s not good. The 4069UB will struggle trying to pump out VCC/2 into a short to ground, probably get hot, and certainly not work so well. The moral of the story: if you use a virtual ground voltage, don’t connect it to actual ground.
If you might have this shared-ground situation, the simple solution is to include DC-blocking capacitors on the output for each of the two stereo channels. While it was easy enough to just say “1uF capacitors” on the input side, the size of output caps should probably be larger but this depends on the load resistance and the amount of current we’ll need to drive into the load.
For example, I have a pair of headphones with 32 Ohm drivers inside, which puts the cutoff frequency of a 100uF capacitor at 1/(2*pi*C*R) = 1/(2*pi*100uF*32 Ohms) = 50 Hz — a low pitch, but one I’d like to hear. Maybe 220uF would be better for low impedance headphones. On the other hand, a less-demanding pair of 600 Ohm headphones will run fine with a 100uF cap down to around 3 Hz which is way below human hearing, and more like a fast tempo than a low note. You could probably get away with 10uF in this case.
In sum, the capacitor-based solution won’t end up shorting to ground, but requires a fairly big capacitor to pass bass notes. The virtual ground solution is clever and works perfectly well with headphones or when battery powered. Shorting the virtual ground to actual ground is to be avoided.
Stereo audio is nothing more than a right and left channel, that is two inverters on the 4069UB instead of one, but it’s a great step forward for our synth devices. You can either send all of one instrument voice to the left or right channel, or connect a single voice to both channels through different input resistors.
It’s nice to have a simple stereo jack breakout board at this point — something you can simply clip or plug into your circuit and then connect up to your headphones or amplifier. Ours was made by soldering a 3.5mm stereo jack to a scrap of copper-clad, traces hand-drawn with a Sharpie, and etched. We tossed on some small wire loops to serve as nice ‘scope test points, because it’s nice to see as well as hear what’s going on.
Let’s take a break from all this theory and build up two capacitor-decoupled mixer circuits.
We’ll play around with ping-pong stereo just to show off, and use the 4066 quad switch chip to do it. Just above, we plugged a given voice into either the left or right channel, or both, and then swapped them around. Now, we’ll use the 4066 switch IC to do the plugging and unplugging for us.
The 4066 quad switch is both as useful and as simple as it sounds — it’s four logic controlled single-pole, single-throw switches in a package. If you want to connect and disconnect stuff, naturally under logic control, this IC is a great solution.
Previously we’ve looked at the 4051 8-way switch and used it to select one from eight possible inputs. The limitation with the 4051 is that it’s only possible to select one from the eight inputs at a time. The 4066, on the other hand, is just a set of four switches. This lets us build setups where more than one input channel is active at a time.
Here, we’ll be using the 4066 to route two sound inputs each into one or both of our right and left outputs. Take one voice, say a quiet one like the drum or cymbal circuit, and connect it through two 100k resistors into two switches from the 4066. The other side of each switch is connected to the left and right 4069UB amplifier circuits, respectively. When only the “left” switch is active our drum sound comes out the left side, and vice-versa. When neither is active, the drum is silenced, and when both are active the drum will be centered in the stereo field, and a bit louder because you’ve got two drum signals in place of one.
We can repeat the same hookup for a second voice. Let’s assume that the second voice is a loud one, like a VCC-to-GND square wave or similar. For comparable volume level with the quieter sound, we’ll need to run this loud input through a larger resistor, say 1 MOhm. Any of these input resistors can be substituted with a potentiometer if you’d like smooth control of the volume level. And again, if any of the input signals are not centered around VCC/2, pass them through a 1uF cap on their way into this circuit and don’t forget to de-couple the output or use a virtual ground.
Now we can turn on and off the left and right channels for inputs A and B with logic-level voltages at the four inputs.
Now don’t forget our sequencing tricks from previous sessions. For instance, adding a 4017 counter to the mix would allow us to trip the different 4066 switches in order by tapping off of the counter stages. Panning two similar sounds (triangle wave and square wave in the demo below) between the two stereo channels in sequence or in pairs can make a neat, evolving sound texture out of very simple sources.
The 4066 switch makes a great general-purpose control for turning on and off a given voice. We’re using it here for panning effects, but you could also imagine hooking up four different pitch oscillators to the four switches and playing a simple tune just by selecting which notes make it through the switches at a given time.
And as you can hear in the videos, the 4066 switch works fast enough to be fed audio signals into the switch control port. Every time a jumper wire is pulled out of the board, it couples with the 50 Hz power-line frequency and makes more overtones as the input frequency and the 50 Hz switching frequency mix with each other, for a sound that’s not unlike what you’d get by running both signals through an XOR.
An on-off switch seems like a humble device, but it’s very broadly useful. So have some fun switching elements on and off in the stereo field here, but don’t think that you’ve seen the last of the 4066.
As promised previously, next session we’ll start getting into a little more advanced Logic Noise circuits, and in particular getting into voltage control. The 4046 phase-locked loop IC has a small voltage controlled oscillator inside it (among other parts) so it’ll be our first stop. We’ll make sweeping pitches without turning knobs. Stay tuned!
A number of folks have asked for a parts list for the Logic Noise series. Here goes.
I’ve tried to keep the variety of parts used as low as possible, for instance by using 100k resistors as a standard value whenever they’ll work. All potentiometers we’ve used so far are also 100 kOhms. Capacitors have been between 10nF and 10uF, a fairly normal range, and we’ve used 100nF caps for almost all of pitch-determining applications. The point of all this is that you can buy these parts in large enough volume to hopefully get a discount.
All of the 4000-series ICs are available under different names from different manufacturers. Most of the chips in my drawer are from TI or Fairchild, but I’ve got a bunch from ON and NXP. Most of the time, they’re interchangeable:
CD4xxx from TI and Fairchild Semiconductor
MC14xxx from ON Semiconductor
HEF4xxx from NXP
In buying ICs, I almost never buy one, and for most of these parts the volume discounts start at 10 pieces. Take the quantites below to be rough suggestions. You can never have too many useful parts.
Paul over at DorkbotPDX has written an article on Teensy Audio Library with S/PDIF support:
Thanks to the amazing effort of Frank Boesing, the Teensy Audio Library now has native S/PDIF output.
Using a $1 TOSLINK connector, or just a red LED, you can get optical S/PDIF digital audio output.
After two and a half years of work and dozens of prototypes, Kaia Dekker and Jesse Vincent have launched Keyboardio Model 01 on Kickstarter: an heirloom-grade mechanical keyboard designed for serious typists.
As you’ll see from the video presentation below, the Model 01 is not just a keyboard. Kaia and Jesse actually re-envisioned the way we type to make it feel great. On top of that it has a beautiful hardwood enclosure and it ships with source code and a screwdriver. The Model 01’s firmware is a regular Arduino sketch you can explore and change yourself.
The project reached its target in the first few hours and you have a few more days to get one!
In the meantime they also joined the Arduino AtHeart Program to make it fully customizable with the Arduino IDE:
We’ve built the Model 01 around the same ATmega32U4 microcontroller that Arduino uses in the Arduino Leonardo. Early on, we figured we’d eventually switch away to a cheaper ARM microcontroller, but then we fell in love with just how easy Arduino makes it for a new programmer to get up to speed. For all intents and purposes, the Model 01’s brain is a regular Arduino. You can update your keyboard from the Arduino IDE. If you want to make your keyboard do something special, there are thousands of Arduino resources online to help you out.
Dave Young lives in Denver with a baby, a wife, and a dog called Penny. Penny’s a good dog (good dog, Penny!) – she’s a softie around the baby, walks to heel, and doesn’t destroy things. All that good dog stuff.
But Penny has one weak spot. Dave says:
Her only issue is that she goes BONKERS for food. My wife and I have done a great job training it out of her when we’re around so we no longer have to worry about a cheese board sitting on the low coffee table, but I know she gets on the counters any time we are away. Sounds like a job for a machine!
How’s it work? There’s a laser tripwire, which triggers audio of Dave saying “Hey!” in a COMMANDING MANNER. The setup also takes a picture of Penny’s infraction using the Raspberry Pi camera board.
Full instructions are available over at Element14 so you can make your own. I’m already thinking about ways you could expand this project: Mooncake, the Raspberry Pi cat, doesn’t respond well to voice commands, but we think a Pi-powered water pistol could be just the ticket on those days we want to defrost prawns. Ideas for your own feature-creep in the comments please!