Learning Goals 5 min
Today we drill the programming-heavy domains: 5 (syntax), 6 (I/O + PWM), 7 (logic / algorithms), 8 (boards). These are 55% of the exam — the biggest single block. By the end you will:
- Trace small sketches and predict outputs.
- Recognise common bugs and their fixes.
- Know which board / function / library to pick for a scenario.
Warm-Up 5 min
Same drill: pen + paper, < 2 min per question.
Sample Questions · Domains 5-8 60 min
Domain 5 · Programming Syntax
int a = 5;
int b = 3;
int c = a / b;
int d = a % b;
Serial.print(c); Serial.print(" "); Serial.println(d);Output?
Answer
Integer division: 5/3 = 1. Modulo: 5%3 = 2. Output: 1 2.
What's wrong with this declaration?
unsigned int count = -1;Answer
Assigning a negative literal to unsigned int wraps to the max value (e.g. 65535 on UNO). Sometimes intentional; usually a bug.
for (int i = 0; i < 5; i++) {
if (i == 3) continue;
Serial.print(i);
}Output?
Answer
continue skips the rest of this iteration. Output: 0124.
Which declares a constant that lives in flash (not RAM) on AVR?
const int x = 5;const char* msg = "hello";const char msg[] PROGMEM = "hello";static int x = 5;
Answer
3. PROGMEM places the constant in program memory (flash). Without it, even const arrays get copied to RAM at startup.
Domain 6 · Inputs / Outputs / PWM
What does analogWrite(9, 64) do on a UNO?
Answer
Generates a PWM signal on D9 with duty cycle = 64/255 ≈ 25%. Frequency ≈ 490 Hz on D9. Pin must be PWM-capable.
The UNO's ADC returns values in the range:
Answer
0 to 1023 (10-bit). 0 = 0 V, 1023 = VREF (default 5 V).
Why is delay() inside an interrupt handler bad?
Answer
delay() depends on Timer 0 and interrupts being enabled. Inside an ISR, interrupts are disabled by default → delay() hangs. Also: ISRs should be as short as possible.
Which pin combo is correct for a Servo on a UNO?
- Signal → D9, Power → +5V, GND → GND
- Signal → A0, Power → +5V, GND → GND
- Signal → D9, Power → +3.3V, GND → GND
Answer
1. Servos need 5 V and a digital PWM-capable pin. Most servos won't move from 3.3 V.
Domain 7 · Programming Logic & Algorithms
Why use millis() instead of delay() in a robot main loop?
Answer
delay() blocks the CPU; nothing else can run. millis() lets you check the time without blocking, so other tasks (sensor reads, button checks) keep running.
What does this function compute?
int f(int n) {
int s = 0;
for (int i = 1; i <= n; i++) s += i;
return s;
}Answer
Sum of integers from 1 to n. (Triangle number; closed form n(n+1)/2.)
You debounce a button by:
Answer
Sampling the pin, waiting a short fixed time (e.g. 50 ms), sampling again, and accepting the press only if both samples agree. Or in non-blocking style with millis().
What's a state machine?
Answer
A program organised around a small fixed set of named states + rules for transitions between them. Implemented with an enum + switch in loop(). Used in traffic-light controllers, doorbells, robots.
Domain 8 · Frameworks & Boards
Which Arduino board has the most GPIO pins?
- UNO R3
- Mega 2560
- Nano
- Nano 33 BLE
Answer
2. Mega: 54 digital + 16 analog = 70 pins.
The default I²C pins on Arduino UNO are:
Answer
SDA = A4, SCL = A5. (Also exposed on the SDA/SCL header pins on R3.)
Which library is for I²C communication?
- SPI
- Servo
- Wire
- Stepper
Answer
3. Wire is the I²C library; SPI is for SPI.
Which board can run TensorFlow Lite Micro for gesture recognition?
- UNO R3
- Nano 33 BLE Sense
- Nano (V3)
- Mega 2560
Answer
2. Nano 33 BLE Sense has the Cortex-M4 + 256 KB RAM + 1 MB flash + on-board IMU. UNO/Nano/Mega lack the RAM and have no IMU on board.
Try It Yourself · Time test 15 min
Take all 16. Time + score.
- 14-16: solid.
- 10-13: revisit specific lessons.
- < 10: re-read L01-L03 syntax + L03 protocol clusters.
Mini-Challenge · Speed drills 10 min
Re-do all 32 questions (this lesson + previous) WITHOUT looking at answers. Time strictly: 32 × 2 min = 64 min. Then check. Anything > 2 min/question is a sign the exam will run long.
Recap 5 min
Domains 5-8 are the biggest block. Trace sketches mentally. Recall pin maps. Know which library is which. Don't get stuck — flag + move on. Tomorrow: a full mock exam.
- Integer division
- For ints,
/rounds towards zero. Use float division for fractional results. - Modulo (%)
- Remainder of integer division. Common for "every Nth iteration" tests.
- continue / break
- continue = skip rest of this iteration. break = exit the loop entirely.
- Interrupt service routine (ISR)
- Function called by hardware on an event. Must be brief; can't use delay() or Serial.print() reliably.
- millis()
- Milliseconds since the program started. Wraps after ~49 days. Non-blocking timing.
- State machine
- enum + switch pattern. The most common way to structure non-trivial Arduino sketches.
- Wire library
- I²C; SPI for SPI; Servo for servos; Stepper for steppers. Don't confuse names under exam pressure.
- PROGMEM
- AVR keyword for storing data in flash instead of RAM. Use with
pgm_read_*to read.
Homework 5 min
- Score the 16 questions. Note weak spots.
- Re-do all 32 (from L04-46 + L04-47) under time pressure.
- Read ahead to ARD-L04-48 (Mock Exam + Study Plan). The final lesson.