Day 1 of 5
⏱ ~60 minutes
Arduino in 5 Days — Day 1

Setup and First Sketch

Arduino is the fastest path from idea to blinking LED. Today you'll get the IDE running, understand the sketch structure, and write your first program.

Arduino IDE and Board Setup

Download the Arduino IDE 2 from arduino.cc. Install it. Connect your Arduino Uno or Nano via USB. In Tools → Board, select 'Arduino Uno'. In Tools → Port, select the COM port (Windows) or /dev/cu.usbmodem... (macOS) or /dev/ttyACM0 (Linux). If Linux shows permission errors: sudo usermod -aG dialout $USER then log out and back in.

Sketch Structure

Every Arduino sketch has two functions. setup() runs once at power-on — initialize pins, serial port, and libraries here. loop() runs forever after setup — this is where your main logic lives. There is no main() — the Arduino framework wraps everything. The built-in LED is on pin 13 (constant LED_BUILTIN). pinMode(pin, OUTPUT) configures a pin. digitalWrite(pin, HIGH) sets it to 5V.

Serial Monitor for Debugging

Serial.begin(9600) in setup() opens a UART connection at 9600 baud. Serial.println(value) sends a line. Open the Serial Monitor (Ctrl+Shift+M) — it shows live output from the Arduino. This is your primary debugging tool. Use Serial.print() without newline for inline values, Serial.println() to add a newline.

cpp
// Arduino Blink with Serial feedback
// Upload to Arduino Uno/Nano via Arduino IDE

const int LED_PIN = LED_BUILTIN; // Pin 13
const int BLINK_INTERVAL = 500;  // milliseconds

void setup() {
  Serial.begin(9600);
  pinMode(LED_PIN, OUTPUT);
  Serial.println("Arduino started. Blinking LED...");
}

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println("LED ON");
  delay(BLINK_INTERVAL);

  digitalWrite(LED_PIN, LOW);
  Serial.println("LED OFF");
  delay(BLINK_INTERVAL);
}

// ── Non-blocking blink (better practice) ────────────
// Use millis() instead of delay() so other code can run
unsigned long lastToggle = 0;
bool ledState = false;

void loop_nonblocking() {
  unsigned long now = millis();
  if (now - lastToggle >= BLINK_INTERVAL) {
    lastToggle = now;
    ledState = !ledState;
    digitalWrite(LED_PIN, ledState ? HIGH : LOW);
    Serial.print("LED: ");
    Serial.println(ledState ? "ON" : "OFF");
  }
  // Other code here runs every iteration without blocking
}
💡
Never use delay() in real projects — it blocks everything. Use millis() to track elapsed time and take action when enough time has passed. This lets the same loop handle multiple timers simultaneously.
📝 Day 1 Exercise
Blink Three LEDs at Different Rates
  1. Wire 3 LEDs with 330Ω resistors to pins 9, 10, 11.
  2. Implement non-blocking blink for each LED: 250ms, 500ms, 1000ms intervals using millis().
  3. Add Serial output: print which LED toggled and at what millis() time.
  4. Verify all three blink independently without blocking each other.
  5. Add a 4th state: when all three are ON simultaneously, print 'SYNC' to serial.

Day 1 Summary

  • setup() runs once, loop() runs forever — this is the entire Arduino execution model
  • Use millis() not delay() for timing — delay() blocks the entire MCU
  • Serial.begin(9600) + Serial.println() is your debugging lifeline on embedded hardware
  • LED_BUILTIN (pin 13) has a built-in current-limiting resistor — external LEDs always need their own
Challenge

Implement a Morse code transmitter. Define a string message (e.g., 'SOS'). Encode dots (250ms on, 250ms off) and dashes (750ms on, 250ms off) with 500ms gap between letters. Use only millis() — no delay(). Print each symbol to Serial as it transmits.

Finished this lesson?