Programmable Control

N5 Engineering Science · Booklet 4b

← Back to N5 Engineering Science

What this topic is

A microcontroller is a small computer on one chip. It reads its inputs, follows a program and switches its outputs.

You plan the program as a flowchart, read it as numbered lines the way the exam prints it, then build it on an Arduino Uno and test it.

Slides and resources

Every lesson's slides, with and without answers.

Section 1 · Lesson 1

Microcontrollers Exam

A microcontroller is a small, programmable chip that controls a system. It runs a program stored in its memory. It reads inputs and switches outputs.

In the exam Advantages over hard-wired control, and wiring a microcontroller. 2021 Q7(b) · 2022 Q14(c) · 2023 Q9(d) · 2025 Q8(c) · 2026 Q13(e)

The exam's microcontroller

  • 8 pins: each one is an input or an output.
  • The I/O table in the question says which.
  • In our room: inputs on pins 2 and 3, outputs on pins 4 to 7.

Input (a switch or a sensor) → process (the microcontroller and its program) → output (a lamp, buzzer or motor).

The exam's microcontroller: an 8-pin block, pins 0 to 3 on the left and 7 to 4 on the right, between a 5 V rail and a 0 V rail. The Exam's Microcontroller 8 pins each an input or an output The I/O table says which In our room in: 2, 3 out: 4 to 7 5 V 0 V 0 7 1 6 2 5 3 4 microcontroller

Where you meet one

The booklet sorts examples into sectors. One of each:

A ticket machine at a railway station
Commercial: a ticket machine at a railway stationPhoto: Infrastorian, CC0, via Wikimedia Commons
Boxes moving along a packing-line conveyor
Industrial: boxes moving along a packing-line conveyorPhoto: SimónK, CC BY-SA 4.0, via Wikimedia Commons
The automatic doors inside a bus
Transport: the automatic doors inside a busPhoto: Leif Jørgensen, CC BY-SA 4.0, via Wikimedia Commons
A smart light bulb
Home: a smart light bulbPhoto: Danielrosehill, CC BY 4.0, via Wikimedia Commons

Hard-wired or programmable?

Hard-wiredProgrammable
Made offixed components and wiresa microcontroller and a program
The job isin the wiringin the program
To change the jobnew parts, new wiringchange the program
Hard-wired circuit: a resistor and an LDR divider feed a transistor through a base resistor; the transistor switches a lamp. The job is fixed by the wiring. Hard-Wired Control Hard-wired fixed components and wires The job is in the wiring Change the job new parts, new wiring 5 V 0 V LDR lamp
Hard-wired: the job is in the wiring.
Programmable circuit: a switch into the microcontroller's pin 2, a buzzer on pin 4, and a motor on pin 7 through a transistor. The job is in the program. Programmable Control Programmable a microcontroller and a program The job is in the program Change the job change the program 5 V 0 V 0 7 1 6 2 5 3 4 microcontroller switch buzzer M motor
Programmable: the job is in the program.

Advantages and disadvantages

AdvantageWhy
Reprogrammedchange the program, not the wiring
Re-usedone board, many products
Fewer componentsso more reliable, and faster to assemble
DisadvantageWhy
Needs a programmersomeone must write and test the program
Needs a power supplythe chip needs one to run
Harder to followyou cannot see the job by looking at the parts
Watch out: "easier to change" scores 0 on its own. So do "it is cheaper", "it is programmable" and "fewer components" with no reason. Say how: it can be reprogrammed, with no rewiring; it needs fewer components, so it costs less; one board can be re-used for a new job. (Marking instructions 2021, 2022 and 2025.)

Model answer

Describe two advantages of a microcontroller over a hard-wired circuit for a bus's doors. 2 marks

The door times can be reprogrammed with no rewiring.(1)
Fewer components, so the doors are more reliable.(1)

Wiring inputs and outputs

  • Input: a switch from 5 V to the pin. Pressed, the pin gets 5 V and the program reads it as on.
  • Output: from the pin to 0 V. Switched on, the pin gives 5 V, current flows and the buzzer sounds.
  • A motor needs a transistor. A pin gives a small current, about 20 mA. A motor needs much more.

