Back to homeTechnology · Secondary Year 3 · Change subject
Start for free
Secondary 3 · Technology
Programming and robotics · Control and robotics

Microcontrollers and Robots

Before you start, make sure you know: The electric circuit (Secondary Year 1)
Before you start, make sure you know: Robots and controller boards (Secondary Year 2)

At your school's science and technology fair, Ximena's team presents a parking gate that lifts by itself when a car arrives. It has no computer, no screen, and no keyboard. What makes it "think"? A small board that fits in your hand. By the end of this page you will be able to explain how it does it.

The microcontroller: a tiny computer

Comparison between a desktop computer, large, with a screen, keyboard, and wall outlet, and a microcontroller, a small chip with input and output pins that runs on batteries desktop computer many tasks at once microcontroller one fixed task internet outlet expensive, large input output input and output pins batteries cheap, small

A board like Arduino carries a microcontroller and the connectors to use it easily. You program it from a computer, but afterward it works on its own.

Practice★☆☆Not started
Explain what a microcontroller is (a complete but small computer inside a board) and two differences from a desktop computer: what each can do and what each is used for.

Explain what a microcontroller is (a complete but small computer inside a board) and two differences from a desktop computer: what each can do and what each is used for.

Solve
Practice★☆☆Not started
Explain how a program reaches the board: where it is written, what happens when it is "uploaded" via the cable, and why the board then works independently without a…

Explain how a program reaches the board: where it is written, what happens when it is "uploaded" via the cable, and why the board then works independently without a computer, running the program in a loop.

Solve
Practice★★★Not started
Your team must select the hardware platform to build a home automation prototype that controls blinds using servomotors, detects gas leaks and presence in three…

Your team must select the hardware platform to build a home automation prototype that controls blinds using servomotors, detects gas leaks and presence in three different rooms, and displays the status on an LCD screen.

  1. a) Compare the suitability of using a compact "all-in-one" board (with sensors and LED display integrated on the printed circuit board itself) versus a modular development board with expansion pins and a breadboard. Analyze aspects such as the spatial distribution of the sensors throughout the home and the wiring of power actuators.
  2. b) If during assembly a student makes a mistake and burns out the temperature sensor due to overvoltage or reverse polarity, analyze the technical and cost impact on the integrated board versus the modular board.
  3. c) Justify with reasoned arguments which of the two platforms you would choose for this final home automation robotics project and for which of them you would reserve an initial two-hour introductory programming session.
Solve

Pins: where everything connects

Diagram of inputs and outputs connected to a board: pushbutton and LDR as inputs, LED and servo as outputs board ⏺ button digital input ☀ LDR analog input LED digital output ⚙ servo output (angle)

Besides the signal pins, the board has power pins (5 V and 3.3 V) and several GND pins. And the USB connector does two things: it uploads the program from the computer and powers the board while it is connected.

Practice★☆☆Not started
The figure shows a microcontroller board with its groups of pins labeled, except for one. The covered pin is the common reference that all the circuits you connect to…

The figure shows a microcontroller board with its groups of pins labeled, except for one.

Microcontroller board with digital pins, analog pins and power pins; one of them is covered with a question mark digital pins D2–D13 USB microcontroller analog pins A0–A5 5 V 3.3 V ?

The covered pin is the common reference that all the circuits you connect to the board return to. Name it and explain what it is for, what the difference is between digital pins (all or nothing) and analog pins (they read continuous values), and what the USB connector is used for.

Solve
Practice★☆☆Not started
Classify these items according to whether they connect to an input pin or an output pin on the board, and justify one of each type: a push button, an LED, an LDR, a…

Classify these items according to whether they connect to an input pin or an output pin on the board, and justify one of each type: a push button, an LED, an LDR, a buzzer, and a potentiometer.

Solve
Practice★☆☆Not started
State whether these statements are true or false and justify each answer: (a) the board executes the program exactly as written, without translating it first; (b) the…

