Microcontrollers, flowcharts & programming
Engineering Science · National 5 · mrkellydt.co.uk
What you're learning in this topic
Learning intention WALT
We are learning about microcontrollers, flowcharts & programming, specifically to be able to:
- draw flowcharts with start/stop, input, output, decision and loop symbols
- use fixed loops, continuous loops and conditional loops
- write programs using high, low, pause, if…then, for…next
Success criteria WILF
- I can draw flowcharts with start/stop, input, output, decision and loop symbols
- I can use fixed loops, continuous loops and conditional loops
- I can write programs using high, low, pause, if…then, for…next
Microcontrollers
A microcontroller is a small programmable computer on a chip, with inputs and outputs, used in washing machines, microwaves, toys, traffic lights, car systems and industrial machines.
- Advantages over hard-wired circuits: reprogrammed without changing the circuit, so products can be changed or improved quickly; fewer components, so smaller, cheaper, quicker to assemble and more reliable (fewer parts to fail); one chip replaces many parts, so less stock and fewer resources used; can be reused, so less waste; can carry out complex sequences, counting and timing.
- Disadvantages: needs a computer, software and programming skills; software can be expensive; the chip can cost more than simple ICs; a fault in the program can stop the whole system; it may need driver circuits for high-current outputs.
Flowchart symbols
- Start / stop: rounded box (terminator).
- Output: parallelogram, e.g. "pin 7 on", "pin 7 off".
- Process / delay: rectangle, e.g. "wait 0.5 s". Always give a unit.
- Decision: diamond with Y and N exits, e.g. "pin 1 on?" or "repeated 6 times?".
Checking an input is a decision, not an output: the 2025 report saw input checks drawn as parallelograms. Give pin numbers and delay units, and make every loop arrow return to the right place.
Loops
- Continuous (infinite) loop: the program returns to the start forever.
- Fixed (finite) loop: repeats a set number of times, e.g. "for b0 = 1 to 15 … next b0", then carries on. The 2025 N5 report: most didn't name a fixed loop.
- A decision that loops back to itself waits for an input.
Program commands (PBASIC style)
main:
if pin1 = 1 then flash ' wait for the switch
goto main
flash:
for b0 = 1 to 6 ' fixed loop: 6 times
high 7 ' LED on
pause 500 ' 0.5 s (pause is in ms)
low 7 ' LED off
pause 500
next b0
goto main ' continuous loop
Other languages are fine (e.g. Arduino digitalWrite, delay). You won't be asked to write code from scratch, but you may read, complete or correct it, and flowchart answers must be detailed.
Design challenge: pedestrian crossing
The brief. Design the control for a crossing outside an Inverness primary school: traffic lights stay green until a button is pressed, then change to let people cross.
- Draw a flowchart for one complete cycle.
- Use a loop so the system keeps running.
- State suitable time delays for each stage.
- Write the program in PBASIC-style commands.
What a good answer includes
- Start, loop: check button (decision), then amber → red with the green man → amber → green.
- A continuous loop back to the button check.
- e.g. amber 3 s, red with green man 10 s; pause is in milliseconds (pause 3000).
- high/low for each output pin, if…then for the input, pause for delays, goto for the loop.
Key terms
| Decision symbol | Diamond with Y/N exits, used to test an input or a count. |
|---|---|
| Output symbol | Parallelogram, e.g. "pin 7 on". |
| Delay symbol | Rectangle with a time and unit, e.g. "wait 2 s". |
| Fixed loop | Repeats a set number of times. |
| Continuous loop | Repeats forever. |
| pause 500 (PBASIC) | A 0.5 s delay: pause is in milliseconds. |
| Advantage of a microcontroller | Reprogrammed without changing the circuit; fewer components. |
Quick check
1. Which is an advantage of a microcontroller over a hard-wired circuit?
- It needs no software to be written
- Fewer components, so more reliable
- It is always cheaper than any chip
- It never needs a driver for outputs
Show answer
2. Which symbol tests whether a switch is pressed?
- Parallelogram
- Diamond
- Rectangle
- Oval
Show answer
3. "for b0 = 1 to 15 … next b0" is a…
- Continuous loop
- Decision
- Fixed loop
- Delay
Show answer
4. In PBASIC, pause 2000 waits for…
- 2 ms
- 0.2 s
- 20 s
- 2 s
Show answer
5. An advantage of a microcontroller over a hard-wired circuit is…
- It can be reprogrammed without changing the circuit
- It never needs a power supply to run
- It works without any input devices
- It is always faster than a hard-wired circuit
Show answer
Printable worksheet
An I do, we do, you do worksheet for this topic, with a separate answer sheet.