Project 1.02 Simple LED Chase

In this project, you’ll use all four LEDs to blink a chase pattern!

In this project we will use all four LEDs to blink a chase pattern. This example shows a very simple way to create a pattern using digitalWrites and delays.

Project Code:

				
					/////////////////////////////////////////////////
// Project 1.02 LED Chase

byte LED1 = 13;
byte LED2 = 6;
byte LED3 = 7;
byte LED4 = 8;

void setup() {
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}

void loop() {
  digitalWrite(LED4, LOW);
  digitalWrite(LED1, HIGH);
  delay(250);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  delay(250);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
  delay(250);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, HIGH);
  delay(250);
}
/////////////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

Here we set the four variables needed to represent the pins that the LEDs are attached to:
				
					byte LED1 = 13;
byte LED2 = 6;
byte LED3 = 7;
byte LED4 = 8;
				
			
Next, we need to tell the microcontroller that these pins are outputs:
				
					void setup() {
  pinMode(LED1, OUTPUT); 
  pinMode(LED2, OUTPUT);
  pinMode(LED3, OUTPUT);
  pinMode(LED4, OUTPUT);
}
				
			
After that, we can sequentially turn on and off the LEDs to represent a chase pattern. To do this, we have to turn the last LED off, the next LED on, and then wait.
				
					void loop() {
  digitalWrite(LED4, LOW);
  digitalWrite(LED1, HIGH);
  delay(250);
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, HIGH);
  delay(250);
  digitalWrite(LED2, LOW);
  digitalWrite(LED3, HIGH);
  delay(250);
  digitalWrite(LED3, LOW);
  digitalWrite(LED4, HIGH);
  delay(250);
}
				
			
What you may have noticed about the code above is that something happened over and over again. Usually, when things happen over and over again, it is a sign that it should be in some kind of loop and/or function.

Learn More In Our Free Instructional Guidebook

This comprehensive guidebook for the 1st Maker Space Microcontroller Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of microcontrollers, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on learning, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Developmental Project 1.00 Vote

In this project, vote using the OLED and buttons.

Developmental Project 2.00 Mind the Dog

The program demonstrates how embedded systems can track time without stopping the program. Instead of using delay(), which pauses execution, it uses the millis() timestamp technique to calculate elapsed time. This allows multiple tasks—timers, display updates, and LED indicators—to run simultaneously.