মূল বিষয়বস্তুতে যান
Learn/First steps with Arduino Uno/Your first sketch: Blink
First steps with Arduino Uno · Lesson
10 min read

Your first sketch: Blink

setup(), loop(), pinMode, digitalWrite and delay — and a blinking LED.

What You Will Learn

  • Explain setup() and loop()
  • Configure a pin as an output
  • Control timing with delay()

Every Arduino sketch has two functions. setup() runs once when the board powers up or resets. loop() then runs again and again, forever.

Arduino C++
void setup() {
  pinMode(9, OUTPUT);     // pin 9 will drive something
}

void loop() {
  digitalWrite(9, HIGH);  // 5 V
  delay(500);             // wait 500 ms
  digitalWrite(9, LOW);   // 0 V
  delay(500);
}
Blink an LEDarduino-uno
Open in Lab
UNOATmega328P: The 8-bit AVR microcontroller that runs your sketch (16 MHz, 32 KB flash, 2 KB RAM).ATmega328PUSB-B: USB connection for uploading sketches and for the Serial Monitor. Also powers the board (5 V).DC jack: Barrel jack for 7–12 V from a battery pack or adapter (centre positive).ATmega16U2: Converts USB to serial for uploads and Serial.print().RESET: Restarts your sketch from the beginning (setup() runs again).L (D13): Built-in LED connected to pin 13 (LED_BUILTIN).ON: Power indicator.5 V regulator: Turns 7–12 V from VIN/jack into a steady 5 V.16 MHz: Clock source: the microcontroller runs 16 million cycles per second.ICSP: In-circuit programming header (SPI). Used to burn a bootloader; not needed for normal uploads.220 Ω+
Note: Press Run. Change the delays to make it blink faster, then try a heartbeat pattern.
delay() stops everything else. That's fine for now; the Programming Patterns course shows how to do several things at once with millis().

Check Your Understanding

Test what you learned in this lesson

1How often does setup() run?

2What does delay(1000) do?