Arduino Projects


Table of Contents:

  1. Audio VU Meter
  2. 8x8 Red Dot Matrix Display Using the 4017 Decade Counter
    1. LED Matrix Banner
    2. Audio Spectrum Analyzer
    3. Breakout Clone
  3. 8x8 RGB Dot Matrix Display
  4. One-Digit Clock
  5. Four-Digit Clock
  6. Ping Pong Ball Used as an LED Lampshade
    1. Breathing LED
  7. Halloween Jack-O-Lantern with Animated Eyes
  8. 3x3 LED Cube

Audio VU Meter


Added June 18, 2012
I recently heard about the Arduino Uno board and picked-up one last week to check-out. After witnessing first-hand what all the hype is about, I only wish I had found out about these boards sooner - they have brought microcontrollers to the masses the way Commodore did the same for computers a generation ago!

After following the obligatory blinking / pulsing LED tutorials, it seemed like it would be cool to connect a bunch of LEDs and use them to display the relative volume of audio in real time, hence my first project seen here. It was also my first attempt at creating a "home-made" shield. They say necessity is the mother of invention, and after a while I really needed to clear the breadboard so I could reuse it, along with my very limited supply of jumper wires, for other projects. It's comprised of Radio Shack's popular 276-150 protoboard, which is surprisingly close in dimensions with the Uno (which is probably coincidental). Pass-through headers were soldered through the top. That's it! At under $5 a pop, that's not a bad deal for a shield!

This shield is a simple layout comprised of ten LEDs with current-limiting resistors, connected to digital pins 2 through 11. A potentiometer has been added for sketches that use it, and is coded here for analog pin 0. In the VU Meter application, it is used to adjust the sensitivity. An eighth-inch stereo audio jack is connected with the left channel going straight to analog pin 1, and common ground of course going to one of those so liberally-provided on the Uno. When connected to the headphone jack on my iPod, I found that I had to turn the volume up to about 95% of full volume in order to get enough dynamic range for the meter to be usable. To calibrate, use the lowest volume level on the audio device which will still drive the display into the red zone when the potentiometer is turned all the way up. If the signal is coming from a line-level source, this doesn't apply as the signal level is usually constant and independent from the device's volume level.

Select code:




8x8 Red Dot Matrix Display
Using the 4017 Decade Counter


Added June 23, 2012
If a string of LEDs was fun to watch, I figured the excitement could only be multiplied with a two-dimensional grid of them, so I bought the LD788BS-SS22 8x8 LED dot matrix display from Jameco to tinker with.

Most of the circuits I've seen online use the 74HC595 Shift Register with this type of display. As I had forgotten to include one in my order, it occurred to me that it might be possible to drive it using the ubiquitous 4017 Decade Counter instead, since I had a few of them lying around. I've seen several electronics kits that use this inexpensive chip for coin toss, knight rider, roulette and other applications where only one of up to ten outputs is active at any given time. With only eight rows needing to be selected individually, I wanted to see if it was possible to drive this display in multiplex fashion. The only concern was whether it could operate at a high enough refresh rate to overcome flicker. The datasheet indicated it could operate into the megahertz range - well beyond what I needed it for. So I got started wiring-up everything as shown in the schematic on the right.

On the 4017, decoded outputs (not the pins themselves) #1-8 are connected through 10K resistors to the bases of eight NPN transistors, which are configured for switching the cathode pins (rows) on the dot matrix display to ground. The eight column pins connect to the Uno's digital pins via 220 Ohm current-limiting resistors. After eight columns have been scanned, the Clock line is pulsed to advance to the next row. After the eighth row has been scanned, the Reset line is pulsed to return to the top row and repeat the cycle again. The concept is similar to raster scanning and flyback in a cathode ray tube (CRT) display. So for this implementation, only ten Arduino digital lines are used. Project schematic and source code are provided here freely for non-commercial use.

LED Matrix Banner

To test functionality of the hardware, I wrote the following sketch to scroll a banner message across the display. Simply copy and paste the code into the Arduino IDE, customize the three user-defined constants for banner message, end-of-message pause time and scroll speed as desired. Then compile (no libraries or header files are needed). Feel free to send me email if you have any questions, tips or other feedback.

Select code:


Update for June 25, 2012:

Since I ultimately plan to migrate the layout onto a home-made shield, and since space would be severely cramped with only 30 columns on the board, today I replaced the eight transistors and 10K resistors with a single 2803 Darlington Array IC. Much more compact and tidy! At just 79¢ each for the chip, it wasn't a budget-buster, either. Below is a photo of the updated breadboard layout.

 
Update for June 27, 2012:

