Introduction: 8-LED Larson Scanner With Arduino

About: I'm a U.S. Marine stationed in southern California. In the boredom of my off-hours, I tinker around with simple electronics and look for ways to improve my home. I love Instructables!
This is a simple way to make a Larson Scanner using an Arduino, with the added capability of setting the scanning rate with a potentiometer.

Minimum parts list:

(1)  Arduino Duemilanove (or equivalent / compatible)
(8)  LED's of your choice. I used 5mm T1-3/4 120-180 degree water clean 1500mcd pure green LCD's.
(8)  100ohm 1/8 watt (minimum) resistors. I used (4) 330ohm 1/4 watt, and (4) 450 ohm 1/4 watt, just because that's what I had lying around. I see no difference in brightness between the two.
(1)  10k potentiometer of your choice.
(1)  project breadboard, solderless "push-in" style.
(11)  4 inch lengths of hookup wire , preferrably solid core with tinned tips. Stranded wire will work, but is just more annoying. I used pre-assembled breadboardinging wires that came in a kit.



I did not write the sketch personally, but rather modified someone else's to fit my needs. It includes the ability to add a button, which I don't use.
The sketch for the Arduino is as follows:

const int buttonPin = 2;
const int ledPin1 = 13;
int buttonState = 0;

int leds[] = {3, 4, 6, 7, 8, 9, 10, 11};
#define NUMBER_OF_LEDS (sizeof(leds)/sizeof(int))

boolean larson[][NUMBER_OF_LEDS] = {
{ HIGH, LOW, LOW, LOW, LOW, LOW, LOW, LOW},
{ LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW},
{ LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW},
{ LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW},
{ LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW},
{ LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW},
{ LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW},
{ LOW, LOW, LOW, LOW, LOW, LOW, LOW, HIGH},
{ LOW, LOW, LOW, LOW, LOW, LOW, HIGH, LOW},
{ LOW, LOW, LOW, LOW, LOW, HIGH, LOW, LOW},
{ LOW, LOW, LOW, LOW, HIGH, LOW, LOW, LOW},
{ LOW, LOW, LOW, HIGH, LOW, LOW, LOW, LOW},
{ LOW, LOW, HIGH, LOW, LOW, LOW, LOW, LOW},
{ LOW, HIGH, LOW, LOW, LOW, LOW, LOW, LOW},
};

#define FRAMES (sizeof(larson)/(sizeof(larson[0])))


int sensorPin = 0;

void setup() {
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin, INPUT);
for (int led=0; led<NUMBER_OF_LEDS; led++) {
pinMode(leds[led], OUTPUT);
}
}

void loop(){

buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(ledPin1, HIGH);
}
else {

long time = millis();

for (int frame=0; frame<FRAMES; frame++) {
for (int led=0; led<NUMBER_OF_LEDS; led++) {
digitalWrite(leds[led], larson[frame][led]);
}
int sensorValue = map(analogRead(sensorPin), 0, 1023, 0, 1000);
while (sensorValue >= (millis() - time)) {
sensorValue = analogRead(sensorPin);
}
time = millis();
}
}

}