State whether these statements are true or false and justify each answer: (a) the board executes the program exactly as written, without translating it first; (b) the board pins can handle any current, so the LED can be connected without a resistor; (c) a servo motor can be set to a specific angle commanded by the program; (d) the board remembers the last program even if it is disconnected from the power supply.

Solve

Sensors and actuators

Block diagram: the ultrasonic and infrared sensors send signals to the board, and the board sends commands to the servo, the motor, and the buzzer INPUTS CONTROL OUTPUTS board ultrasonic infrared servo motor buzzer
Sensor What it measures Project
Ultrasonic distance parking gate
LDR light lamp that turns on at dusk
Temperature temperature automatic fan
Infrared line light or dark on the floor line-following robot

Among actuators, the LED gives light and the buzzer gives sound. A potentiometer, on the other hand, is an input: you turn the knob and the board reads the value.

How to choose the board

Before buying or building, count what your project needs: how many sensors, how many actuators, and how many pins each one uses (an ultrasonic sensor uses 2, a servo 1, an LED 1).

  • A compact "all-in-one" board (with sensors and a display already soldered on) is handy for a small project concentrated in one place, but you can't add more or separate the sensors.

  • A modular board with expansion pins and a breadboard lets you connect as many sensors and actuators as it has pins, and place them far away with wires: for example, a gas sensor in each bedroom of an apartment.

  • Power actuators (blinds with large servos, motors) do not connect directly to the pins: they have their own controller and their own power supply.

Rule of thumb: add up the pins you need, add some margin to expand the project, and choose the board that has them and lets you place each sensor where it is needed.

Practice★☆☆Not started
The figure shows a mobile robot seen from above, with its elements labeled and its "brain" covered. Name the covered component (the microcontroller board), explain what…

The figure shows a mobile robot seen from above, with its elements labeled and its "brain" covered.

? battery motorized wheels ultrasonic sensor buzzer LED

Name the covered component (the microcontroller board), explain what information it receives from the sensors and what commands it sends to the actuators, and classify the labeled elements (motorized wheels, ultrasonic sensor, buzzer, LED, battery) as input, output, or power source.

Solve
Practice★☆☆Not started
State what each sensor that can be connected to the board measures and a project in which you would use it: ultrasonic sensor (distance), LDR (light), temperature…

State what each sensor that can be connected to the board measures and a project in which you would use it: ultrasonic sensor (distance), LDR (light), temperature sensor, and infrared line sensor (distinguishes light from dark on the ground).

Solve
Practice★☆☆Not started
State what each connectable actuator to the board does and a key difference between them: an LED, a buzzer, a servo motor (turns to the exact position commanded), and a…

State what each connectable actuator to the board does and a key difference between them: an LED, a buzzer, a servo motor (turns to the exact position commanded), and a DC motor (rotates continuously at higher or lower speed).

Solve
Practice★★☆Not started
To move a parking lot barrier, you can use a servo motor or a DC motor. Compare both: which reaches an exact position and stays still, which rotates continuously, which…

To move a parking lot barrier, you can use a servo motor or a DC motor. Compare both: which reaches an exact position and stays still, which rotates continuously, which requires less extra electronics in this project, and why.

Solve
Practice★★☆Not started
A robot's motors are not powered directly from a board pin, but from the battery via a "motor driver board". Explain why (the pins provide very little current and the…

A robot's motors are not powered directly from a board pin, but from the battery via a "motor driver board". Explain why (the pins provide very little current and the motor requires much more), what role the driver board plays, and how this relates to a relay in electronic circuits.

Solve

Programming with conditions: read, compare, act

The program is written on a computer, compiled (translated into machine language), and uploaded through the USB cable to the board's memory. From there, the board keeps it even when powered off and runs it on its own, in a loop.

An input that triggers a sequence

A pedestrian traffic light adds an input: the pedestrians' button. The program does not change the lights as soon as it is pressed, but follows a flowchart with timings.

