Programmable Systems: Microcontrollers and Interfacing
What Is a Microcontroller?
A microcontroller is a small computer on a single chip. It contains a processor (to execute instructions), memory (to store the program and data) and a set of input and output connections — all on one integrated circuit. Microcontrollers run a program that reads sensor inputs, makes decisions and drives output devices. They replace large banks of discrete logic gates, making control systems compact, flexible and reprogrammable.
Common microcontroller families include the PIC (Peripheral Interface Controller — widely used in industrial and automotive applications) and development boards such as the BBC micro:bit and Arduino (used in school workshops and rapid prototyping). For this specification, flowchart examples are limited to three inputs and three outputs within an engineered system.
The microcontroller follows the input–process–output model. Sensors and switches are inputs; the microcontroller’s program is the process; actuators (motors, solenoids, LEDs, buzzers) are outputs. The program runs in a continuous loop: read inputs → make decision → set outputs → repeat.
Flowchart Programming
Microcontrollers are typically programmed using a flowchart program at GCSE level. A flowchart shows exactly what the microcontroller does at each step, making it easy to trace the logic before writing code. The standard symbols are the same four shapes from Lesson 1: oval (start/stop), rectangle (process), parallelogram (input/output) and diamond (decision).
A typical microcontroller flowchart for a temperature-controlled fan looks like this in sequence:
- START
- Read temperature sensor (ADC converts analogue output to digital number)
- Decision: is temperature above threshold (e.g. 30°C)?
- YES → Switch fan motor ON; loop back to “Read temperature sensor”
- NO → Switch fan motor OFF; loop back to “Read temperature sensor”
This loop runs continuously while the system is powered. The decision diamond and its YES/NO branches create the responsive behaviour. Changing the threshold value in the program immediately changes the system behaviour — no rewiring needed. This is a key advantage of programmable systems over fixed logic-gate circuits.
Discrete logic gates are fixed — once a circuit is built, its behaviour is determined by the physical wiring. Adding a new condition means redesigning and rebuilding the circuit. A microcontroller replaces all the logic gates with a program, so:
- Behaviour can be changed by reprogramming — no hardware changes needed.
- Multiple conditions and complex decision trees can be handled by a single chip that would require dozens of logic gates if built from discrete components.
- The same hardware platform (e.g. Arduino) can be programmed to control a fan, a door lock or a conveyor — reducing component variety and manufacturing cost.
- Timing functions (delays, PWM motor speed control) are built into the microcontroller — they would require separate timer ICs in a discrete circuit.
The ADC and Sensor Thresholds
Most real-world sensors (thermistors, LDRs, pressure transducers) produce analogue sensor outputs. The microcontroller’s internal ADC converts these to a digital number (typically 0–1023 for a 10-bit ADC). The program then compares this number to a sensor threshold: if the reading exceeds the threshold, the output is triggered; if not, it stays off.
Example: an LDR connected to a 10-bit ADC produces values from 0 (very dark) to 1023 (very bright). The program might set a threshold of 200: if reading < 200, switch on the lamp; if reading ≥ 200, switch off. Adjusting the threshold changes the light level at which the lamp triggers, without any soldering.
A sensor threshold is a number stored in the microcontroller program. The ADC converts the analogue sensor voltage into a digital value; the program compares this to the threshold and decides what action to take. Changing the threshold changes the system’s sensitivity without rewiring — this is a major advantage of programmable control over fixed logic.
Microcontroller output pins supply only a small current (typically 20–40 mA). Most actuators (motors, solenoids, lamps) draw far more current than this. Connecting a motor directly to an output pin would damage or destroy the microcontroller. An interfacing component is used to switch the larger current safely.
The two main interfacing components are:
- Bipolar junction transistor (BJT) — a small base current from the microcontroller controls a much larger collector-to-emitter current through the load. Think of it as a current-controlled switch. An NPN transistor is used with the load between the positive supply and the collector, and the emitter to ground.
- Field-effect transistor (FET/MOSFET) — a voltage on the gate terminal switches a much larger current through the drain-to-source path. FETs are voltage-controlled (not current-controlled like BJTs) and are preferred for driving motors and high-power LEDs because they can switch rapidly and waste very little energy when fully on.
A protection diode (flyback diode) is placed across an inductive load (motor, solenoid) in parallel to absorb the voltage spike that occurs when the device is switched off. Without it, the spike can destroy the transistor or FET.
Industrial Application: Pick-and-Place Machines
A pick-and-place machine on an electronics production line uses a microcontroller to control three outputs: a vacuum gripper (picks up components), an X-Y positioning motor (moves to target location) and a placement actuator (releases the component). Three sensors (position encoder, component-present sensor, placement-complete sensor) provide the three inputs. The microcontroller loops through its flowchart program hundreds of times per second, precisely coordinating all six connections. This is exactly the three-inputs, three-outputs model described in the specification.