The transistor driver: the base lead goes pin → resistor → base. The collector has the motor, with a diode across it. The emitter goes to 0 V.

Watch out: "driver" on its own scores 0. Say it is a transistor.

Wiring: a switch from 5 V into pin 2; a buzzer from pin 4 to 0 V; pin 7 through a base resistor to a transistor, which switches a motor with a diode across it. The Transistor Driver Base lead pin, resistor, base Collector motor, diode across it Emitter to 0 V 5 V 0 V 0 7 1 6 2 5 3 4 microcontroller switch buzzer M motor
Practice — exam style Booklet p.3

1. Describe two advantages of using a microcontroller rather than a hard-wired circuit to control a lift. 2 marks

Answer
Any two: it can be reprogrammed (for example new floor times) with no rewiring (1); it needs fewer components, so it is more reliable or cheaper to make (1); one board can be re-used for a different job (1). "Easier to change" on its own scores 0.

2. Explain why a microcontroller is used in an automatic washing machine. 2 marks

Answer
Cause: the program can be changed (1), effect: so new wash programmes can be added with no change to the circuit (1).

3. State why a transistor is connected between pin 7 and a motor. 1 mark

Answer
The pin gives only a small current; the transistor switches the larger current the motor needs (1). "A driver" on its own scores 0.
Section 2 · Lesson 2

Flowcharts Exam Assignment

A flowchart shows the steps of a program in order, using the six symbols in the data booklet. The exam asks you to complete a flowchart from an I/O table every year.

In the exam Completing a flowchart from an I/O table: every paper. 2021 Q13(b) · 2022 Q9(a) · 2023 Q8(a) · 2024 Q11(b)

The six symbols

All six are on page 6 of the data booklet.

SymbolNameIts job
Terminator symbolTerminatorStart or end of a program or sub-procedure.
Line symbolLineThe direction of flow. Arrows are needed going up or left.
Input / output symbolInput / outputSwitches an output, or reads an input. Give the pin.
Process symbolProcessAn operation, for example a delay. Give the unit.
Decision symbolDecisionA yes or no question. Label the paths Y and N.
Sub-procedure symbolSub-procedureRuns a separate section of program, then comes back.

Lines and arrows

  • Down or right: an arrow is not needed.
  • Up or left: an arrow is needed.
  • Every loop back: draw its arrow. The marking instructions mark it.

What goes in the box

BoxThe exam's way
Outputpin 7 on · pin 7 off
Input decisionpin 1 on?
Delaypause 0.5 s (always a unit)
Fixed loopx3?

The booklet writes the same boxes as Lamp (output, pin 13) ON, Wait 1 s (1000 ms) and count < 5?. Both score. Either way, every output has its pin and every delay has its unit.

Flowchart: start; pin 5 on, pause 2 s, pin 5 off, pause 2 s; a line back up with an arrow. Lines and Arrows Down or right an arrow is not needed Up or left an arrow is needed Every loop back draw its arrow: the MI marks it start pin 5 on pause 2 s pin 5 off pause 2 s
A loop back up always has its arrow.

The four structures

Continuous loop

Repeats for ever, until the power goes off. Drawn as a line back up, with an arrow.

Flowchart: start; pin 5 on, pause 2 s, pin 5 off, pause 2 s; a line back up to pin 5 on. Continuous Loop Repeats forever, until the power goes off Drawn as a line back up, with an arrow start pin 5 on pause 2 s pin 5 off pause 2 s

Fixed loop

Repeats a set number of times, then moves on. Drawn as a decision, x3?, with N looping back.

Flowchart: start; pin 6 on, pause 0.2 s, pin 6 off, pause 0.2 s; decision x3? with N back to pin 6 on and Y to end. Fixed Loop Repeats a set number of times, then moves on Drawn as a decision, x3?, N loops back start pin 6 on pause 0.2 s pin 6 off pause 0.2 s x3? N end Y

Time delay

The program waits for a set time. Outputs stay as they are while it waits.

Flowchart: start; pin 4 on; pause 10 s; pin 4 off; end. Time Delay A pause the program waits for a set time Meanwhile outputs stay as they are start pin 4 on pause 10 s pin 4 off end

Branch

A yes or no decision. Each answer has its own path, labelled Y and N.

