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.
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.
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.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.
// 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
}
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.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.