Embedded Programming
Boards, the IDE, and your first working code.
Introduction to Embedded Programming
From blank board to blinking LED
Navigate with ← → or Space · F to present fullscreen · N for the script
Lesson notes
Pick a board, install the IDE, and learn the anatomy of a sketch: setup(), loop(), pins, the serial monitor, blinking and fading LEDs, reading a potentiometer, plus data types and operators.
Introduction to Embedded Programming
From blank board to blinking LED
- Arduino / ESP32 / STM32 boards
- The IDE and sketch structure
- setup(), loop(), pinMode()
- Serial monitor for debugging
- LED control & PWM fading
- Potentiometer & analog input
- Data types, variables, operators
Choosing a Board
Arduino vs ESP32 vs STM32
| Arduino Uno | ESP32 | STM32 | |
|---|---|---|---|
| Core | ATmega328 · 8-bit | Dual 32-bit | ARM Cortex-M |
| Speed | 16 MHz | 240 MHz | 72–480 MHz |
| Wireless | None | Wi-Fi + Bluetooth | None (varies) |
| Best for | Learning basics | IoT & connectivity | Performance & control |
For this bootcamp we mostly use ESP32 — it has Wi-Fi/BT and is cheap, but Arduino code runs on all of them.
The boards you will program
Different brains, same idea — pins on the edges, USB to upload code.
- Arduino Uno — classic 8-bit, beginner-friendly
- ESP32 — fast, Wi-Fi + Bluetooth
The IDE & Sketch Structure
Two functions run every sketch
setup()
- Runs ONCE at power-on/reset
- Configure pins, start Serial
- Initialize sensors and libraries
loop()
- Runs FOREVER, over and over
- Your main program logic
- Read sensors → decide → act
Walk through: install IDE, select board, select port, click Upload. The classic flow.
pinMode + the skeleton
- pinMode() tells a pin to be an INPUT or OUTPUT
- Serial.begin() opens the USB link for debugging
void setup() {
pinMode(13, OUTPUT); // set pin 13 as an output
Serial.begin(115200); // start serial at 115200 baud
}
void loop() {
// your code repeats here, forever
}Serial Monitor — your debugger
Print values to see what is happening
- Match the baud rate in the monitor to Serial.begin()
- print() stays on the line; println() moves to the next
void setup() {
Serial.begin(115200);
}
void loop() {
int reading = analogRead(34);
Serial.print("Sensor: ");
Serial.println(reading); // println adds a new line
delay(500);
}Teach "printf debugging" — when in doubt, print the variable. It is the #1 beginner debugging skill.
LED Control & PWM
Blink, then fade
- digitalWrite = fully ON or OFF
- analogWrite uses PWM — rapid on/off pulses fake an in-between brightness
// Blink
digitalWrite(13, HIGH); delay(500);
digitalWrite(13, LOW); delay(500);
// Fade with PWM (analogWrite: 0–255)
for (int b = 0; b <= 255; b++) {
analogWrite(ledPin, b); // brightness
delay(5);
}PWM = Pulse Width Modulation
The pin switches on/off thousands of times a second. The fraction of time it stays ON — the "duty cycle" — sets the average power.
- 25% duty = dim · 75% = bright
- Same trick sets motor speed
- analogWrite(pin, 0–255)
The bar shows average power tracking the duty cycle — the LED brightness follows it.
Analog Input — the potentiometer
Read a knob, control brightness
- analogRead returns a number across the ADC range
- map() rescales one range to another — incredibly useful
int raw = analogRead(34); // 0–4095 on ESP32
int duty = map(raw, 0, 4095, 0, 255);
analogWrite(ledPin, duty); // knob sets brightnessDigital vs Analog pins
Digital
- Only HIGH or LOW (1 or 0)
- digitalRead / digitalWrite
- Buttons, LEDs, logic signals
Analog
- A range of values (a voltage)
- analogRead in, PWM out
- Sensors, knobs, dimming
Data Types & Operators
Common data types
| Type | Holds | Example |
|---|---|---|
| int | whole numbers | -5, 0, 42 |
| float | decimals | 3.14, 0.5 |
| bool | true / false | true |
| char | one character | 'A' |
| String | text | "hello" |
| byte | 0–255 (8 bits) | 0xFF |
Variables, constants & operators
Storing values
- int ledPin = 13; — a variable
- #define PIN 13 — text replaced before compile
- const int PIN = 13; — typed, safer constant
Operator families
- Arithmetic: + − * / %
- Relational: == != < > <= >=
- Logical: && || !
- Bitwise: & | ^ ~ << >>
Prefer const over #define in modern code — it is type-checked. Bitwise ops matter for registers and flags.
Day 4 — Key Takeaways
- setup() runs once; loop() runs forever
- pinMode sets direction; digitalWrite/Read for on-off
- Serial.println is your debugger
- PWM (analogWrite) fakes analog output for fading & speed
- analogRead + map() turns a knob into any range
- Choose the right data type; know your operator families