Flowchart: start; decision pin 2 on? with N back to itself; Y to pin 4 on, pause 3 s, pin 4 off; back to the decision. Branch A decision yes or no Each answer its own path, labelled Y and N start pin 2 on? N pin 4 on pause 3 s pin 4 off Y

How the marks are given

  • Each output: on and off, in the right place (1)
  • Each input decision: Y, N, a loop and an arrow (1)
  • Each delay: right place, with a unit (1)
  • x3?: Y, N, and an arrow back before the repeat (1)
  • A loop to the start with an arrow, or an end (1)
  • All the symbols right (1)

The method

  1. Read the I/O table: which pins are in, which are out.
  2. Draw one box per bullet, in order, top to bottom.
  3. Turn each input into a decision, pin 1 on?, with Y and N.
  4. Turn each repeat into x3?, with an arrow back.
  5. Finish: loop to the start, or end. Check pins, units and arrows.

Worked example. Input: train sensor, pin 0. Outputs: lamps, pin 7; barrier motor, pin 6. When the train sensor is on, the lamps flash 4 times, 0.5 s on and 0.5 s off. The barrier motor then turns on for 6 s, then off. The sequence returns to the start. 9 marks

Answer
Flowchart: start; decision pin 0 on? with N back to itself; Y to pin 7 on, pause 0.5 s, pin 7 off, pause 0.5 s; decision x4? with N back to pin 7 on; Y to pin 6 on, pause 6 s, pin 6 off; back to the start. Worked Example: The Answer (9 marks) start pin 0 on? N Y pin 7 on pause 0.5 s pin 7 off pause 0.5 s x4? N pin 6 on Y pause 6 s pin 6 off pin 0 on?: Y, N, loop (1) pin 7 on, off (1) Both pauses, units (1) x4?: Y, N (1) Arrow back (1) pin 6 on, off (1) pause 6 s, unit (1) Loop to start (1) All symbols right (1)

pin 0 on?: Y, N, loop (1) · pin 7 on, off (1) · both pauses with units (1) · x4?: Y, N (1) · arrow back (1) · pin 6 on, off (1) · pause 6 s with unit (1) · loop to start (1) · all symbols right (1).

Task: order the flowchart

A warning lamp on pin 4 comes on for 4 seconds, then goes off, then the program stops. Tap the boxes into the right order. Two boxes lose marks: leave them out.

Booklet page 9, question 1, written the exam's way.

Build it in a simulator

NoSyntaxSim draws the same symbols. Each input or output box picks a pin from the hardware panel. Run Programme lights each box as it runs. It writes a delay as Wait 3000ms; on paper we still write pause 3 s.

Yenka builds the same flowchart with its own symbols. In class you use both, so you know both.

A flowchart in NoSyntaxSim: TRAIN_SENSOR = ON?, then LAMPS = ON, Wait 3000ms, LAMPS = OFF, beside the virtual microcontroller.
NoSyntaxSim V2 by Peter Strain (NoStrainSims), free and open to all.
Practice — exam style Booklet p.9–13

1. A car wash has a button on pin 1, a pump on pin 5 and a brush on pin 4. When the button is pressed, the pump runs for 20 s, then stops; the brush then runs for 30 s, then stops. The sequence repeats. Complete the flowchart. 6 marks

Answer
Flowchart: start; decision pin 1 on? with N back to itself; Y to pin 5 on, pause 20 s, pin 5 off, pin 4 on, pause 30 s, pin 4 off; then back to the decision.startpin 1 on?NYpin 5 onpause 20 spin 5 offpin 4 onpause 30 spin 4 off

pin 1 on? with Y, N, loop and arrow (1) · pin 5 on and off (1) · pin 4 on and off (1) · both pauses with units (1) · loop to the start with an arrow (1) · symbols (1).

2. State the programming structure: a sign flashes all day. 1 mark

Answer
A continuous loop.

3. State the programming structure: a bell rings 4 times, then stops. 1 mark

Answer
A fixed loop.
Section 3 · Lesson 3

Reading programs Exam

The exam prints a program as numbered lines. Each line is one box of a flowchart. You will be asked to read it: find a line, count the loops, say what a line does. You are never asked to write code.

