Arduino Uno Example Sketch: Blink

The original code used pin 13 and had a continuous loop of 1000 milliseconds for the little LED on the board to blink on and off. The example code uses the built-in delay function to pause between each action in the loop function. The setup requires each pin to be defined so that the microcontroller can function on the pins that we choose.

Start Example Code

// the setup function runs once when you press reset or power the board
void setup() {
	// initialize digital pin 13 as an output.
	pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
	digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(1000);              // wait for a second
	digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
	delay(1000);              // wait for a second
}

Initial Code Wiring Diagram

This uses the onboard LED on Pin 13. Here you can see where that is located on the board. No additional wiring is needed.
image

Expanded Code

To do my own little project I added an LED and a resistor on pin 12 and shut off pin 13. I then also changed the timing of the new LED so it would simulate the SOS distress call.

// the setup function runs once when you press reset or power the board
void setup() {
	// initialize digital pin 13 as an output.
	pinMode(12, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(250);             // wait for quarter second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(250);             // wait for quarter second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter half second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(250);             // wait for quarter half second

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(500);              // wait for a half second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(500);             // wait for half second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(500);              // wait for a half second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(500);             // wait for half second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(500);              // wait for a half second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(500);             // wait for half second    

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter  second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(250);             // wait for quarter second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(250);             // wait for quarter second  

	digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
	delay(250);              // wait for quarter second
	digitalWrite(12, LOW);   //turn the LED Off ( Low is the voltage level)
	delay(800);             // wait for 800 milli seconds - when it loops without longer delay it looks like it does a different pattern 
}

Expanded Code Wiring Diagram

Blink%20picimage

The red wire is connected to pin 12 and on the “plus” column on the breadboard.
The red wire is connected in series to a 330-ohm resistor and a red LED.
The orange wire is connected to ground on the Arduino and to the negative lead of the LED.

Bill of Materials


Link to Cart: https://www.digikey.com/short/pq2v19

1 Like