← How-Tos
electronics Jul 3, 2026 ◯ 2 min read

Getting Started: First Sketch to First Project

arduinogetting startedbeginnertutorial

Anatomy of a Sketch

void setup() { // runs once at power-on/reset } void loop() { // runs repeatedly, forever, after setup() }

Every Arduino program has exactly these two functions. setup() is where you configure pin modes, start serial communication, initialize sensors. loop() is where the actual ongoing behavior lives — it runs continuously until power is cut.

Your First Real Circuit: Button-Controlled LED

const int buttonPin = 2; const int ledPin = 13; void setup() { pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { bool pressed = digitalRead(buttonPin) == LOW; // pull-up means LOW = pressed digitalWrite(ledPin, pressed ? HIGH : LOW); }

Reading the Serial Monitor

Add Serial.begin(9600); in setup(), then Serial.println(someValue); anywhere in loop() to print debug output. Open Tools > Serial Monitor (or the icon top-right) and make sure its baud rate dropdown matches what you set in Serial.begin() — mismatched baud rate is the most common reason people see garbage characters instead of readable text.

Analog Input Basics

analogRead(A0) returns 0-1023 representing 0-5V (or 0-3.3V on 3.3V boards) on that analog pin — this is how you read potentiometers, light sensors (LDRs), and most analog sensors.

PWM "Fake Analog" Output

Digital pins marked with a ~ on the board silkscreen support analogWrite(pin, value) where value is 0-255 — this isn't a true analog voltage, it's a fast on/off pulse (PWM) that averages out to look analog to LEDs (brightness), motors (speed via a driver), and most things that respond to average power rather than instantaneous voltage.

Where to Go Next

Once button+LED and analog read both make sense, you have the two fundamental I/O patterns nearly every Arduino project builds on. From here: try combining them (analog input controlling PWM output — a potentiometer dimming an LED), then move on to a real sensor (DHT22 temp/humidity is a forgiving first "real" sensor to add).