In the exam Reading a program: 3 of the last 6 papers. 2022 Q9(b)(c) · 2023 Q9(c) · 2025 Q2

Task: read the program

A conveyor counts boxes. Read the program, then tap an answer to each question. Every answer tells you why.

  1. main:if input2 is off then main
  2. let count = 0
  3. label_1:switch on 7
  4. pause 1500
  5. switch off 7
  6. let count = count + 1
  7. if count = 8 then label_2
  8. goto label_1
  9. label_2:pause 2500
  10. goto main

1. Which line has a time delay?

2. How many times does pin 7 turn on?

3. Lines 3 to 8 make which type of loop?

4. What does line 5 do?

5. How long is the delay on line 9?

Task: trace it, pass by pass

Pin 4 should flash 3 times. Work through the program one pass at a time. Fill in the table, then check it. Then press Run it to watch each line.

  1. main:let count = 0
  2. label_1:switch on 4
  3. let count = count + 1
  4. switch off 4
  5. if count = 3 then label_2
  6. goto label_1
  7. label_2:end

Passcountcount = 3?Goes to line
1
2
3

Model answers

Describe the function of line 5 in the barrier program. 1 mark

It sends the program back to line 1, so it repeats for ever.(1)

Scores 0: "It goes to main." Say what that does.

Marking instructions, 2022 Q9(b).

  1. main:if input1 is off then main
  2. switch on 6
  3. pause 4000
  4. switch off 6
  5. goto main

Explain why lines 2 to 7 do not run 10 times. 2 marks

Cause: line 8 goes back to line 1, let count = 0,(1)
Effect: so the count resets and never reaches 10.(1)

The word so joins the cause to its effect.

Marking instructions, 2022 Q9(c).

  1. main:let count = 0
  2. label_1:switch on 7
  3. pause 300
  4. switch off 7
  5. pause 300
  6. let count = count + 1
  7. if count = 10 then label_2
  8. goto main
  9. label_2:switch on 5
  10. end
Watch out: loop back below the count. A goto that jumps above let count = 0 resets the count every time round, so a fixed loop never ends. Jump to the label just below it: goto label_1, not goto main.

Your turn: program to flowchart

Draw the flowchart for this program on paper. Check every pin, every unit and every arrow. Then open the answer.

  1. main:if input3 is off then main
  2. switch on 5
  3. switch on 4
  4. pause 2000
  5. switch off 5
  6. pause 1000
  7. switch off 4
  8. goto main
Answer
Flowchart: start; decision pin 3 on? with N back to itself; Y to pin 5 on, pin 4 on, pause 2 s; then pin 5 off, pause 1 s, pin 4 off; back to the decision.startpin 3 on?NYpin 5 onpin 4 onpause 2 spin 5 offpause 1 spin 4 off

Three ways to write one program

The same buzzer program, written the exam's way, the booklet's way and in Arduino C. Watch the times: the exam's pause 500 and Arduino's delay(500) are milliseconds. The booklet says 0.5 seconds.

The exam

main:
switch on 5
pause 500
switch off 5
pause 1000
goto main

The booklet

loop
high buzzer
pause 0.5 seconds
low buzzer
pause 1 second
end loop

Arduino C

void loop() {
  digitalWrite(5, HIGH);
  delay(500);
  digitalWrite(5, LOW);
  delay(1000);
}
Practice — exam style Booklet p.14

A car wash brush is controlled by this program.

  1. main:if input2 is off then main
  2. let count = 0
  3. label_1:switch on 6
  4. pause 3000
  5. switch off 6
  6. let count = count + 1
  7. if count = 4 then main
  8. goto label_1

1. State the line number that contains a time delay. 1 mark

Answer
Line 4.

2. State how many times pin 6 switches on each time input 2 comes on. 1 mark

Answer
4 times.

3. State the type of loop in lines 3 to 8. 1 mark

Answer
A fixed (finite) loop.

4. Line 8 is changed to goto main. Explain what happens to the brush. 2 marks

Answer
Cause: the program goes back to line 1 and line 2 sets the count to 0 again (1), effect: so the count never reaches 4 (1). The brush switches on once each time round, and keeps going while input 2 is on.
Section 4 · Lesson 4

Build, test and fix Assignment