Flowchart of a pedestrian traffic light: cars' green until the button is pressed, then amber for 2 seconds, red with pedestrian green for 5 seconds, closing warning, and back to green cars green, pedestrian red button pressed? no yes cars amber, 2 s cars red and pedestrian green, 5 s pedestrian green flashes (warning)

The cars' green light is not cut off instantly when the button is pressed, because a driver going at speed needs to see the amber first in order to brake safely. That is why there is a timed sequence between the input (the button) and the output (the red). In addition, the closing warning (a flashing light) tells the pedestrian not to start crossing anymore. In total, after pressing, the crossing lasts $2 + 5 = 7\ \text{s}$ plus the warning.

Practice★★☆Not started
You want an LED to light up when the room light falls below a certain level. Explain which pin you use to read the LDR (an analogue one), what setting a "threshold" in…

You want an LED to light up when the room light falls below a certain level. Explain which pin you use to read the LDR (an analogue one), what setting a "threshold" in the program means, and write the three key lines in pseudocode: read, compare, and act.

Solve
Practice★★☆Not started
The figure shows the flowchart for controlling a parking lot barrier using an ultrasonic sensor, but the decision box is covered. Write the condition that the board must…

The figure shows the flowchart for controlling a parking lot barrier using an ultrasonic sensor, but the decision box is covered.

start ? no yes raise the barrier wait 5 s lower the barrier the ultrasonic sensor measures the distance to the approaching car

Write the condition that the board must check (if the measured distance is less than a certain value, a car is present), explain what the loop does while no one arrives, and what would happen if the barrier lowered without waiting a few seconds.

Solve
Practice★★☆Not started
Design a traffic light using the board: decide how many output pins you need and for what, write the sequence of states with their timings (green $4\ \text{s}$, amber…

Design a traffic light using the board: decide how many output pins you need and for what, write the sequence of states with their timings (green $4\ \text{s}$, amber $1\ \text{s}$, red $4\ \text{s}$), and explain why the program is written as an infinite loop.

Solve
Practice★★☆Not started
Your program should turn on an LED when a button is pressed, but the opposite occurs: it is on and turns off when pressed. Explain two possible causes (the program logic…

Your program should turn on an LED when a button is pressed, but the opposite occurs: it is on and turns off when pressed. Explain two possible causes (the program logic is inverted or the push button is wired in reverse, "active-low") and how you would test each one.

Solve
Practice★★★Not started
A group of students has programmed a pedestrian traffic light with a push-button using the following logic: as soon as the pedestrian presses the button, the vehicular…

A group of students has programmed a pedestrian traffic light with a push-button using the following logic: as soon as the pedestrian presses the button, the vehicular light turns instantly from green to red and the pedestrian light turns green for 15 s. After testing it on a road model, they observe sharp braking by vehicles and continuous traffic jams if several pedestrians repeatedly press the button.

  1. a) Justify two road safety and traffic flow flaws present in this initial program.
  2. b) Design the flowchart or the corrected timing sequence (indicating inputs, outputs, and recommended times) to resolve both problems, incorporating a transition phase (amber) and guaranteeing a minimum time of continuous green for cars before serving another pedestrian call.
  3. c) If you want to add an intermittent acoustic buzzer for visually impaired individuals during the last 3 s of the pedestrian green, how should you modify the timing of that output?
Solve

Ultrasonic sensor

Ultrasonic sensor: a pulse goes out toward the obstacle and the echo returns; the round-trip time measures the distance sensor pulse (out) echo (back) obstacle

It can fail with soft objects (cloth, foam) that absorb sound, and with slanted surfaces that deflect the echo in another direction, so that it never returns to the sensor.

The obstacle-avoiding robot

With this sensor mounted on the front, the robot follows a simple behavior that repeats in the loop:

  1. It measures the distance ahead.

  2. If it is clear (distance greater than the threshold, for example $20\ \text{cm}$), the motors move forward.

  3. If it detects something close (distance less than the threshold): it stops, turns a little, and measures again. If it is still blocked, it turns again; if there is now a path, it moves forward.

