One of the most important but often hidden everyday applications for computers (or just processors) is for sensing and control.
This is a subset of this is robotics.
The combination of micro processors with external electrical circuitry is sometimes known as physical computing.
A good example of computer control can be seen in car manufacturing.
The vast numbers of robotic systems are having an enormous impact on the world as shown in the videos below. The projects in this website illustrate many other practical problems which have been solved by automation.
Watch the videos below to see some other examples of computer control in action.
Because the control computer and the device it is controlling can communicate using radio waves there can be large distances between the two devices.
One of the most extreme examples of this is controlling the Mars rover, Perseverance from the Earth.
Things do not always go according to plan.
You should be familiar with the following and how to use them to build simple circuits:
Batteries and voltage (for control projects we use a range of voltages, typically, 3V, 5.5V, 6V and 9V to power them).
Current and resistance (the current depends on the voltage and resistance and a broad awareness of this is enough for most of the work on this website).
multistrand wire (do not buy single strand wire, it is not flexible enough), cutting and stripping insulation, making connections by twisting wire.
Short circuits (careless wiring and poor insulation planning leads to short circuits which quickly run batteries down. They can generate a great deal of heat particularly when working with 9V, leading to minor burns and even fire).
Polarity - positive and negative (components such as LEDs and buzzers have positive and negative polarity and have to be connected the right way round in a circuit or they will no work).
Soldering is not essential for most prototyping and project work - this comes later at Grade 7 and older.
For micro:bit work, you should acquire and practise these skills:
MakeCode IDE for block code editing and simulator testing your code Click this link and sign in
Downloading code to the micro:bit
Connecting components to the micro:bit for input and output
If you have never used a micro:bit before don't worry.
Learning how to use the micro:bit is child's play - literally.
The excellent turorials on the MakeCode website were designed for children to teach themselves by working through the clear instructions and experimenting with simple coding mini-projects.
Physical Computing and Robotics
Robotics is the use of physical computing to create automated systems that can operate without human intervention.
The micro:bit was specifically designed with the teaching of 'physical computing' in mind. Physical computing is the the connection of electronic components to a computer or procssor for the creation of sensing and control systems.
Key criteria for the micro:bits design were that it should be:
cheap - so schools can afford to purchase them in large numbers
easy to use and compatable with the sort of cheap electrical circuit components already existing in many schools
child-friendly and easy to use
well supported by a wide range of free resources and tutorials to teach and learn about coding and physical computing
robust so it is not easily damaged
low voltage to prolong battery life
supported by an excellent, simple to use, block based coding environment similar to Scratch
engaging and enjoyable to use with some useful built in sensors
The micro:bit more than meets these ambitious criteria and is now used in schools the world over.
Input components, switches, buttons and sensors (measuring such things as, sound, magnetic field, movement, temperature) feed data into the micro:bit's processor.
Output components, LEDs, buzzer, speaker, motors, servos, etc. make things happen outside the micro:bit's processor.
Connect an LED to a micro:bit and write some code using the red, Advanced, Pins, blocks to control the LED as follows:
Make it come on automatically.
Make it come on and then go off after a fixed time.
Make it flash 10 times.
Make it respond to an input so the LED will come on when button A is pressed and go off when button B is pressed.
The LED instructions will tell you how to attach and program an automated (robotic) LED.
Use the tutorials to work out make your micro:but do the following:
Make it come on for three seconds everytime the micro:bit is moved.
Make it respond to movement or a change in temperature.
If you have a micro:bit V2, make it play a tune when you clap your hands.
The LED has polarity, a positive 'leg' and a negative 'leg'.
If a component that has polarity such as a buzzer or an LED is connected the wrong way round it will not work.
When connecting a component (such as the red LED shown above) to the pins of the micro:bit to give a 3 volt output to the component note the following:
The crocodile clips are insulated to prevent short circuit.
The positive (longer) leg of the LED is connected to the control pin which provides the voltage (in this case pin 0).
The negative (shorter) leg of the LED is connected to GND, the negative side of the circuit.
A 220 ohm resistor has been added to the short, negative leg of the LED, to reduce the current so that it does not burn out the LED. As the output voltage from the micro:bit is only 3 volts the resistor is not really needed. It is important to protect LEDs with a 220 ohm resistor when using more then 3 volts.
When using crocodile clips connect them at 90 degrees with one jawspushed throught the hole in the pin for better grip.
If you have access 3D printer print out some micro:pegs for a quick and simple connection without the need for crocodile clips.
Create a sign in Click this link and sign in
Start the Tutoriak and work through it.
Scroll down to the Tutorials section and work through some of the tutorials - take your pick - to develop you Makecode
This is the MakeCode script to turn on the LED.
This script intorduces the comparator construct (coding skill) to test if button A has been pressed.
Button A is the input (data comes into the micro:bit).
Writing to digital pin P0 is the output (a voltage is sent to the LED to make it light up).
The code is put inside a forever loop so that it continuously repeats.
Before downloading your code, test it using the simulator to make sure it has no bugs (errors).
If there are errors in the code and it does not functvion as expected, then debug (correct) your code and then download it for testing with an LED.
The downloading process io send your code to a micro:bit is explained in one of the tutorials.
First but you will need to connect your micro:but to your computer using a download cable.
With three coloured LEDs, a piece of wood and some glue it is easy for learners to bult a traffic light model.
micro:pegs being used to connect a traffic light model
There are three outputs to control, one for each light.
The red wire of the red LED is connected to Pin 0
The red wire of the orange LED is connected to Pin 1
The red wire of the green LED is connected to Pin 2
All three black, negative, wires are connected to the GND pin.
The traffic light circuit built using crocodile to crocodile clips (note the LEDs share the same GND connection)
This script below can be used to test the lights but note that it is full of bugs and needs developing.
It is better pedagogy to give your pupils some ideas for a working program but leave some pieces out and some errors in and ask them to improve the program to make it work as required by the problem they are solving.
Reading and debugging code is a core skill at every level of program writing from the beginner to the expert coder.
As your pupil's knowledge and skills grow, then make them plan, test and improve their own programs from start to finish.
UK traffic light sequence
Now use the algorithm below to create a pedestrian crossing light.
Repeat forever:
Turn green light on
Wait 30 seconds (traffic can flow)
Turn green light off, turn amber light on
Wait 2 seconds
Turn amber light off, turn red light on
Wait 10 seconds (pedestrians can cross)
Turn amber light on
Wait 2 seconds
A logical development of this project is to add a button so that the traffic can flow continuously so long as no one is waiting to cross.
A pedestrian will have to provide the system with some data so that it changes the lights and stops the traffic.
You are going to connect a switch to use as the input device. If you do not have a switch make one with some drawing pins, a paperclip and two lengths of wire.
When connecting a switch to the pins of the micro:bit to provide an input:
One leg of the switch is connected to the control pin (in this case pin 0).
The other leg is connected to the GND pin.
Switches do not have polarity
Mark out a piece of card to match the template above (cut out the white hole).
Cut two squares of aluminium foil the same size as each yellow square in the template.
Strip 1 cm of insulation from each end of the 15 cm wires.
Splay the ends of one wire out and tape it to the edge of one piece of aluminium.
Splay the ends of the other wire out and tape it to the edge of the other piece of aluminium.
Place one piece of aluminium foil over the hole in the middle of the card and fold the left hand side of the card over the top of it to keep the foil in place.
Flip the card over and do the same on the other side.
The hole in the centre of the card should now have a piece of foil either side of it.
Tape around the edge of the card ‘sandwich’ to keep the foil in place.
You now have a homemade pressure sensor, the two wires are used to connect it to a micro:bit.
A hole in the middle layer of card allows the two layers of foil to touch
Notice the micro:pegs being used to connect the wires to the pins on the micro:bit
Pressure pad burglar sensor, microbit and alarm (buzzer)
The burglar sensing pressue pad is made using carboard, two wires and aluminium cooking foil.
The sensor has to be designed so that when pressure is applied to the pad, two pieces of foil are pushed together, completing a circuit.
This provides an input to Pin 0 of the micro:bit.
When the micro:bit receives an input from the sensor, it is programmed to sound an alarm.
Note, the buzzer has polarity so must be connected positive to positive and nagative to negative.
The alarm will continue to sound.
The alarm is reset by pressing button A and button B it the same time.
Notice, some lines of code are indented. This is to make the code more readable so keep the indents as they are.
turn buzzer on
if button A and B are pressed
if pressure pad is pressed
turn buzzer off
display text string 'Reset'
forever
display burglar detected icon
Rock, paper, scissors is a two player game. On a count of three both players display a hand signal of either scissors, a rock or a piece of paper.
Scissors beats paper, paper beats rock and rock beats scissors.
Program a micro:bit to create a computer version of the rock, paper, scissors game.
The flowchart below is the algorithm for the game.
It uses the on shaken input to play the game.
choice is a variable which is used to store a random number in the range 0 to 2, generated by the computer.
This script uses three comparators to compare the value of choice with the numbers 0, 1 and 2 in turn. E.g. If choice = 2 display the scissors sprite.
Flow chart algorithm
This is the MakeCode script for the rock, paper, scissors app.
The quickest way to create a script like this is to create one if statement and then duplicate it to create the other two.
This will introduce bugs to the code.
Remind your pupils that they must remember to edit the duplicated scripts to debug them.
This is a way of introducing some maths to STE(A)M by creating a device to record numerical data.
Problem - Create a people counter app for a doorman to use to keep track of the number of people inside a busy venue.
The flowchart below is the algorithm for a simple people counter.
count is a variable which keeps track of the number of people.
When the system starts, count is set to 0.
As a person enters the venue, the dorman presses Button A.
As a person leaves the venue, the dorman presses Button B.
This is the MakeCode script for the people counter app.