Project 1.00 Blink

In this project, you’ll learn how to blink an LED!
Nearly everyone starts by learning how to blink an LED. Let’s take a second to think about how a light blinks. First, a light turns on, then waits for some amount of time, then turns off, waits for some amount of time, and repeats. That process is what we need to create in Arduino code.

Project Code:

				
					///////////////////////////////////////////////////
//Project 1.00 Blink

byte LED1 = 13;

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

void loop(){ 
  digitalWrite(LED1,HIGH); 
  delay(1000); 
  digitalWrite(LED1,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.

Let’s take a closer look at how this sketch works. We declare one byte variable at the top of the sketch. It is a global variable since it is declared outside the setup() function, loop() function, or any other function. This means we can use it anywhere else in the sketch and it will be recognized. LED1 gets assigned the value 13 because that’s the pin number (on the microcontroller) that LED1 is connected to.

				
					byte LED1 = 13;
				
			

Every sketch needs one setup() and one loop() function. The setup() function runs only once. That’s all we need to set the pinMode of the LED to output so that we can switch it on and off:

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

Now comes the loop() function. This function will run repeatedly. At the top of the block comes the digitalWrite statement. This powers the pin attached to LED1 with 5 V, causing the LED to light up.

				
					void loop(){ 
   digitalWrite(LED1,HIGH);
				
			

LED1 will remain in a HIGH state until we tell it otherwise or we disconnect the MC Trainer from its power source. We want it to stay on for only a second, so we wait 1000 milliseconds (1 second):

				
					delay(1000);
				
			

And then switch the pin to LOW. Now the LED switches off:

				
					digitalWrite(LED1,LOW);
				
			

We keep it off for another second and then finish the loop() function:

				
					  delay(1000);
}
				
			

The closing bracket tells the MC Trainer to go back to the top of the loop() function and repeat it.

Try seeing how fast the LED can blink by changing the number in the delay function. Just a hint, it can blink faster than we can see!

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.