Product Review: Charlieplexed SparkFun 8×7 LED Array

abccharlieplexedledsanimatedI recently picked up the new SparkFun LED Array – 8×7 to try out some hardcore charlieplexing, and so far it’s been working great.

Quoting Wikipedia, charlieplexing is

“…a technique for driving a multiplexed display in which relatively few I/O pins on a microcontroller are used to drive an array of LEDs. The method uses the tri-state logic capabilities of microcontrollers in order to gain efficiency over traditional multiplexing.”

Charlieplexing itself is a simple idea and can be an extremely efficient way of making an LED grid. However, laying out the wiring of a charlieplexed grid, whether on a breadboard or a PCB, can be complicated and require a bit of thinking. It’s easy to layout a grid with 12 or 20 LEDs, but once you start trying to make grids with 30 or more LEDs, it gets a little crazy.

I love SparkFun’s 8×7 LED Array because it eliminates the need to go through the long process of designing and wiring together the grid. Plus it’s in a neat compact module that can be easily embedded. Out of the box, all I had to do was solder on headers and plug it directly into the digital pins on my Arduino. I didn’t need to wire any external resistors, as they’re already built into the board.100_5200

SparkFun has made an Arduino library for controlling the array that allows you to easily write text and draw shapes and do other interesting things on the grid. However, I wanted to use my array with my Raspberry Pi’s GPIO for the purpose of making an archaic internet-connected game system. I’ve written a single-file class in Python 3 for controlling the array with the Raspberry Pi’s GPIO, called pythonic-charlie, and you can find it here (my first legit GitHub repo! Woot woot!). It’s still under development, and still has bugs that need smoothing, but it allows you to display a list of coordinates, test the grid to verify that it’s wired properly, and display a neat little screensaver. I’m currently working on something that will display text. example-wiring

If you ever wanted to learn how to charlieplex LEDs, SparkFun’s 8×7 LED Array is a really great place to start.


Happy Arduino Day 2016 + Testing a Power Relay

Happy Arduino/Genuino Day 2016!

arduino uno pic

Take some time today to do a little project with your Arduino!

Testing a Power Relay

My tech savvy grandma recently got me a very nice IoT power relay! I spent a while testing it out by making a simple system to automatically turn my desk light and my Pi monitor on or off. I hooked an SR-04 ultrasonic sensor to my Arduino Uno and wrote a sketch to have it detect when my hulking mass is close to my desk and send a signal to turn the relay on or off.

power relay hooked up
This is my power relay setup connected to an Arduino and ultrasonic sensor. I taped the ultrasonic sensor down to keep it from wiggling about. The Arduino is being powered by a USB port on my Pi 2.

The most challenging part of creating this little system was getting accurate readings from the ultrasonic sensor. They can read inaccurately if objects are moving around in front of the sensor, and the light would flicker annoyingly if I moved too quickly. I figured out how to smooth the value by reading from the sensor 30 times in 1.5 seconds, and then taking the average of all 30 values.

The power relay works great. It required no setup out of box, and it’s simple to connect your controller. Its only disadvantage is that it doesn’t have an ‘always-on’ power source, which requires you to have an external power source for the device controlling the relay.

iot power relay
This is the power relay I tested.

Check out the sketch I wrote for this project below, or click here to download.


Using an Arduino with a Power Relay

Parts used:
--ultrasonic sensor
--desk lamp
--Arduino Uno
--120v relay

This sketch uses an ultrasonic sensor to detect whether
a person in near or sitting at a desk, and sends a 
signal to a power relay to turn desk lighting on or off.


#include <NewPing.h>

const int LIGHT = 10;
const int TRIGGER = 12;
const int ECHO = 11;

NewPing sonar(TRIGGER, ECHO);