I started working on creating a permanent shield for the design last night and finished it today. A piece of used protoboard from another "retired" project was cut to size and, together with a right-angle header, props-up the display for viewing from a horizontal direction. Besides esthetics, the smaller footprint for the interface with the main board allowed more space for wiring and the other components.

In another fortuitous coincidence, the pins for the decoded outputs being used on the 4017 are almost exclusively on one side, and I exploited this feature by aligning traces between it and the 2803 as much as possible - so only one wire needed to be routed separately between the two. This is why the two chips are both oriented in reverse directions. This also meant their order would be thrown out of sequence, but I realized there was no point in maintaining it since it would be "scrambled" eventually anyway, once reaching the arbitrary (from a user's perspective, at least) pinouts of the LED matrix - so I just made a chart on paper to keep track of it all.

Below are a few photos of the completed shield.

Audio Spectrum Analyzer

Added June 30, 2012:
Members of the Arduino community have contributed code which I have adapted to turn the display into a crude Audio Spectrum Analyzer. The included sketch is based on a Fast Fourier Transform (FFT) library which uses integer math for optimal processing speed. It's not scientific or anything... but who doesn't like to watch bouncing lights?
Select code:

Breakout Clone

Added July 8, 2012
Updated July 12, 2012
Like most households, we have at least one video game console - two, in our case. My son uses an Xbox 360, while the more humble Nintendo Wii has been relegated mainly for my (very) occasional workout with Wii Fit. I can't speak for others, but the Nunchuk controller which comes with it has seen very little use, compared to its wireless counterpart. Well, it looks like that might be about to change since I recently picked-up the WiiChuck Adaptor from DFRobot. For those who haven't seen it, it's a small PCB with contacts that slip into the controller, exposing the Data, Clock, Power and Ground lines. Since the Nunchuk supports the I2C protocol, that means it can be exploited for other uses.

Initially, the adaptor was plugged-into a small breadboard with jumper wires leading to the Arduino. However, I came across a tip for a different breakout board that had two of the analog pins configured for output, with one set HIGH and the other LOW so they could deliver power to that board. I figured, if it works for that board, maybe it could work for this one as well. Sure enough, it did and updated pictures are posted here to prove it.

Okay, I prefaced this piece by insinuating I'm not much of a gamer... but having grown up in the 70's and 80's, I've always been a fan of old school video games which, admittedly, don't hold a candle to what's available now. Still, I've probably got a copy of Breakout, Arkanoid, Krakout or other such "break-the-blocks" variant for every computer or gaming system I've owned. So you'll probably understand why I was compelled to throw something together to utilize the newfound capability.

The result is my humble stripped-down interpretation of the classic that you see here. There are nine levels of increasing difficulty, with rows of blocks being added along the way as well. Pressing the "Z" button pauses or unpauses the game. Pressing "C" switches between the joystick and the accelerometer. Pressing both buttons simultaneously restarts the game. Pass all nine levels to receive a congratulatory message. There are unlimited lives in this version, so take all the time you need to practice.

Select code:


8x8 RGB Dot Matrix Display


Added July 19, 2012
Updated July 22, 2012
It was a lot of fun building and using the 8x8 red dot matrix display, but the nagging urge to move up to the RGB world proved too much... so I finally splurged and bought one this week.

Having a total of 192 LEDs built-into it, current consumption was a primary concern. I built several prototypes, all using the 74HC595 Shift Register IC to sink the red, green and blue cathode columns. For sourcing power to the common anode rows, I tried both the 595 and the 4017 Decade Counter IC and ended up having better results using the latter. Both chips were configured to multiplex the display by cycling from one row to the next, but the 595 seemed to be somewhat more susceptible to flicker - presumably because each redraw of the display required sending 32 bits of data. Using the 4017, only 24 bits need to be sent, with a simple toggling of the clock line to advance to the next row.

For the application of driving LEDs, both chips are hindered by the limitation of sourcing only about 35mA, which in testing resulted in whites turning pinkish as more LEDs on a given row were switched on. To eliminate that problem, I changed the code to update rows on a pixel-by-pixel basis. This solved the problem of "current-hogging", but also introduced annoying flicker - even with no delay() function calls anywhere in the sketch. After streamling the code as much as possible to remove any bottlenecks, it occurred to me that if two pixels (6 LEDs max) could be sourced without adversely affecting the color balance, I could cut the number of redraws in half by evaluating and rendering two pixels at a time - so for a given row of eight pixels, the shiftOut function would be called just four times. Sure enough, it worked like a charm and there is no longer any perceptible flicker (to my eyes, at least ).

I also tinkered with various techniques to allow more than the standard eight colors to be displayed simultaneously, and was able to obtain best results by using two RGB frame buffers, so as to extend or contract the duty cycle for a given primary color or combination thereof. It's a crude implementation of pulse width modulation, but it yielded six additional colors (13 if you count the darker versions of the first seven ). The table below summarizes the idea behind this implementation:

Component
Colors
Mixed Color
                                       
Cycle 1
Red                    
Green                    
Blue                    
Cycle 2
Red                    
Green                    
Blue                    

I had to set my camera to "sunset" mode, which is why the pictures in the animation on the right look so dark - it was a tradeoff between being able to see the display or seeing anything else. Still, the images posted here don't begin to convey the brightness and clarity seen from a first-person perspective. As far as current draw goes, hooking-up the multimeter to the breadboard showed an impressively meager draw of just 16mA, which is a testament to improvements in the efficiency of newer LEDs. If there's anything to complain about, it's that now I'll have to figure out how to fab a board for a permanent shield.... well, that's for another day.







One-Digit Clock


Added June 20, 2012
This was the second shield I built. I had a 7-segment display laying around and wanted to make use of it... so I thought, why not make a clock with just one digit? Well, the hardware was super easy - after all, it's just one digit and a couple pushbuttons. The simplicity of the hardware was offset by increased complexity on the software side, though, which wasn't at all fun to write. It basically just cycles between displaying digits for the hours and minutes, one at a time. A decimal point appears with the ones digit for the hours - a sort of pseudo-colon to help distinguish hours from minutes, since that's the only extraneous indicator we have to work with, other than the segments comprising the digits themselves.

The finished product was something only a true geek could appreciate, and I'm sure a patent for it still doesn't exist... so what are you waiting for! Anyway, there's not much else to say about it besides how to set it up and use it, which is covered toward the top of the included source code:

Select code:



Four-Digit Clock


Added July 3, 2012
The idea for this clock came somewhat by accident... okay, partially by accident, coupled with curiosity. My son is a teenager now, and with his kind permission I was rummaging through his old toy box in search of a ping pong ball that I wanted to convert into a lampshade for an RGB LED. Well, I never found the ping pong ball, but I did find his old SpongeBob SquarePants alarm clock. It looked like the photo seen to the right, except poor SpongeBob had broken off the top and had gone missing. This also left the top of the enclosure partially exposed. Being the good parent that I am , I couldn't allow the clock to be used again at the risk of electric shock, so I promptly confiscated it. Also not wanting to contribute to e-Waste, I figured why not take it apart (since it was partly disassembled anyway) and see if I could re-use the display?

As I pondered how I might be able to access the pins for the display, I figured anything I did would probably butcher it pretty badly and render the display unusable. But if all failed, there wouldn't really be any monetary loss, so I approached the task casually. I used wire cutters to cut along the base of the ribbon cable connecting to the PCB until it was removed, then snipped along the edge of the ribbon until the lengths were reasonably even. To expose the wires, I cut about 1/8" into the insulation running between each lead, bent each slightly away from the others and removed the insulation with a wire stripper. To my surprise, I was actually able to successfully expose all 30 pins without damaging any of them!

To interface the display with the breadboard, I knew that if I tried inserting the pins directly, one or more of them would undoubtedly get bent. It brought me back to the days when I had a 80286 PC that used SIPP memory, before SIMMs overtook the market in prominence - but I digress. Unfortunately, I didn't have any SIPP sockets to use for this project... so I improvised by lining-up several machined DIP sockets and inserted the pins through one side. Counting just one side, 9+9+8+4 totalled exactly the 30 pin wells needed. Any amount over 30 would have worked, of course, but this just made for a neater appearance. With the help of a small flat-tipped screwdriver, good eyeglasses and a bit of patience, I gently eased all the pins into their corresponding wells.

I searched the net for a datasheet for this SB6052N display, which only turned up a couple crude drawings that showed it using two cathodes, but made no mention of pinouts. So I grabbed pen, paper, 9-Volt battery and 1K resistor and embarked on the task of mapping all the supported segments. Below is a summary of my findings:

Pin #:1256910121315161718192021262930
K1 Segment:K1 PM E2G2D2F2A3B3C3E4G4D4F4 K1:
K2 Segment: K2 B1C1B2C2A2F3G3D3E3B4C4A4K2  

A little explanation is probably in order: To conserve the number of lines required to drive this display, the manufacturer engineered it to use two cathodes. Cycling between them at a refresh rate high enough to overcome flicker allows the display to be viewable as a continuous image, and is a commonly-employed technique for LED clocks (aka. "multiplexing"). For the above chart, K1 and K2 represent the cathodes for each duty cycle. Note that connections have been provided at or near each end of the pinouts - obviously to allow more flexibility in interfacing with other hardware components. As this display uses four digits, I've numbered them from left to right. So as an example in the chart above, "E4" would represent the "e" segment of the fourth digit (ones column of minutes), using standard "a" through "g" references typical for 7-segment displays (a diagram is shown above in the previous project).

I had followed the helpful ShiftOut Tutorial on the Arduino web site, and happened to have a couple shift registers on hand, which I intended to use to drive this display. The 74HC595 IC is often overlooked for directly driving LEDs because they typically don't provide enough current, but I specifically chose the ones I'm using since the datasheet for this part quotes a source or drain of up to 25 mA. Using a 330-Ohm resistor in series with each cathode results in ample brightness, with a drain of just 9 mA per cathode - well within specifications.

The rest of the connections were made in a process of stepwise refinements: First by using two Arduino digital pins to control the cathodes via transistors by switching them to ground. Then it occurred to me that only 14 of the 16 combined bits from the shift registers were being utilized - so I routed them to the transistors and used them instead, thereby conserving a couple Arduino pins. The last refinement was to do away with the transistors completely and drive the cathodes straight from the shift register pins, which is the wiring configuration shown in the photos on the right.

After completing the hardware side of things, the next obvious step would be to write software for a clock, which I completed this morning. The sketch is provided here freely for non-commercial use. With digital clocks, some people don't mind a blinking colon between the hours and minutes, whereas others find them to be annoying. To please everyone, a boolean flag has been added toward the top of the source code to enable or disable this feature. I would have liked to add support for 24-hour time, but unfortunately this display is hard-wired only for segments "b" and "c" in the tens column for hours - so it can only display the number "1". Two momentary pushbuttons have been added to the circuit, as can be seen in the photos on the right. These are used to set the time. When not in time-set mode, the button normally used to increment the selected digit instead toggles between displaying hours and minutes, or only seconds.

As for my son, I bought him another alarm clock to rid my guilt for taking his. The new one is also more appropriate for his age.

Update for July 16, 2012:

Today I created a permanent shield for the clock. The layout is nearly identical to that of the breadboard; the main exception being removal of the pull-down resistors previously used with the switches - I had read a tip that you can avoid using them if you reconfigure the switches as shunts to ground and set the state of the associated input pin to HIGH in your setup procedure. This allows one to exploit the 20K pull-up resistors that are built-into each of the available Atmel MCU pins. The button state would then be read in reverse: HIGH would mean the switch is open and LOW would mean it is closed. As you can see from the photos on the right, space was severely limited, so even the prospect of leaving out two resistors was worth the slight tweaking of code to align the software with the hardware.

Select code:







Ping Pong Ball Used as an LED Lampshade


Added July 12, 2012
I thought I had an original idea about using a ping pong ball as a lampshade for an LED... turns out through a quick web search that not only was this thought of before, but it was even a trend that spiked and faded about four years ago. Well, better late than never, right? One frequent topic of discussion was how to best diffuse the light, since white LEDs are often produced in "water clear" epoxy, have a relatively narrow field of focus and therefore usually leave a distinct bright spot on any nearby object. I've found a good degree of success toward eliminating this problem by doing the following:
  • Scuffed the exterior of the LED epoxy. In my case I would have used sandpaper, but couldn't find any - so I used a file instead.
  • Used a light diffuser cap that came with another LED. This is the type of part that snaps-into a hole drilled into a cabinet or project enclosure. It didn't completely eliminate the problem, but it helped.
  • Before covering the LED with the diffuser cap, I took a piece of Scotch Transparent tape, then folded it over so the sticky sides were pressed against each other. Then punched a hole in the tape. The circular-shaped piece that would ordinarily be discarded was then pressed into the diffuser before covering the LED with it. The idea behind this step is that the transparent tape is rough on the exterior edges and helps to further scatter the light, without unduly blocking it.
  • Took about six inches of insulated solid core 24 AWG wire and formed a ring to both elevate and support the ping pong ball. I've found that best lighting results are obtained by raising the ball just enough so the bottom edge of the LED (where the leads meet the epoxy) is flush with the hole. This allows the majority of its light to be scattered within the enclosure. If the LED is elevated much beyond this point, there is little to no improvement in the lighting characteristics, while the chances for a bright spot only increase as the top of the LED gets nearer to the inside surface of the ball.

It may also be of benefit to check the operational characteristics of the LED being used and bias it accordingly. This may sound like common sense, but the voltage drop for one part versus another - even for the same color LED, may vary considerably. This has implications for the current running through the LED, and overall brightness. A resistor value that allows too much current through the LED may not only exacerbate the problem of bright spot, but possibly shorten the lifespan if not destroy the LED. Too little current may leave the ball darker and make it tempting to lower the ball or raise the LED... which ironically could still increase the chance for bright spot. In the case of the LED used for this test, it has a voltage drop of just over two Volts and is rated for operation at up to 30 mA. Since it will be driven using a 5-Volt supply, a 150-Ohm resistor has been chosen: 5 Volts supply - 2 Volts dropped = 3 Volts ÷ 150 Ohms = 20 mA... a conservative current drain, with enough "oomph" to provide ample lighting.

Breathing LED

The following sketch lights an LED to full brightness and back down to completely dark, pauses, then repeats. The way in which it does this makes it look like the LED is "breathing." The behavior of LEDs, both electrically as well as optically, is very non-linear. In fact, when using a PWM value of just 10% of the entire range, an LED may have already achieved 90% of its peak brightness. For this reason, I chose the Sine function and while it doesn't completely mitigate the problem, it goes a long way and is extremely simple to code. The graphs on the right illustrate both linear and logarithmic curves, which were generated by pointing a photoresistor directly at an LED and sampling the values obtained from the Arduino ADC converter.

Select code:



Halloween Jack-O-Lantern with Animated Eyes


Added November 17, 2014

I know it's been a long time since the last Arduino update. I have to admit that from about mid-2013 onward, I've been tinkering with the Raspberry Pi and kind of went on an Arduino hiatus as a result. R-Pi topics are covered in great detail in the Raspberry Pi Forums and via The MagPi online fanzine, so anything I could write here wouldn't do it proper justice.

I got back into the Arduino "groove" by deciding to use a couple Adafruit 8x8 LED matrices with backpacks that would serve as animated eyes for a Halloween Jack-O-Lantern. The first animation was a series of five "frames", with the eyes looking toward the left, left-center, center, center-right, right and then back toward the other direction.

I used the Adafruit Trinket for this task, and the sketch was just able to fit within the meager memory constraints of the device. On the last day, I wanted to add random eye-blinking to the animation sequence, but this compiled to 7K, which was about 2K too big, so I switched to the OSEPP Pro Mini, with plenty of "room to breathe" at 32K available. Utilizing I2C, the LED backpacks reduced the required pin count to just four (Ground, VCC, Clock and Data), making wiring a breeze. Since the eyes naturally "looked" in the same direction, it was a simple matter to just wire them in parallel.



3x3 LED Cube


Added November 17, 2014

After fairly decent results with the Jack-O-Lantern, I started thinking about making something for the upcoming holidays. The LED cube seemed like something neat to try. I'd seen the Velleman MK193 LED Cube Kit at Fry's, but couldn't justify spending over $30 for what is mostly just 27 LEDS, a stand and a few other components. Since I had all the parts except for the LEDs themselves, I decided to drop $8 for a 25-pack of LEDs and do the rest on three mini breadboards snapped alongside each other.

A quick Web search showed several designs and layouts, most of which involve nine "columns" and three "levels" – for a total of 12 microcontroller pins. Each pin can source or drain 40 mA. Since each column can have up to three LEDs lit simultaneously, I set the resistor value to 220 Ohms (5 Volts - 2 LED Forward Voltage Drop) ÷ (40 mA ÷ 3). Any lower value of resistor would allow an uneven amount of current to flow if only one or two LEDs in a column were lit, and possibly lead to flickering.

Since up to nine LEDs could be lit simultaneously on any level, the maximum current needed to be drained is 9 x 13.6 mA = 122 mA, which exceeds the 40 mA limit for the microcontroller. For this reason, I used three NPN transistors for switching each of level of LED Cathodes to ground. I used 2N3904s because I had them in my parts box, but 4401s or 2222s would work just as well.

Most wiring schemes have the pins grouped with pins controlling the columns at one end and the rows at the other end. I decided to lay out the wires and transistors in the most space-efficient manner I could envision. In software, the pins are mapped virtually using one array for the columns and another for the rows, so there wasn't much of a complexity hit by doing it this way.