100%
GRIMOIRE
GrimoireDindon CorpusSynthesis VolumesThe Foundation of Iron
FRENAR
RATIO
THE FOUNDATION OF IRON · COURSE MATERIAL · WEEK 4
◆◆◆
EMBEDDED PROGRAMMING
BASICS
Week 4 of 26 · Block 2 — Physical Automation
10h theory · 25h practice
◆ WEEKLY LEARNING OBJECTIVES

1. Understand microcontroller architecture (CPU, memory, I/O pins)
2. Distinguish sensors from actuators, understand the concept of a control loop
3. Write and upload a first Arduino program
4. Read a digital and an analogue sensor
5. Drive an actuator (motor, relay) from a program

◆◆◆
NOTE FOR THE INSTRUCTOR

This week connects directly with Block 1: Boolean logic (Week 3) reappears in program conditions, and voltage reading (Week 1) in analogue sensors. Stating this explicitly helps trainees see the continuity of the pathway.

Amine RAITI · Infrastructure Architect & SRE
Public document · CC BY-NC-SA 4.0 · AI Powered by Amine
Opération Dindon
RATIO
COURSE OUTLINE · 10H
THEORY GUIDING THREAD
4.1 · Microcontroller architecture3h
— CPU, flash memory (program), RAM (variables), input/output pins (I/O)
— Microcontroller vs microprocessor (standalone integrated system vs requiring external peripherals)
— Introducing the Arduino board used (digital pins, analogue pins, power supply)
4.2 · Sensors and actuators3h
— Sensor = converts a physical quantity into an electrical signal (e.g. button, light sensor, distance sensor)
— Actuator = converts an electrical signal into a physical action (e.g. LED, motor, relay)
— Digital signal (0/1) vs analogue signal (continuous value) — link with the binary covered in Week 2
4.3 · The control loop2h
— Arduino program structure: setup() (initialisation, once) and loop() (infinite loop)
— Control loop concept: read a sensor → decide → act on an actuator → repeat
— Direct link with the Boolean logic from Week 3: conditions (if/else) use AND/OR/NOT
4.4 · Analogue reading and conversion2h
— Analogue-to-digital conversion (ADC): a continuous voltage becomes a digital value (0-1023 on Arduino, 10 bits)
— Link with Week 1 (voltage) and Week 2 (binary, powers of 2: 2^10 = 1024 possible values)
EXAMPLE TO DEVELOP ON THE BOARD

A light sensor powered at 5V and read by a 10-bit analogue input returns a value between 0 (0V, total darkness) and 1023 (5V, full light). This value can then be compared to a threshold in a condition (if value > 500).

RATIO
EXERCISE 1 · FIRST ARDUINO PROGRAMS AND SENSOR READING · 12H

Equipment: Arduino Uno board (1 per pair), USB cable, computer with the Arduino IDE installed, LED, 220Ω resistor, push button, light sensor (LDR photoresistor), breadboard, jumper wires.

(1h30) Installing and getting familiar with the Arduino IDE, uploading the provided "Blink" program (blinking the built-in LED), checking it works.
(2h) Wiring an external LED on a breadboard with a protection resistor, modifying the program to blink it at a different frequency.
(2h30) Wiring a push button as a digital input, writing a program that turns on the LED only when the button is pressed (direct link with the conditional logic from 4.3).
(3h) Wiring a light sensor (photoresistor) as an analogue input, reading and displaying the raw value (0-1023) on the serial monitor.
(2h) Writing a program that combines sensor and actuator: automatically turn on the LED if the measured light level drops below a given threshold (simulating automatic lighting).
(1h) Testing, adjusting the trigger threshold, validating the expected behaviour.
SOLUTION — EXERCISE 1

Expected program for step 3 (button → LED): in the loop() function, read the button pin's state with digitalRead(), then use a structure such as if (buttonState == HIGH) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }.

Expected program for step 5 (sensor → automatic LED): read the sensor value with analogRead() (a value between 0 and 1023), then compare it to a threshold (e.g. 400) with if (sensorValue < 400) { digitalWrite(ledPin, HIGH); }.

Marking point: check that each pair correctly identified the direction of the sensor's variation (value increasing or decreasing with darkness, which depends on the voltage-divider wiring used).

RATIO
EXERCISE 2 · MOTOR AND RELAY CONTROL · 13H

Equipment: 5V relay module, small DC motor, NPN transistor (if no relay available), external power supply for the motor, multimeter (acquired in Week 1), breadboard, jumper wires.

(2h) Introduction to the relay module: why a relay is needed to drive a load with power higher than what an Arduino pin can directly supply (recap of the power calculation from Week 1).
(3h) Wiring the relay driven by an Arduino digital pin, test program (toggling on/off every 2 seconds).
(3h) Wiring a small DC motor through the relay, powered by an external source, controlled by the Arduino program.
(3h) Writing a program integrating a sensor (from Exercise 1) and an actuator (motor via relay): start the motor automatically based on a sensor condition (e.g. a fan that starts if a simulated temperature exceeds a threshold).
(2h) Full system testing, measuring the motor's running current with the multimeter, checking consistency with the power concepts from Week 1.
SOLUTION — EXERCISE 2

Expected justification for step 1: an Arduino pin typically supplies a maximum current of 20-40 mA, insufficient for most DC motors, which require several hundred mA. The relay allows a low driving current to control a fully electrically separate power circuit.

Expected program for step 4: a structure similar to Exercise 1 (sensor reading + condition + action), but using digitalWrite() on the relay pin instead of an LED — demonstrating that the same programming logic applies to any actuator.

◆ SUMMARY SHEET — WEEK 4 SELF-ASSESSMENT
1. I can describe the basic architecture of a microcontroller (CPU, memory, I/O).
2. I can distinguish a sensor from an actuator.
3. I can write and upload a simple Arduino program.
4. I can read a digital input (button) and an analogue input (sensor).
5. I can use a condition (if/else) to trigger an action based on a sensor reading.
6. I know why a relay is needed to drive a power load.
7. I can wire and control a DC motor via a relay.
8. I can integrate a sensor and an actuator within the same program.