Blinking LED - the first Arduino sketch

FunduinoPublished on

Der erste Sketch: die Onboard-LED an Pin 13 blinken lassen

Aufgabe: Eine Leuchtdiode soll blinken.

Auf dem Arduino ist an Pin 13 bereits eine LED eingebaut – für Testzwecke. Häufig blinkt diese Lampe schon, wenn du ein neues Arduino-Board anschließt, weil das Blink-Programm zum Testen des Boards je nach Hersteller bereits vorab installiert ist. Dieses Blinken programmierst du jetzt selbst.

Zum Aufbau: Du musst nur das Board per USB-Kabel mit dem Computer verbinden. Eine weitere Schaltung brauchst du nicht.

Arduino UNO with the onboard LED on pin 13 circled in red
The onboard LED on pin 13 is circled in red.

You need this

Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino 11,12 € *Item no. F23107480About the product — Funduino UNO R3 Microcontroller - ATmega328P, 16 MHz, for Arduino

1 part for 11,12 € *Ready to ship immediately · Delivery time: 1-3 business days

* All prices include statutory VAT, plus shipping costs.

The setup section: Set pin 13 as an output

You only have one output: a voltage must be output at Pin 13 - after all, the LED is supposed to light up.

Write the setup section in the middle of the white input field in the Arduino software. The setup information goes between the curly braces - in this case: Pin 13 should be an output.

The setup section
void setup() // The setup begins here.
{ // A program section begins here.
  pinMode(13, OUTPUT); // Pin 13 should be an output.
} // A program section ends here.

The loop section: the main program

Now add the contents of the loop section, which is the main program: turn on the LED, wait one second, turn off the LED, wait one second. Then the loop section starts over - the LED blinks.

The loop section
void loop() // This is where the main program begins.
{ // This is where a program block begins.
  digitalWrite(13, HIGH); // Turn on the voltage at pin 13 (LED on).
  delay(1000); // Wait 1000 milliseconds (one second).
  digitalWrite(13, LOW); // Turn off the voltage at pin 13 (LED off).
  delay(1000); // Wait 1000 milliseconds (one second).
} // Program block ends.

Upload the complete sketch

Done. Your sketch now looks like this when assembled. All you have to do now is upload it to the board - click the button circled in red at the top left of the software.

Arduino software with the upload sketch button highlighted in red
Upload the sketch using the button circled in red at the top left.
The complete sketch
void setup() // This is where setup begins.
{ // This is where a section of the program begins.
  pinMode(13, OUTPUT); // Pin 13 is set as an output.
} // A section of the program ends here.
void loop() // This is where the main program begins.
{ // This is where a section of the program begins.
  digitalWrite(13, HIGH); // Turn on the voltage at pin 13 (LED on).
  delay(1000); // Wait 1000 milliseconds (one second).
  digitalWrite(13, LOW); // Turn off the voltage at pin 13 (LED off).
  delay(1000); // Wait 1000 milliseconds (one second).
} // A section of the program ends.

Variation: make the LED blink faster

You can now modify the program. For example, make the LED blink very quickly by reducing the delay from 1000 ms to 200 ms.

Upload the new sketch to the board again. If everything worked, the LED will now blink faster.

Variation – blink faster
void setup()            // This is where setup begins.
{                       // This is where a program section begins.
  pinMode(13, OUTPUT);  // Set pin 13 as an output.
}                       // This is where a program section ends.
void loop()               // This is where the main program begins.
{                         // Program section begins.
  digitalWrite(13, HIGH); // Turn on the voltage at pin 13 (LED on).
  delay(200);             // Wait 200 milliseconds.
  digitalWrite(13, LOW);  // Turn off the voltage at pin 13 (LED off).
  delay(200);             // Wait 200 milliseconds.
}                         // Program section ends.
Rate the instructions

Comments

Ask a question or share an experience

Contact us if something doesn’t work. Please include your board and the error message.

We review every comment before publication. Your email address remains with us.