void setup(){
  pinMode(LIGHT, OUTPUT); 

/* The main loop iterates every 2.5 seconds. */

void loop(){
  /*In order to get a accurate measure of whether
  someone is near, we read the ultrasonic sensor
  30 times and take the average. That way, if the
  ultrasonic sensor reads sporadically as it 
  occasionally does, those values will be averaged out.  
  This takes 0.05 * 30 = 1.5 seconds to get a value
  from the sensor. */
  while (int i, i < 30, i++){
    sum = sum + sonar.ping_cm();
  int average_distance = sum/30; 
  /* Using the value, we send a signal to the relay
  depending on whether someone is detected less than 
  130 cm away. We also pause for a second for good 
  measure. */
  if (average_distance < 130){
    digitalWrite(LIGHT, HIGH);
    digitalWrite(LIGHT, LOW);

How to Use Ultrasonic Sensors with the Arduino

I’ve made my first video tutorial! I obtained some SR-04 ultrasonic sensors quite cheaply, and I’ve been learning how to use them with the Arduino, with good results. I’ve created a tutorial covering how to get the proper libraries and how to use the basic functions in the Arduino IDE to interface with the sensor.

Here’s the steps (covered in the video) on how to get NewPing, a library created for controlling ultrasonic sensors, up and running with the Arduino IDE:

  1. Use this link to download the NewPing Library:
  2. Click “Download NewPink v1.7” and save the .zip file.
  3. Open the Arduino IDE, and go to ‘Sketch>Include Library>Add .ZIP Library’ and then navigate to where you saved the .zip download, and click ‘open.’
  4. Go to ‘Sketch>Include Library’ again and scroll all the way down to the bottom and select NewPing.
  5. The NewPing library will now be included in your sketch.
  6. For some sample sketches and documentation of NewPing, look here:!syntax.

For code sample written in the tutorial, click here.

P.S. – Yesterday was the first anniversary of this blog (this is my 48th post)! 😀

ultrasonic sensor schematic

Mouse Emulation With an Analog Joystick and Arduino

another view of arduino joystick circuitMy latest mini-project has been hooking an analog joystick up to an Arduino to make my own joystick computer mouse…plus I have some news… my soldering iron

I got a soldering iron for Christmas! YAY! I desoldered an analog joystick from an old PlayStation 2 controller (see my Tear Down from a while back), and bought a joystick breakout board from SparkFun so I could fit the joystick into a breadboard. I originally made my own breakout board using a PCB etching kit, but it just got messy and I decided to save myself the hassle and just buy one.

This is the breakout board I was making for the joystick. It didn't come out too good.
This is the breakout board I was making for the joystick. It didn’t come out too good, as I drilled the holes too big and the solder ran through.

I practiced using my soldering iron quite a bit over the holidays and I feel like I’m finally getting the hang of it! I soldered the joystick along with some old headers from a furnace board without a hitch!

arduino joystick breakout with controller pad
This is the finished analog joystick soldered to the breakout board.

I then wired it up on the breadboard, along with my Arduino Micro (which can emulate a mouse and keyboard, unlike most of the other Arduino boards), an LED indicator light, a toggle switch, and two pushbuttons to act as right and left click mouse buttons. The toggle switch shuts the mouse on and off, and the LED indicates if it’s on or off. I tested it out on my laptop and my Raspberry Pi, and it works great! Certainly it’s more interesting to use a joystick than a regular mouse!

arduino joystick mouse final circuit
This is the finished circuit.

Check out the software on GitHub Gist here. I had some help from the Arduino website, as well as from Jeremy Blum’s excellent book Exploring Arduino.

Breadboard schematic of circuit.

Candle Snuffer with Arduino and 9V Battery

another side view of snuffer

Having the urge to make a ‘pointless invention’,  I made a candle snuffer from a DC motor off an old helicopter, a 9V battery, and Erector set pieces. Basically, a fan blade attached to the motor and wired to a pushbutton sends a sufficient gust of air to blow out the flame of a small candle. I made two different versions of the snuffer, one with a only a 9V battery and one with an Arduino powered of a 9V battery, with the motor connected to 9V.

The snuffer basically has a little tray for a candle, with a fan pointed down at the top of the candle. A breadboard is mounted upright on the side, and the 9V battery is stowed under the tray. Below is a view of the whole thing lying on it’s side without the candlelaying flat

Arduino Micro Candle Snuffer

When I first got the idea for a candle snuffer, I immediately thought using the Arduino Micro with a fan and allowing for time delays, temperature sensing for ‘overheat’ shutoff, and a photoresistor to detect if the candle is lit or not. The first thing I made was the breadboard mount and the candle tray out of Erector set pieces, and then I attempted to add the photoresistor, near the candle. However the heat from the candle would have likely damaged the photoresistor.

Getting the motor to spin fast enough to blow out the candle flame was a challenge with Arduino due to power constraints and transistor problems. I first tried direct drive off an Arduino pin’s 5V, but that did not make the motor spin nearly fast enough. Then I tried driving the motor with 9V via PNP transistor controlled by the Arduino, which, after a couple transistor overheats, still did not allow the motor to spin fast enough maybe due to voltage drops and such. My final version uses a 5V relay which seems to work really well. The fan spins more than fast enough using the relay. I’m not a huge fan (no pun intended) of relays because they can be difficult to wire and take up a lot of space on the breadboard. I had to tape my relay in place with my bright yellow electrical tape to keep it from popping out.arduino_candle snuffer wiring

Because of all the frustration with driving the tiny little fan motor, I didn’t do much with the Arduino software side of things. You can check out the code I used here, which basically sends a gust of air at the candle flame when the button is held down. I didn’t add a time-delay or other sensing capabilities yet, though I may not because this is kind of already a benched project.

In my wiring, the 9V battery is connected to the Arduino’s Vin pin, and its ground is tethered to the Arduino’s ground. The relay turns on and off when it gets a signal from the Arduino. The fan runs off of the Arduino’s constant 5V pin. I’m not sure how this differs from direct motor drive from a pin, but the fan spins moves much faster.

Candle Snuffer Powered Off of 9V

Halfway through building the Arduino Micro version, I tore it all up and resorted to a pushbutton wired between 9V and the motor. When you press the button, the fan comes on and blows out the candle. I did look into using a 555 timer IC to try and create a 30 minute time delay until the candle is snuffed, but that ended up being a little complicated since I don’t have all the capacitor values. Ironically, this version of the candle snuffer does exactly the same thing as the Arduino Micro version.

The schematic is below. It’s quite simple.

9v circuitpic candle snuffer
side view of snuffer

Oscillating Fan with Arduino – Part 2

Oscillating fan with micro the whle thingI’ve finished up my oscillating fan! My final design changed significantly though due to some technical difficulties. In the end I opted to use the Arduino Micro because it was the right size for this smaller project. Unable to obtain a 9v battery, I used 4 AA batteries, which barely power the Arduino and the fan. I was originally was going to use a temperature sensor with temperature indicator LEDs, but my temperature sensor was behave erratically. Sadly, I may have fried it at some point. Instead, I used two potentiometers, one controlling the fan speed, and one controlling the oscillation speed, and they work quite nicely. Using Erector set pieces, I made a tray for the breadboad it taped to the battery pack. I used more pieces to mount the fan and support the breadboard, and the final project is nice and compact.

Oscillating fan with micro side view

To view code, click here.diagram of the Oscillating fanIf you build a project like this, with external power, you have to be careful of which rail has which power connection. In this project, I had one rail on 6v (the battery) and one on 5v (the Arduino’s logic voltage). If you draw from the 6v to power the potentiometers or other sensors, you could damage your Arduino. It’s also important to remember to connect the Arduino’s and the batteries’ ground together.

Below is the fan mounted to the servo using Erector set pieces.

Oscillating fan with micro fan construct