On the Uno, the plan becomes real: NoSyntaxSim → Duino.app: Verify → Upload → build it. Then you test every job, fix what fails, and test again. The assignment asks for exactly this.

Pins The exam uses inputs on pins 0–3 and outputs on 4–7. Our Uno uses inputs 2–3 (pins 0 and 1 carry its USB link) and outputs 4–7. The booklet's code uses pins 13, 9–11 and 8.

Getting started on the Uno

Our boards are Elegoo Uno R3, a copy of the Arduino Uno. You program them in Duino.app.

  1. Open Google Chrome (or Edge) and go to duino.app. Safari and Firefox can't reach the USB port.
  2. Plug the board in with its USB cable. A light on the board comes on.
  3. Choose the board Arduino Uno. Check it every lesson: the wrong board means the upload fails.
  4. The first time you upload, Chrome asks which USB device to use. Pick the one that names Arduino, CH340 or USB Serial, then Connect.
  5. In the Code tab, delete the code that is already there, then type yours.

Verify before you Upload, every time. Verify (some versions say Compile) checks your spelling and punctuation without touching the board. Upload sends the program to the board and runs it. If Verify shows an error, it names the line: fix it first.

Anything after // is a note for people. The board ignores it. Delete the code and the board stops working; delete the notes and it works the same, but no one can follow it. Add your own notes to explain your thinking.

Which breadboard holes are joined+−abcdefghij123456
  • Row 3, holes a–e: joined to each other.
  • Row 3, holes f–j: joined to each other, but not to a–e.
  • The + rail: joined all the way down. So is the − rail.
  • The centre gap (blank strip) is not joined across.
Wire 5V on the Uno to the + rail and GND to the − rail first. To join two things, put their legs in the same row, on the same side of the gap.

LEDs and buzzers on the breadboard

  • Every LED needs a 220 Ω resistor in series. Without one, too much current burns out the LED, and can damage the pin.
  • The LED's long leg (+) goes towards the Uno's pin. The short leg, by the flat edge, goes through the resistor to GND.
  • An LED works only one way round. If it won't light, turn it round.
  • A resistor has no + or −. 220 Ω is red, red, brown, then gold.
  • A buzzer needs no resistor. Its + leg (marked +, longer) goes to the pin.

It won't upload, or it won't work

What happensCheck this
Upload fails, or "no board"Arduino Uno chosen? USB plugged in? Did you press Connect when Chrome asked?
Red error on VerifyRead the line number. Usually a missing ; or a misspelled word.
Uploaded, but nothing happensDid you press Upload, or only Verify? Verify only checks.
Nothing on the breadboard works5V to the + rail and GND to the − rail? Legs in the same row, on the same side of the gap?
One LED won't lightLong leg towards the pin? Its resistor reaching GND? Try it the other way round.
The buzzer only clicks with tone()It is an active buzzer: switch it with digitalWrite instead.

Worked example 1: the flashing lamp

A warning lamp flashes on and off the whole time the machine is on.

void setup() {
  pinMode(4, OUTPUT);
}
void loop() {
  digitalWrite(4, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  delay(1000);
}

setup() runs once: pin 4 is an output. Everything in loop() repeats for ever: that is the continuous loop. delay(1000) holds the lamp for 1000 ms, 1 s.

Wiring: microcontroller pin 4 through a 220 ohm resistor and an LED to 0 V. Worked Example 1: The Plan and the Wires start pin 4 on pause 1 s pin 4 off pause 1 s 5 V 0 V 0 7 1 6 2 5 3 4 microcontroller 220 Ω LED
Pin 4 → 220 Ω → LED → 0 V. The LED's long leg goes to the resistor.
Breadboard: a yellow lead from Uno pin 4 to a 220 ohm resistor and a red LED; the LED's link and the GND lead go to the minus rail.
Breadboard, with the Uno's pins along the top.

Worked example 2: traffic lights

The UK sequence: red; red and amber; green; amber; back to red. Red on 4, amber on 5, green on 6.

void setup() {
  pinMode(4, OUTPUT);   // red
  pinMode(5, OUTPUT);   // amber
  pinMode(6, OUTPUT);   // green
}
void loop() {
  digitalWrite(4, HIGH);
  delay(3000);
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, HIGH);
  delay(3000);
  digitalWrite(6, LOW);
  digitalWrite(5, HIGH);
  delay(1000);
  digitalWrite(5, LOW);
}

