Back to homeTechnology and Engineering I · 1st Bach. Science · Change subject
Start for free
BAC1 tech · Technology and Engineering I
Computer systems · Microcontrollers

Microcontrollers and open-source hardware

A microcontroller board fits in the palm of your hand and costs just a few euros, yet it is a complete computer: processor, memory and connections to the outside world on a single chip. Understanding it thoroughly — its pins, its two-part program and the components around it — is the gateway to programmable electronics and open-source hardware.

Before you start, make sure you know: Electronic components (4th ESO)
Before you start, make sure you know: Programming controller boards (4th ESO)

The microcontroller and open-source hardware

Comparison between a large desktop computer, with a screen, keyboard, network and mains plug, and a microcontroller, a very small board with input and output pins powered by batteries. desktop computer many tasks at once screen network keyboard mains plug expensive, large microcontroller one fixed task input and output pins input output batteries cheap, small
Practice★☆☆Not started
Explain what a microcontroller is and what three basic blocks it integrates into a single chip (processor, program and data memory, and input/output ports). Compare its…

Explain what a microcontroller is and what three basic blocks it integrates into a single chip (processor, program and data memory, and input/output ports). Compare its size and power with those of a personal computer.

Solve
Practice★☆☆Not started
Arduino is the best-known example of open-source hardware. Explain what it means for its hardware to be open-source (the board's schematics and designs are public and…

Arduino is the best-known example of open-source hardware. Explain what it means for its hardware to be open-source (the board's schematics and designs are public and anyone can manufacture or modify them) and name two advantages this offers to someone learning electronics.

Solve
Practice★☆☆Not started
Classify these components as a sensor (input) or actuator (output) in a microcontroller system: (a) a temperature probe, (b) a motor, (c) a microphone, (d) an LED strip,…

Classify these components as a sensor (input) or actuator (output) in a microcontroller system: (a) a temperature probe, (b) a motor, (c) a microphone, (d) an LED strip, (e) an ultrasonic distance sensor, and (f) an irrigation solenoid valve.

Solve

Digital pins, analogue pins and PWM

Practice★☆☆Not started
The inputs on the board can be digital (reading only two states: $0\ \text{V}$ or $5\ \text{V}$) or analogue (reading an intermediate value). Classify these input…

The inputs on the board can be digital (reading only two states: $0\ \text{V}$ or $5\ \text{V}$) or analogue (reading an intermediate value). Classify these input signals: (a) a push button, (b) a potentiometer turned halfway, (c) a light sensor giving a voltage proportional to brightness, and (d) a limit switch.

Solve
Practice★☆☆Not started
The digital outputs on the board give only two values ($0\ \text{V}$ or $5\ \text{V}$). Explain what can be controlled directly with this type of signal (an LED, a…

The digital outputs on the board give only two values ($0\ \text{V}$ or $5\ \text{V}$). Explain what can be controlled directly with this type of signal (an LED, a relay, a buzzer) and what limitation exists if an intermediate brightness or speed is desired.

Solve
Practice★☆☆Not started
Explain what a PWM (pulse-width modulation) signal is: an output that switches very quickly between $0\ \text{V}$ and $5\ \text{V}$ and, depending on the proportion of…

Explain what a PWM (pulse-width modulation) signal is: an output that switches very quickly between $0\ \text{V}$ and $5\ \text{V}$ and, depending on the proportion of high time, simulates an intermediate value. Give the example of adjusting the brightness of an LED.

Solve
Practice★★☆Not started
The board's analogue input converts a voltage between $0\ \text{V}$ and $5\ \text{V}$ into a number between $0$ and $1023$. A program turns on an alert if the reading…

The board's analogue input converts a voltage between $0\ \text{V}$ and $5\ \text{V}$ into a number between $0$ and $1023$. A program turns on an alert if the reading exceeds $600$. (a) Calculate what voltage corresponds to the threshold $600$, with $V = \frac{600}{1023} \cdot 5$. (b) Explain in your own words what the program does and why the threshold is chosen with a margin relative to the typical resting value.

Solve
Practice★★☆Not started
A PWM output of $5\ \text{V}$ operates with a duty cycle of $25\ \%$ (a quarter of the period high). (a) Draw two periods of the signal in your notebook. (b) Calculate…

A PWM output of $5\ \text{V}$ operates with a duty cycle of $25\ \%$ (a quarter of the period high). (a) Draw two periods of the signal in your notebook. (b) Calculate the mean voltage value "seen" by a slow load such as an LED or motor, $V_\text{media} = 5 \cdot 0{,}25$. (c) Explain what mean value a duty cycle of $75\ \%$ would give and how brightness or speed is adjusted this way.

You can do it on paper and send a photo with your answer.

Solve
Practice★★★Not started
A team of students connects a photoresistor (LDR) to the analog input A0 of a microcontroller board ($10\ \text{bits}$, range from $0$ to $1023$) using a voltage…

A team of students connects a photoresistor (LDR) to the analog input A0 of a microcontroller board ($10\ \text{bits}$, range from $0$ to $1023$) using a voltage divider. When calibrating under real conditions, they record a digital reading of $120$ in darkness and $870$ under maximum sunlight.

(a) Deduce the linear interpolation mathematical function that transforms any raw reading $L$ into a percentage of illumination $P \in [0, 100]\ \%$. Calculate the percentage value if the ADC delivers a reading of $495$.

(b) A student implements the line in the code: int porcentaje = (lectura - 120) / 750 * 100;. Upon opening the serial monitor, they find that the variable is always $0$ for any intermediate light level and suddenly jumps to $100$ in direct sunlight. Diagnose the cause of the error in processor arithmetic and write the corrected instruction maintaining integer operations.

(c) If the biasing resistor of the divider is accidentally disconnected, input A0 is left open-circuit, picking up readings outside the calibrated range (for example, $L = 50$). Predict what problem this will cause in the percentage calculation and propose how to protect the code using clamping functions.

Solve

The program: setup and loop

Structure of an Arduino program: setup() runs only once and then loop() repeats non-stop, with an arrow going from its end back to its start. setup() runs only once: configure pins at start-up loop() read, decide, act — and start again repeats while the board is switched on
Practice★☆☆Not started
Every program for these boards has two parts: setup and loop. Explain what is written in each (in setup, what is prepared once, such as configuring the pins; in loop,…

Every program for these boards has two parts: setup and loop. Explain what is written in each (in setup, what is prepared once, such as configuring the pins; in loop, what repeats continuously while the board is powered on) and why this structure fits a control system.

Solve
Practice★★☆Not started
A program configures pin 8 as an output in setup and, in loop, sets the pin high, waits $1\ \text{s}$, sets it low, and waits $1\ \text{s}$. (a) Describe what an LED…

A program configures pin 8 as an output in setup and, in loop, sets the pin high, waits $1\ \text{s}$, sets it low, and waits $1\ \text{s}$. (a) Describe what an LED connected to that pin does. (b) Calculate the flashing period and its frequency in hertz. (c) Explain what you would change in the program to make it flash twice as fast.

Solve
Practice★★☆Not started
The figure shows the diagram of an Arduino-type microcontroller board with its pin headers, with one pin marked with a question mark, as shown in the figure. (a)…

The figure shows the diagram of an Arduino-type microcontroller board with its pin headers, with one pin marked with a question mark, as shown in the figure.

USB microcontroller digital pins 0 to 13 (~ = PWM) ? analogue inputs A0 to A5 5 V GND power supply via USB or external jack (7 to 12 V)

(a) Identify the pin headers on the board: digital, analogue, and power. (b) The pin marked with the question mark is in the digital row and has the ~ symbol: explain what it can do besides supplying $0\ \text{V}$ or $5\ \text{V}$. (c) State which pin you would connect each component to and why: a push button, a potentiometer, and a dimmable LED.

Solve
Practice★★☆Not started
Write in pseudocode the complete program (setup and loop) so that an LED connected to pin 9 turns on while a button connected to pin 2 is held down, and turns off when…

Write in pseudocode the complete program (setup and loop) so that an LED connected to pin 9 turns on while a button connected to pin 2 is held down, and turns off when released. Explain the configuration of each pin in setup (input or output).

Solve
Practice★★☆Not started
A program to control an LED on pin 7 does not work: in loop, the pin is set high and low, but the LED never turns on. Checking setup, no one configured the pin as an…

A program to control an LED on pin 7 does not work: in loop, the pin is set high and low, but the LED never turns on. Checking setup, no one configured the pin as an output. Explain why this oversight prevents it from working (by default, pins remain as inputs) and rewrite the correct setup in pseudocode.

Solve

Interface components: protecting and adapting

Electrical diagrams with an Arduino board: on the left, a push-button between +5 V and digital input D2, with a 10 kΩ pull-down resistor from the pin to ground; on the right, digital output D13 powers an LED through a 220 Ω series resistor that limits the current to below 20 mA. Input with pull-down Output with resistor Arduino Uno D2 D13 +5 V push-button digital input resistor pull-down 10 kΩ GND (0 V) released → pin at 0 V (reads 0) pressed → pin at 5 V (reads 1) digital output resistor in series 220 Ω I < 20 mA LED GND
Practice★☆☆Not started
An LED is connected to an output pin of the board ($5\ \text{V}$). Explain what component must always be placed in series (a series resistor) and what two things its…

An LED is connected to an output pin of the board ($5\ \text{V}$). Explain what component must always be placed in series (a series resistor) and what two things its absence could damage: the LED itself or the pin of the board, which can only supply around $20\ \text{mA}$.

Solve
Practice★★★Not started
A student sets up a push button by connecting one terminal to the $+5\ \text{V}$ pin of the board and the other directly to the digital input D2, without adding any…

A student sets up a push button by connecting one terminal to the $+5\ \text{V}$ pin of the board and the other directly to the digital input D2, without adding any further components. When monitoring the input, they observe that when pressing the button they read a stable logical '1', but upon releasing it, the pin oscillates chaotically between '0' and '1' in response to any nearby movement or vibration.

(a) Interpret this failure based on the concept of high input impedance in digital logic gates and explain what it physically means for the input to remain in a "floating" state.

(b) Draw or describe in detail the circuit of a $10\ \text{k}\Omega$ pull-down resistor. Justify the voltage value at pin D2 both with the push button at rest and pressed, and calculate the current consumed by the resistor in each state.

(c) The student asks whether they could use a $10\ \Omega$ resistor instead of $10\ \text{k}\Omega$, arguing that it will "divert noise to ground more strongly". Technically refute their proposal by calculating the power that such a resistor would dissipate and the risks to the power supply. Furthermore, explain how the setup could be solved without external components by activating the INPUT_PULLUP option of the microcontroller.

Solve

Controlling power actuators: relays and transistors

A pin on the Arduino board, at 5 V and about 20 mA, powers the coil of a relay. This closes the contact of a separate power circuit, with a 230 V source, that drives a pump: a small current controls a large current. board Arduino pin GND 5 V · ≈20 mA relay coil contact large current power circuit separate source · 230 V ~ pump 230 V control circuit small current a small current controls a large current
Practice★★☆Not started
The figure shows a light measurement system with a microcontroller board: an LDR is connected to an analog input (A0) and an LED is driven from a digital pin (D9). The…

The figure shows a light measurement system with a microcontroller board: an LDR is connected to an analog input (A0) and an LED is driven from a digital pin (D9). The inside of the board is marked with a question mark.

Block diagram: an LDR connected to input A0 of a microcontroller board whose interior is marked with a question mark, and an LED connected to output D9LDRlight sensorA0Microcontroller board?D9LED
  1. a) Explain what the central box marked with the question mark contains, that is, what the program running in the loop function does between reading A0 and driving output D9.
  1. b) Write that program in pseudocode so that the LED turns on when the LDR reading exceeds a threshold.
  1. c) State which two essential external components are missing from the drawing for the circuit to really work.
Solve
Practice★★★Not started
The figure shows the diagram of an automatic irrigation system using a microcontroller board: a soil moisture probe connects to A0 and output D7 controls the pump via a…

The figure shows the diagram of an automatic irrigation system using a microcontroller board: a soil moisture probe connects to A0 and output D7 controls the pump via a component marked with a question mark, as shown in the figure.

moisture probe A0 microcontroller board D7 ? pump 230 V if the soil is dry, the board turns on watering; when the probe detects sufficient moisture, it stops

(a) Identify the component marked with the question mark (the element that allows an output of $5\ \text{V}$ and low $\text{mA}$ to control a $230\ \text{V}$ pump) and explain its function. (b) Describe the inputs and outputs of the system and the complete operating cycle. (c) Propose two reasonable improvements (not watering at night or when it rains, low tank level warning), stating which sensor or condition each would add to the program.

Solve
Practice★★★Not started
It is desired to regulate the rotational speed of a $12\ \text{V}$ direct current motor with a rated current of $800\ \text{mA}$ using a microcontroller board whose…

It is desired to regulate the rotational speed of a $12\ \text{V}$ direct current motor with a rated current of $800\ \text{mA}$ using a microcontroller board whose digital outputs provide a maximum of $5\ \text{V}$ and $20\ \text{mA}$.

(a) A student proposes powering the motor by operating a BJT transistor in its linear/active region controlled by an analog voltage, behaving as a variable series resistor. If the motor operates at half power receiving $6\ \text{V}$ and drawing $500\ \text{mA}$, calculate the power that the transistor would have to dissipate as heat ($P = V_{CE} \cdot I_C$). Compare this value with the dissipation of the transistor operating in saturated switching using PWM ($V_{CE(\text{sat})} \approx 0,25\ \text{V}$) with a duty cycle of $50\ \%$ and justify the energy superiority of PWM.

(b) Explain how a DC motor can rotate at a smooth, constant speed when powered by square wave pulses at $500\ \text{Hz}$ instead of a pure DC voltage.

(c) When switching an inductive load such as a motor with PWM, it is essential to add an antiparallel diode (flyback). Predict what will happen at the instant the transistor abruptly transitions from saturation to cutoff if this diode is omitted, justifying your answer based on the law of self-induction ($V_L = -L \frac{di}{dt}$).

Solve
Practice★★★Not started
An engineering firm must select the automation platform for two facilities: • Facility A: Industrial hydraulic press in a metalworking workshop, with $15\ \text{kW}$…

An engineering firm must select the automation platform for two facilities:

• Facility A: Industrial hydraulic press in a metalworking workshop, with $15\ \text{kW}$ three-phase motors, $24\ \text{V}$ solenoid valves, continuous mechanical vibrations, and high electromagnetic noise.

• Facility B: Distributed network of $80$ sensor nodes to monitor in real time the microclimate inside a group of greenhouses, battery-powered and connected via MQTT wireless protocol.

(a) Select and reasonably justify whether you would implement a programmable logic controller (PLC) or a microcontroller board in each of the two facilities.

(b) Analyze the requirements for electrical conditioning and noise immunity: compare how each platform manages inputs/outputs (galvanic isolation, industrial standard voltage levels versus $3,3\ \text{V}$ or $5\ \text{V}$ TTL/CMOS levels).

(c) A manager suggests replacing the PLCs in the metalworking plant with low-cost commercial microcontroller boards to reduce the initial investment by $85\ \%$. Write a technical report refuting their position, considering machinery safety regulations (CE marking, electromagnetic compatibility directive), maintainability by plant technicians, and standard languages (IEC 61131-3 versus C/C++).

Solve

Calibration, hysteresis and autonomy

Hysteresis cycle of a fan: as it warms up it switches on at 30 °C and as it cools down it switches off at 28 °C, with a 2 °C band between the two thresholds. 28°C (off) 30°C (on) hysteresis 2 °C fan on fan off → when warming up ← when cooling down temperature
Practice★★☆Not started
A temperature sensor is connected to an analogue input: the reading $0$ corresponds to $0\ ^\circ\text{C}$ and the reading $1023$, to $100\ ^\circ\text{C}$. (a)…

A temperature sensor is connected to an analogue input: the reading $0$ corresponds to $0\ ^\circ\text{C}$ and the reading $1023$, to $100\ ^\circ\text{C}$. (a) Calculate what temperature corresponds to a reading of $512$, assuming the proportional relationship $T = \frac{lectura}{1023} \cdot 100$. (b) Calculate what reading a temperature of $35\ ^\circ\text{C}$ would give. (c) Explain why this conversion is necessary before displaying the data to a user.

Solve
Practice★★★Not started
A technician programs the cooling control of a server using a microcontroller board. They design the basic logic: "if $T > 30,0\ ^\circ\text{C} \rightarrow$ turn on fan;…

A technician programs the cooling control of a server using a microcontroller board. They design the basic logic: "if $T > 30,0\ ^\circ\text{C} \rightarrow$ turn on fan; otherwise $\rightarrow$ turn off fan". When testing the prototype in a climate chamber around $30,0\ ^\circ\text{C}$, they observe that the fan relay switches frantically several times per second, producing a continuous buzzing sound and overheating the actuator.

(a) Interpret the physical and computational origin of this problem, considering the noise inherent in the analog sensor reading and the thermal inertia of the system.

(b) Redesign the algorithm by implementing hysteresis control with thresholds at $31,0\ ^\circ\text{C}$ (turn on) and $28,0\ ^\circ\text{C}$ (turn off). Write the logic in pseudocode and justify why it is essential to check the current state of the fan or use a state variable.

(c) The temperature probe delivers an analog voltage of $10\ \text{mV}/^\circ\text{C}$ ($0\ \text{V}$ at $0\ ^\circ\text{C}$) connected to the board's $10\ \text{-bit}$ ADC converter ($V_{\text{ref}} = 5,0\ \text{V}$). Calculate the exact integer value ($0$ to $1023$) that the analogRead() function will read for each of the two programmed thresholds.

Solve
Practice★★★Not started
A remote agrometeorological station is powered by a $3,7\ \text{V}$ Li-ion cell with a capacity of $2400\ \text{mA}\cdot\text{h}$. The station takes sensor readings and…

A remote agrometeorological station is powered by a $3,7\ \text{V}$ Li-ion cell with a capacity of $2400\ \text{mA}\cdot\text{h}$. The station takes sensor readings and transmits them by radio: during this active phase, the circuit consumes $75\ \text{mA}$ for $4\ \text{s}$. Between transmissions, the board enters deep sleep mode (deep sleep), where the combined consumption of the board and regulator drops to $50\ \mu\text{A}$ ($0,05\ \text{mA}$). The station must operate uninterruptedly for a minimum of $180\ \text{days}$ (about $4320\ \text{h}$) without recharging the battery.

(a) Derive the expression for the average current consumption $I_{\text{med}}$ as a function of the period between measurements $T$ (in seconds). Calculate the minimum allowable sampling interval to meet the required battery life.

(b) If due to a programming error the radio module does not shut down during sleep, raising the idle consumption to $3,0\ \text{mA}$, predict the new actual battery life keeping the interval calculated in the previous section.

(c) To power the microcontroller at $3,3\ \text{V}$ from the $3,7\ \text{V}$ battery, one technician suggests a linear LDO regulator and another a step-down switching converter (buck). Justify which one is more recommendable for this application, paying special attention to the quiescent current (quiescent current) of each device.

Solve
Practice★★★Not started
A student programs the push-button traffic light of a school pedestrian crossing. They write sequential code where the vehicular green light stays on via the call…

A student programs the push-button traffic light of a school pedestrian crossing. They write sequential code where the vehicular green light stays on via the call delay(20000); then it reads the pedestrian push button with a digitalRead() and, if it is pressed, switches to amber ($3\ \text{s}$) and red ($10\ \text{s}$). When installed, pedestrians complain that they press the button but the traffic light seems unresponsive the vast majority of the time.

(a) Interpret the technical cause of the failure by diagnosing what happens in the microcontroller CPU during the execution of the delay() functions and why button presses are missed.

(b) Redesign the program architecture using a non-blocking finite state machine controlled by the timing function millis(). Write the pseudocode of the loop(), ensuring that the push button reading is serviced continuously without halting execution.

(c) Incorporate into the design two indispensable road safety constraints: 1) ensure that vehicles always have a minimum uninterrupted green time of $15\ \text{s}$ before any pedestrian button press can trigger the switch to amber; 2) justify how to prevent mechanical contact bounce (chattering) of the push button from causing erratic triggering of the cycle.

Solve

Summary

See all the exercises in this section