Skip to content
Arduino contents

Lesson 1.1: Getting started

Before building circuits you need to be able to do three things: upload a program, read what the board reports on the serial monitor, and install libraries. Every lesson takes them for granted.

Parts

How it works

An Arduino program is called a sketch and has two mandatory functions: setup(), which runs once when the board powers up or resets, and loop(), which then repeats forever.

The IDE compiles the sketch on your computer and uploads it over USB. The same cable opens a serial channel: with Serial.begin() and Serial.println() the board writes text you read on the serial monitor, at the speed —in baud— the code sets.

Libraries are ready-made code you reuse: they drive sensors and displays so you don't have to implement their protocols. Some ship with the IDE and the rest are installed from the library manager.

Code

// Blinks the built-in LED and reports it on the serial monitor.
void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  Serial.println("Hello, Arduino");
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  Serial.println("On");
  delay(1000);

  digitalWrite(LED_BUILTIN, LOW);
  Serial.println("Off");
  delay(1000);
}

What the code does

  • LED_BUILTIN is the pin of the LED on the board: pin 13 on the Uno.
  • pinMode(…, OUTPUT) sets the pin as an output, and digitalWrite() drives it to 5 V (HIGH) or 0 V (LOW).
  • delay(1000) pauses the program for a second. It's convenient, but while it waits the board does nothing else.
  • Serial.begin(9600) opens the serial port at 9600 baud: the serial monitor must be set to the same speed.

Step by step

  1. Download the Arduino IDE from arduino.cc and install it.
  2. Plug the board in over USB.
  3. In the drop-down on the top bar —or in the Tools menu— choose the «Arduino Uno» board and the port it shows up on: COM3 or similar on Windows, /dev/cu.usbmodem… on macOS, /dev/ttyACM0 or /dev/ttyUSB0 on Linux.
  4. Paste the code, click Verify (✓) and then Upload (→).
  5. Open the serial monitor with the magnifier icon at the top right and set it to 9600 baud.
  6. To install a library, open the library manager —the books icon in the sidebar, or Ctrl+Shift+I—, search for it by name and click Install.

Result

The LED marked L blinks every second and the serial monitor keeps printing «On» and «Off».

If it doesn't work

  • If the port doesn't show up, try another cable: many USB cables only charge and don't carry data.
  • Compatible boards with the CH340 USB chip need its driver installed on some systems.
  • If the upload fails, check that the selected board and port are the right ones.
  • If the serial monitor shows garbage, its speed doesn't match the one in Serial.begin().