Three outputs, so three pinMode lines, and each LED has its own 220 Ω. Two outputs HIGH at once give the red and amber stage.

Flowchart in three columns: pin 4 on, pause 3 s, pin 5 on, pause 1 s; pin 4 off, pin 5 off, pin 6 on, pause 3 s; pin 6 off, pin 5 on, pause 1 s, pin 5 off; back to pin 4 on. Worked Example 2: Traffic Lights start pin 4 on pause 3 s pin 5 on pause 1 s pin 4 off pin 5 off pin 6 on pause 3 s pin 6 off pin 5 on pause 1 s pin 5 off 1 red 2 red + amber 3 green 4 amber
The same sequence as a flowchart, one column per two stages.
Wiring: pins 4, 5 and 6 each through a 220 ohm resistor and an LED (red, amber, green) to 0 V. Worked Example 2: The Wires 5 V 0 V 0 7 1 6 2 5 3 4 microcontroller 220 Ω red 220 Ω amber 220 Ω green pinMode(4, OUTPUT); pinMode(5, OUTPUT); pinMode(6, OUTPUT);
Breadboard: red, amber and green LEDs on Uno pins 4, 5 and 6, each with a 220 ohm resistor.
Breadboard, with the Uno's pins along the top.

Worked example 3: the darkness alarm

When it gets dark, the LED flashes 5 times, then the system keeps watching.

void setup() {
  pinMode(4, OUTPUT);
  // A0 is an analogue input: no pinMode
}
void loop() {
  int light = analogRead(A0);
  if (light < 300) {
    for (int i = 0; i < 5; i++) {
      digitalWrite(4, HIGH);
      delay(500);
      digitalWrite(4, LOW);
      delay(500);
    }
  }
}

analogRead(A0) gives a number from 0 to 1023. In the dark the LDR's resistance goes up, so A0 goes down. if (light < 300) is the branch. for (i = 0; i < 5; i++) is the fixed loop: i counts 0, 1, 2, 3, 4, which is five flashes.

Wiring: an LDR from 5 V to A0 with 10 kilohm from A0 to 0 V; pin 4 through 220 ohm and an LED to 0 V. Worked Example 3: The LDR on A0 5 V 0 V 0 7 1 6 2 5 A0 4 microcontroller LDR 10 kΩ 220 Ω LED analogRead(A0) a number from 0 to 1023 Dark LDR resistance up, A0 down light < 300 means it is dark
The LDR and 10 kΩ make a voltage divider into A0.
Breadboard: an LDR from the plus rail to the A0 column, a 10 kilohm resistor to the minus rail, and the LED on pin 4.
Breadboard, with the Uno's pins along the top.

Task: match the C line

Choose what each line of Arduino C does. Then check.

pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
delay(2500);
analogRead(A0)
for (int i = 0; i < 5; i++) { … }

Find and fix

Finding faults is called debugging. Change one thing at a time, then test again: change two things and you will not know which one fixed it.

  1. What should it do?
  2. What does it do?
  3. Which line?
  4. Change one thing.
  5. Test it again.

Debug build 1 should flash pin 4, 1 s on and 1 s off. It has 2 faults.

void setup() {
}
void loop() {
  digitalWrite(4, HIGH);
  delay(1);
  digitalWrite(4, LOW);
  delay(1000);
}
The faults
setup() is empty: add pinMode(4, OUTPUT);. delay(1) is 1 ms, not 1 s: it should be delay(1000);.

Debug build 2 should sound the buzzer on pin 7 for 2 s when the button on pin 2 is pressed. It has 2 faults.

void setup() {
  pinMode(2, INPUT);
  pinMode(7, OUTPUT);
}
void loop() {
  if (digitalRead(2) = HIGH) {
    digitalWrite(7, HIGH);
    delay(2000);
    digitalWrite(7, LOW);
  }
The faults
= sets a value; to compare, use ==: if (digitalRead(2) == HIGH). And loop() has no closing } after the if's own }.
Breadboard: a push button on Uno pin 2 with a 10 kilohm resistor to the minus rail, and a buzzer on pin 7.
Breadboard, with the Uno's pins along the top.

