Microcontrollers – sensors driving an LED and a motor

Design & TechnologyElectronics & MicrocontrollersAges 17–18

Use with my class

A circuit with a microcontroller, a light sensor, a push button, a temperature sensor, one LED and one small motor. Pick a sample program (auto light by brightness, timed blink, button toggle, or temperature-controlled fan), then drag the light or temperature slider or press the button to watch the microcontroller read the input, compare it with a threshold, and drive an output pin. The block-program panel highlights the instruction being executed, and the chart below logs the output state over time.

Lesson: Microcontrollers and applications: structure, digital input/output signals, sensors, actuators, and control programs

What it shows

A microcontroller is a small computer on a single chip that runs one program in an endless loop: read the inputs, make a decision, set the outputs. Here a light sensor, a temperature sensor and a push button feed its input pins, and output pins switch an LED or a small motor on (1) or off (0), while an internal clock times the blink program. Because each decision is a comparison written in the program, such as light below a threshold, changing one number in the code changes the device's behavior without touching the wiring. Automatic street lights and thermostats work on the same principle.

How to use

Pick a program with the Auto light, Blink, Push button or Auto fan buttons. In Auto light, drag the Light slider down past the Threshold and watch the LED switch on, the highlighted step in the block program and the output record over time; then move the Threshold slider and repeat. Try Auto fan with the Temperature slider, click Press button several times in the Push button program, and change Blink period to alter the blink frequency.

Parameters you can change

  • Sample program Auto light: LED on when light < threshold, Blink LED on a timer, Push button toggles LED, Auto fan: motor runs when temperature > threshold
  • Sensor threshold (% light or °C) 10–60
  • Blink period 200–3000 ms
  • Show program block diagram

Questions to explore

  1. In the Auto light program, which component is the input, which is the output, and what decision does the program make?
  2. If you raise the threshold from 30 to 50, does the LED switch on earlier or later as the light fades?
  3. With a blink period of 1000 ms, how long is the LED on in each cycle, and what is the blink frequency?