Inputs, Embedded Systems, and Automation
Analogue vs Digital Inputs
- Digital Inputs: Electrical signals that exist in only one of two discrete states—completely ON (
1, typically 3.3 V or 5 V) or completely OFF (0, 0 V). Examples include push buttons, switches, and digital motion sensors. - Analogue Inputs: Signals that vary continuously over time across an electrical range. Examples include light-dependent resistors (light level), thermistors (temperature), and potentiometers (rotational angle).
Because microprocessors operate only on binary numbers, an Analogue-to-Digital Converter (ADC) must sample the continuous analogue voltage and convert it into a discrete digital integer (such as 0 to 1023 for a 10-bit converter).
Embedded Systems
An embedded system is a dedicated computer built into a larger mechanical or electrical system to perform a specific dedicated control function. Examples include domestic washing machines, automotive anti-lock braking systems (ABS), and smart thermostats. They rely on microcontrollers integrating a CPU, memory, and programmable input/output pins on a single chip, built for low power draw and automated operation.
Automated Embedded Program (MicroPython)
In the Applied Learning Task 4 context, students use embedded code to read sensor data, store values, and control outputs automatically. The BBC micro:bit MicroPython module uses read_analog() (using the American spelling in code) to read pin voltages between 0 and 1023.
from microbit import *
readings = [] # list to store analogue data
for i in range(10):
level = pin1.read_analog() # analogue input: reads 0 to 1023
readings.append(level) # store the reading
sleep(1000) # wait 1 second between samples
average = sum(readings) / len(readings)
if average < 300: # threshold check for dark conditions
pin0.write_digital(1) # digital output: turn LED on
else:
pin0.write_digital(0) # digital output: turn LED offExecution Trace: If the ten recorded readings are [250, 260, 240, 255, 245, 250, 260, 240, 250, 250], their sum is 2500 and the average is . Because , pin 0 outputs a high voltage (1) and turns on the LED without human intervention.
