As an Amazon Associate we earn from qualifying purchases.
A chaser is a circuit that switches lights on and off in a repeating sequence so they seem to run along a line. You see them on festival lighting, signboards and decorative strings. This project is an automatic chaser built around the MSP430G2553 microcontroller. A single potentiometer sets the speed, so you can slow the pattern down or speed it up without touching the code.
What this automatic chaser does
The program drives two output pins, P1_6 and P1_7, and runs two patterns one after the other:
- Alternating pattern: the two outputs swap places. One is on while the other is off, then they reverse.
- Flashing pattern: both outputs turn on together, then both turn off together.
After the second pattern, both outputs stay off for 2 seconds, and the whole cycle starts again. The speed of both patterns comes from one analog input, A3, which is where you connect the wiper of the pot.
What you need
- An MSP430G2553 microcontroller, on a LaunchPad board or your own circuit.
- A potentiometer, with its outer legs connected to the supply and ground and its middle leg (the wiper) to A3.
- Two outputs to switch: LEDs with series resistors for a first test, or driver stages for bigger loads.
- The Energia environment (Arduino-style) to compile and upload the sketch. The pin names such as P1_6 and the A3 analog name follow Energia’s conventions.
The code
This is the original sketch for the MSP430G2553:
int b;
void setup() {
pinMode(P1_6, OUTPUT);
pinMode(P1_7, OUTPUT);
}
void loop() {
b=10000/(analogRead(A3)+1);
for(int a=0;a<b;a++)
{
b=10000/(analogRead(A3)+1);
digitalWrite(P1_6, HIGH); digitalWrite(P1_7, LOW);
delay(b);
digitalWrite(P1_6, LOW); digitalWrite(P1_7, HIGH);
delay(b);
}
b=10000/(analogRead(A3)+1);
for(int a=0;a<b;a++)
{
b=10000/(analogRead(A3)+1);
digitalWrite(P1_6, HIGH); digitalWrite(P1_7, HIGH);
delay(b);
digitalWrite(P1_6, LOW); digitalWrite(P1_7,LOW);
delay(b);
}
digitalWrite(P1_6, LOW); digitalWrite(P1_7, LOW);
delay(2000);
}
How the speed control works
The key line is this one:
b = 10000 / (analogRead(A3) + 1);
The MSP430G2553 has a 10-bit ADC, so analogRead returns a number from 0 to 1023 depending on the pot position. The code adds 1 so it never divides by zero, then divides 10000 by the result. The answer, b, is the delay in milliseconds used between each change of the outputs.
- Pot at the low end (reading 0): b = 10000, so each step lasts about 10 seconds. This is the slowest setting.
- Pot near the middle (reading about 511): b = 19, so each step lasts about 19 ms.
- Pot at the high end (reading 1023): b = 9, so each step lasts about 9 ms. This is the fastest setting.
Because the calculation is an inverse, the response is not linear. Most of the visible slow-to-fast change happens in the first part of the pot’s travel, and the upper half changes the speed very little. A logarithmic or linear pot will feel different here, so try both if you have them.
Why the loop count follows the speed
Each pattern runs inside a for loop that repeats while a is less than b. Since b is recalculated on every pass, the number of repeats follows the pot setting too. At fast settings each pattern lasts only a short burst. At slow settings it repeats many times and takes a long time to finish. If you prefer each pattern to last a fixed number of steps, replace b in the loop condition with a constant.
Things to know about the delay
- The delay() call blocks the program. The pot is only read between steps, so at the slowest settings a change may take several seconds to show up.
- The 2-second pause at the end is fixed and does not depend on the pot.
- All outputs are set explicitly in every step, so there is no leftover state between patterns.
Wiring and testing
Start on a breadboard with two LEDs, each with its own series resistor, connected from P1_6 and P1_7 to ground. Connect the pot as a voltage divider with its wiper on A3. Keep the pot supply at the same voltage as the microcontroller, because the ADC reads relative to the supply and an input above it can damage the pin.
Upload the sketch, then turn the pot slowly. You should see the LEDs swap places, then flash together, then go dark for 2 seconds. If nothing happens, check that the pot wiper really goes to A3 and that the LED polarity is correct.
Driving real loads
The microcontroller pins can only supply a small current, so they are not meant to power lamps directly. To switch bigger loads, use a driver stage between the pin and the load:
- Low-voltage DC lamps or LED strips: a transistor or logic-level MOSFET with a suitable resistor on the gate or base. The article on a MOSFET and a pot shows a similar switching stage.
- Mains lamps: a relay module, or an optocoupler with a triac, so the microcontroller side stays isolated from the mains side.
Safety note: mains voltage can kill. Do not work on live AC wiring unless you are experienced, keep the high-voltage section in an insulated enclosure, and always isolate it from the microcontroller circuit.
Ideas to extend the project
- Add more output pins and more steps to make a longer running pattern. For a larger build, see this 4-channel chaser with speed control.
- Add more pattern modes and a button to switch between them. This low cost multiple pattern chaser shows how that can be done on a small microcontroller.
- For AC lighting without a bulky power supply, look at this transformerless AC chaser.
- Replace delay() with a timer-based approach so the pot reacts instantly even at slow speeds.
- Limit the range with constrain() if you don’t want the very slow settings.
FAQ
What does the pot do in this automatic chaser?
It supplies a voltage to the A3 analog input. The code converts that reading into a delay time, so turning the pot changes how fast the outputs switch.
Why does the code add 1 to analogRead?
If the pot is at its lowest position, the reading is 0, and dividing by zero would cause an error. Adding 1 avoids that and sets the slowest delay to 10000 ms.
Can I connect lamps directly to P1_6 and P1_7?
No. The pins can only supply a small current. Use a transistor, MOSFET, relay or optocoupler stage between the pin and the load. LEDs with a resistor are fine for testing.
Can I use an Arduino instead of the MSP430?
Yes, the logic carries over. You would change the pin names, and the ADC range stays 0 to 1023 on a standard Arduino Uno. Check that the 10000 constant still gives the speed range you want.