Project 1.01 Blink x2

In this project, you’ll learn how to blink more than one LED!

In this project, we bring a second LED, LED3, into the mix. We are essentially doing the same thing as the last project, but this time we are using two LEDs.

Project Code:

				
					///////////////////////////////////////////////////
//Project 1.01 Blink x 2 
byte LED1 = 13;
byte LED3 = 7;

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

void loop(){ 
  digitalWrite(LED1,HIGH);
  digitalWrite(LED3,HIGH);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,LOW);
  delay(1000);
  digitalWrite(LED1,HIGH);
  digitalWrite(LED3,LOW);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,HIGH);
  delay(1000);
  digitalWrite(LED1,LOW);
  digitalWrite(LED3,LOW);
  delay(1000);
}
///////////////////////////////////////////////////
				
			

*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.

Like all sketches, this simple sketch includes a setup() and a loop() function. Before the setup() function, we declare two variables that refer to the pin numbers for LED1 and LED3:

				
					byte LED1 = 13; 
byte LED3 = 7;
				
			

In the setup() function, we set both pins to OUTPUT using two pinMode statements:

				
					pinMode(LED1,OUTPUT);
pinMode(LED3,OUTPUT);
				
			

In the loop() function, we first switch both LEDs on by setting the pins to HIGH using two digitalWrite statements:

				
					void loop(){ 
  digitalWrite(LED1,HIGH); 
  digitalWrite(LED3,HIGH); 
  delay(1000);
				
			

After a 1-second delay, we turn both LEDs off:

				
					digitalWrite(LED1,LOW);
digitalWrite(LED3,LOW); 
delay(1000);
				
			

Next, we turn only LED1 on:

				
					digitalWrite(LED1,HIGH); 
digitalWrite(LED3,LOW); 
delay(1000);
				
			

And then switch so that only LED3 is on:

				
					digitalWrite(LED1,LOW); 
digitalWrite(LED3,HIGH); 
delay(1000);
				
			

Finally, we turn both LEDs off for 1 second before the loop() function reaches its closing bracket } and begins again at the top:

				
					  digitalWrite(LED1,LOW); 
  digitalWrite(LED3,LOW); 
  delay(1000);
}
				
			

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.