The "check again" step is important: a single turn does not guarantee that the path will be clear. With only one sensor on the front, the robot cannot see what is at the sides or behind: it can scrape a wall when turning or end up going in circles in a corner. A second sensor (or turning the sensor with a servo) gives it more information.

Practice★★☆Not started
An ultrasonic sensor measures distance like a bat. Explain the principle (it emits a sound pulse and measures how long the echo takes to return), why it has two "eyes"…

An ultrasonic sensor measures distance like a bat. Explain the principle (it emits a sound pulse and measures how long the echo takes to return), why it has two "eyes" (one transmitter and one receiver), and two situations in which it might fail: soft objects that absorb sound and inclined surfaces that deflect the echo.

Solve
Practice★★☆Not started
Describe the high-level behavior of an obstacle-avoiding robot: what the front sensor measures, what the robot does when the path is clear, and what sequence it executes…

Describe the high-level behavior of an obstacle-avoiding robot: what the front sensor measures, what the robot does when the path is clear, and what sequence it executes when it detects something close (stop, turn, check again). What would happen if it only had a forward-facing sensor?

Solve
Practice★★★Not started
To control an access barrier with an emergency stop push button, a student programs the following sequence: During testing, when the emergency stop button is pressed…

To control an access barrier with an emergency stop push button, a student programs the following sequence:

open_barrier();

wait(5000); // fixed 5 s pause with delay

close_barrier();

During testing, when the emergency stop button is pressed during the 5 s pause or while the barrier is descending, the system does not respond and continues its cycle, causing an impact.

  1. a) Explain at the microcontroller execution level why the fixed wait instruction (delay) blocks responsiveness to the emergency.
  2. b) Design the algorithmic structure (in pseudocode or flowchart) that allows keeping the barrier open for 5 s while continuously checking the stop push button to stop the motor instantaneously.
  3. c) If you also need a buzzer to emit intermittent 0.5 s beeps while the barrier is moving, justify why this requirement is unfeasible with blocking pauses and how it is solved.
Solve

Infrared sensor and line follower

To decide whether the sensor "sees" white or black, the board needs a threshold. That threshold is not guessed: it is obtained by calibrating, that is, by measuring the sensor under the real conditions of the track.

Top view of a robot with two infrared sensors 3 cm apart, one on each side of a 2 cm wide black line black line (2 cm) S left S right 3 cm

With two sensors, the spacing between them also matters. The line is $2\ \text{cm}$ wide: if the sensors are closer than that (for example $1\ \text{cm}$), both end up over the black at once and the robot thinks it has reached a mark. If they are too far apart (for example $6\ \text{cm}$), both see white even when the line is drifting to one side, and the robot detects the deviation too late. The best is a spacing slightly larger than the line's width, like the $3\ \text{cm}$ in the figure.

Practice★★★Not started
You are designing the calibration and assembly of a line-following robot that travels along a white circuit with a 2 cm wide black line. The robot has two infrared…

You are designing the calibration and assembly of a line-following robot that travels along a white circuit with a 2 cm wide black line. The robot has two infrared reflectance sensors ($S_I$ and $S_D$) mounted on the front and differential drive with two independent motors.

  1. a) Predict what erroneous behavior the robot will have if you mount the sensors separated by only 1 cm from each other (a distance smaller than the line width). What if you separate them by 6 cm? Justify what the optimal geometric separation should be.
  2. b) Design the robot's decision table indicating the state of each motor (forward, stop, or reverse) for each of the 4 possible reading combinations (White/Black).
  3. c) Upon reaching a sharp left turn, if the robot only turns off the left motor and keeps the right motor forward, it tends to leave the line due to inertia. Justify what change you must make in the motor control to achieve a much tighter turn on its own axis.
Solve

Designing and troubleshooting a robot

Three-phase cyclic flow of a robot with wheels: follow line, detect mark, and signal follow line detect mark signal the main loop repeats the three phases nonstop

Sampling rate

The sampling rate is how often the board reads a sensor. It is chosen according to how fast what you measure changes: if you read too often, you fill the memory with repeated data and waste energy; if you read only now and then, you miss the important changes.