Test, amend, re-test

A pedestrian crossing: red until the button is pressed; then green and the beeper for 5 s; then back to red. One test for each job:

TestShould happenInitial resultPlanned amendmentRe-test
Pressred off, green onred off, green onnone
Wait 5 sgreen off, red ongreen off, red onnone
Beeperstops after 5 sstays onadd pin 7 offstops: pass

Say what you saw, by part. "It didn't work" names no part and no result. "The beeper stayed on after 5 s" does.

Final version. After the re-test, save it under a new name. The assignment asks for the final version.

Model answer

Suggest one improvement to the crossing. Justify it. 2 marks

Improvement: make the beeper pulse on and off,(1)
so blind pedestrians know when it is safe to cross.(1)

"Make it better" scores 0: it names no improvement and gives no reason.

Flowchart of the crossing: pin 4 on; wait for pin 2; pin 4 off, pin 5 on, pin 7 on; pause 5 s; pin 5 off, pin 7 off; back to pin 4 on. Why Engineers Test Job 1 red until the button is pressed Job 2 green and beeper for 5 s Job 3 back to red, beeper off start pin 4 on pin 2 on? N Y pin 4 off pin 5 on pin 7 on pause 5 s pin 5 off pin 7 off
The crossing as planned. The sim file below has a different fault from the table: test every job to find it.
Watch out: the exam never asks for code. "Candidates are not asked to write code in response to a programmable control question. However, if developing a flowchart-based program sequence, sufficient and appropriate detail is required, such as input and output pin numbers and a delay unit." (Course specification, p.9.) Arduino C is for the Uno. In the exam, draw the flowchart, with pin 4 on and pause 1 s.

Practical sheets and the sim file

To open the crossing, press Load Flowchart in NoSyntaxSim and choose the file.

Booklet check

Check your booklet work

Answers to Booklet 4b. Try each one first, then open it. The booklet's own pins (13, 8) are kept here, because the questions use them.

Task 1 — Microcontrollers in use (page 3)
ProductWhy a microcontroller suits it (any valid reason)
Microwave ovenRuns a timed sequence; reads the door switch and buttons; switches the heater, motor and lamp from one chip.
Traffic lightsA repeating timed sequence; the timings change by editing the program, not rewiring.
Robot arm in a factoryControls several motors in order from sensor inputs; reprogrammed for a new task.
Smart heating thermostatReads a temperature sensor, decides, follows a time schedule; settings change in the program.
Practice — Programming structures (page 7)
  1. A continuous loop repeats for ever, until the power is removed.
  2. A fixed loop repeats a set number of times, then the program carries on.
  3. A time delay pauses the program for a set time; the outputs stay as they are.
  4. A branch makes a yes or no decision, so the program follows one of two paths.
  5. A fixed loop (6 repeats).
  6. A continuous loop, with a branch inside it to test the sensor.
Practice — Flowcharts (pages 9 to 13)
  1. The missing process box: Wait 4 s (4000 ms).
  2. Wait 5 s (5000 ms); Wait 2 s (2000 ms); Buzzer (output, pin 8) OFF.
  3. LED (output, pin 13) ON; Wait 1 s; LED (output, pin 13) OFF; Wait 1 s. The question gives no pin: any pin scores, the same one on and off.
  4. The decision Pressed? (No loops back); Buzzer (output, pin 8) ON for 2 s (2000 ms); Buzzer (output, pin 8) OFF.
  5. count = 0; LED ON; Wait 0.5 s; LED OFF; Wait 0.5 s; count = count + 1; the decision count < 5? (Yes loops back, No goes to Stop).
Worked examples — Try changing this (pages 15 to 19)

Worked example 1. (1) Both delays 200: it flashes faster: 0.4 s a flash, so 2.5 times a second. (2) 100 on, 900 off: a short blink once a second. (3) The board only drives the pin named in the code, so pinMode, digitalWrite and the wire must all use the same pin.

Worked example 2. (1) Change the delay after green comes on: delay(3000) becomes delay(6000). (2) Yes, it still runs: // starts a comment, which the board ignores. (3) Nothing goes wrong: setup() still makes all three pins outputs. Swap the pins in the digitalWrite lines instead and the colours change places.

