The Cylonduino, or, my first Arduino Experiement


I've been putting in a lot of extra hours at work the last week in anticipation of an editing deadline. Despite this, I thought it was about time that I attempt a little hardware hacking. Even before computers, I was facinated by electronics. I read book after book, but had little success in applying any of that knowledge beyond kits bought from Radio Shack. Given my recently revived interest in Ham Radio, it was only a matter of time before I'd turn my attention back to this, my oldest of hobbies.

A little about Microcontrollers...

Microcontrollers have recently become surprisingly affordable. It used to be that a microcontrollers, or "BASIC Stamps" as one early product line called itself, that you needed expensive programmer boards and in some cases, knowledge of assembly. Today's microcontrollers are much, much simplier. Beyond a computer and a USB cable, you really don't need much to start experimenting.

When I first looked into buying one, two brands immediately came to mind, the Parallax Quickstart and the Arduino. I've heard of the Parallax before. That esoteric little board is based on a "barrel processor", with 8 independant cores and one shared bus. It's interesting approach certainly captured my interest, but the complexity kept me from investing. Programming the Parallax board requires some finesse, and is probably not the best idea if you haven't any previous hands-on microcontroller experience. The Arduino, on the other hand, is a lot more straightforward.

The Arduino Uno a single core system running at 16Mhz with 32K of on board memory. You can purchase it online from a variety of vendors (although I'm fond of female-led Adafruit), or your local Radio Shack. Yes, Radio Shack. Apparently they got the idea that people still like buying parts and kits. While no Fry's Electronics, Radio Shack has a respectable little section of toys, including the Arduino. The Arduino is agressively open source -- both the hardware and the IDE are open source. The latter even is available on multiple platforms, Linux included (yay!). 

Working with the Arduino platform is a joy. The code is simple, and has plentiful examples. If you're familiar with C, C++, Java, PHP, or languages with similar syntax, you'll be right at home. The code isn't a "real" programming language, but closer to a script. The IDE transforms your code into C prior to compiling and uploading to your microcontroller. Uploading is also joyously simple: Connect USB, install a driver, and you're good. Once set up for the first time, you only need to connect and hit "Upload" on the IDE. 

About the Cylonduino

One of the first things I wanted to do was build a Cylon, or Knightrider-esque LED scanner. The lights blink on in sequence from one side to the other, and then back again. The circuit is pretty simple and is based on a modification of the Bargraph Example.

Hardware Required

Arduino board
(10) LEDs, any color
(10) 220Ω resistors
100kΩ potentiometer
hook up wire

I had a Radio Shack Electronics Learning Lab available, so I used that for all parts.


Here's the Breadboard layout, generated in Fritzing.

The circuit diagram is equally simple:

The Code

const int ledCount = 10;    // the number of LEDs in the bar graph

int ledPins[] = { 
  2, 3, 4, 5, 6, 7,8,9,10,11 };   // an array of pin numbers to which LEDs are attached

int ledLevel = 0;
int whichWay = 1;

void setup() {
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed = ledCount){
    digitalWrite(ledPins[8], LOW);
    whichWay = -1;
    ledLevel -= 2;
  else if(ledLevel = 0){
    digitalWrite(ledPins[ledLevel - whichWay], LOW);
  digitalWrite(ledPins[ledLevel], HIGH);
  ledLevel += whichWay;