Variable Changes in... Reasonable sampling
Air temperature minutes or hours every 1 to 10 min
Soil moisture hours every 10 to 30 min
Daylight minutes every 1 to 5 min
Distance of a moving robot tenths of a second tens of times per second

Measuring temperature every $10\ \text{ms}$ would be a mistake: the air doesn't change in that time and you would get hundreds of identical readings. Measuring it once a day isn't useful either: you wouldn't notice a heat wave at midday in time to open the ventilation.

Practice★★★Not started
Add a space counter to the parking lot barrier: a sensor at the entrance and another at the exit, a variable libres starting at $10$, and a "full" light. Describe the…

Add a space counter to the parking lot barrier: a sensor at the entrance and another at the exit, a variable libres starting at $10$, and a "full" light. Describe the program (what it adds and subtracts), what the barrier does when libres reaches $0$, and what error could cause the count to drift over time.

Solve
Practice★★★Not started
You are tasked with designing the control and logging system for an environmental station in a school greenhouse using a programmable board. a) Select three suitable…

You are tasked with designing the control and logging system for an environmental station in a school greenhouse using a programmable board.

  1. a) Select three suitable sensors to monitor plant conditions, classify them as analog or digital, and justify the ideal sampling rate for each (argue why measuring temperature every 10 ms would be a technical error and why measuring it once a day would be insufficient).
  2. b) Write the Boolean logic condition that simultaneously activates ventilation and automatic irrigation if the temperature exceeds 32 °C and soil moisture falls below 30 %.
  3. c) Reviewing the daily graphical log data, you observe that at 13:00 the light reading is at its maximum, but the temperature probe suddenly reads 0 °C for 15 minutes before returning to 28 °C. Interpret this anomaly, justifying whether it is due to a meteorological phenomenon or an instrumental fault (wiring/sensor).
Solve
Practice★★★Not started
A mobile robot programmed with Arduino works perfectly while connected to the computer via the USB cable (the wheels spin in the air and the program executes the entire…

A mobile robot programmed with Arduino works perfectly while connected to the computer via the USB cable (the wheels spin in the air and the program executes the entire sequence). However, when disconnecting the USB, powering it with a 4 AA battery holder (6 V) connected to both the board and the motors, and placing it on the ground, the following occurs: at the exact moment the motors try to start to overcome friction, the board's power LED flickers slightly, the robot gives a small jolt, and the program restarts from the first line in a continuous loop.

  1. a) Interpret and justify the physical-electrical cause of this failure: what happens to the motors' current demand at the moment of starting and how does it affect the voltage received by the microcontroller?
  2. b) Why did this problem not manifest itself while the robot was being tested connected via USB with the wheels off the ground?
  3. c) Propose and justify two technical modifications to the power supply circuit to definitively solve this problem and ensure the stability of the microcontroller.
Solve
Practice★★★Not started
You must design the autonomous control system for a library messenger robot that transports books between two stations (Table 1 and Table 2) following a line on the…

You must design the autonomous control system for a library messenger robot that transports books between two stations (Table 1 and Table 2) following a line on the floor. The complete cycle consists of: waiting for the start command via a push button, following the line until finding a transverse stop mark, stopping and alerting with a buzzer for 3 s, waiting for the user to remove the book (detected by a presence or weight sensor), and returning to Table 1 by performing a 180° turn to be ready for the next service.

  1. a) Identify the required sensors and actuators, classifying each as an input or an output.
  2. b) Design the system's state machine or flowchart, accurately indicating the robot's different states and what condition triggers the transition to the next state.
  3. c) Add a reactive safety protocol to the design: what sensor must you incorporate and how should the main loop act if a student crosses less than 20 cm in front of the moving robot?
Solve

Back to the beginning: Ximena's gate works because an ultrasonic sensor measures the distance, the board compares it with a threshold, and if there is a car it orders the servo to lift the gate; all in a loop that never ends.

Summary

See all the exercises in this section