Worked example 3. (1) 300 to 600: it triggers more easily; it counts as dark at a brighter light level. (2) i < 10: the LED flashes 10 times. (3) < swapped for >: the alarm goes off in the light, not the dark.

Find and fix (pages 20 and 21)

Debug build 1. setup() has no pinMode(13, OUTPUT);. delay(1) should be delay(1000).

Debug build 2. digitalRead(2) = HIGH should be == HIGH. loop() is missing its closing }.

Practice — Programming in real life (pages 22 and 23)
  1. setup() runs once when the board starts; it sets which pins are inputs and outputs.
  2. loop() runs over and over, for ever, after setup(); it holds the main control program.
  3. digitalWrite(13, HIGH);
  4. pinMode(4, INPUT);
  5. 2.5 s (2500 ms).
  6. (4 marks) for count = 1 to 4 / high LED / pause 0.5 seconds / low LED / pause 0.5 seconds / next count / end. Repeats 4 times (1); LED on (1); LED off (1); both pauses 0.5 s with a unit, then end (1).
  7. (4 marks) setup(): pinMode(2, INPUT); pinMode(8, OUTPUT); loop(): if (digitalRead(2) == HIGH) { digitalWrite(8, HIGH); delay(3000); digitalWrite(8, LOW); }. Both pinMode lines (1); inside loop() so it repeats (1); if with digitalRead(2) (1); buzzer on, delay(3000), buzzer off (1).
  8. (4 marks) The question gives no pin: use any pin, the same in all three lines. setup(): pinMode(13, OUTPUT); loop(): digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); pinMode in setup (1); code inside loop() (1); HIGH then LOW (1); both delays 1000 (1).
Check yourself

Check yourself

Mixed quiz

Tap an answer. Every answer tells you why.

1. A microcontroller is…

2. Which advantage scores a mark?

3. On a flowchart, a diamond is…

4. Which delay box scores the mark?

5. A fixed loop…

6. In the exam's program, pause 750 waits…

7. A goto jumps above let count = 0. What happens?

8. In the exam, answer a programmable control question with…

9. Why does a motor need a transistor?

10. Which test-table entry is best?

Rate your confidence: the booklet's success criteria

R not yet, A getting there, G confident. Saved on this device only.

Recap

Recap and words

What loses marks

  • "Easier to change", "cheaper", "programmable" or "fewer components" on their own.
  • An output box with no pin: write pin 4 on, not "lamp on".
  • A delay with no unit: write pause 4 s.
  • A loop back with no arrow, or a decision with no Y and N.
  • "Goes to main" on its own: say what that does.
  • An explain answer with a cause but no effect: join them with so.
  • Answering a programmable control question in Arduino C.
  • "Driver" on its own: say it is a transistor, and why.

Glossary

Microcontroller
A small, programmable chip that controls a system.
Input / output
Input / output
A box that reads an input or switches an output. Give the pin.
Process
Process
A box for an operation, such as a delay. Give the unit.
Decision
Decision
A yes or no question. Its paths are labelled Y and N.
Terminator
Terminator
Start or end of a program.
Sub-procedure
Sub-procedure
Runs a separate section of program, then comes back.
Continuous loop
Continuous loop
Repeats for ever: a line back up, with an arrow.
Fixed loop
Fixed loop
Repeats a set number of times: a decision such as x3?.
Label
A name for a line, such as main: or label_1:, so goto can jump there.
Arduino C
The code the Uno runs: setup() once, then loop() for ever.
Transistor driver
Lets a pin's small current switch a motor's large current.
Debugging
Finding and fixing faults: change one thing, then test again.

Where this comes up next

Sources & credits: the text, programs, flowcharts, wiring and breadboard drawings are by R Stewart, written for Booklet 4b. Past paper references, marking instruction wording and the course specification © Qualifications Scotland (SQA). Photos via Wikimedia Commons: Infrastorian (CC0), SimónK (CC BY-SA 4.0), Leif Jørgensen (CC BY-SA 4.0), Danielrosehill (CC BY 4.0). NoSyntaxSim V2 by Peter Strain (NoStrainSims). R Stewart - October 2026.