10. Vehicles

This page outlines three vehicle projects of increasing complexity that I have used successfully with children in Years 6 to 9. 

They make an ideal context for a STEM/STEAM curriculum.


micro:bit Python Editor          

Pre-programmed vehicle

The pre-programmed vehicle is the simplest of the three projects. 

There is a need for vehicles that precisely follow a never changing route. This can then be programmed into the vehicle. Naturally safety devices and fail safe mechanisms will need to be added to the vehicle. These aspects of the project can be included as extension work to stretch your more able pupils.

Task:

To build and a robot vehicle that will, reliably and accurately, follow a predetermined route round a factory. 

Design brief:

The robot vehicle must make three circuits of the factory a day to deliver parts to the assembly lines. 

On reaching each production point (A to D) the vehicle must  pause while it is unloaded before moving on. 

Extension challenge:

The vehicle should sound an alarm the whole time it is on the move and a different alarm when it reaches each production point to announce its arrival.


The algorithm can be devised using an unplugged approach but as I am working with older children I prefer to teach the programming constructs and get the children to plan their program using Logo.

Algorithm:

Starting at D, facing up.

repeat 3 [fd 200  rt 90  fd 100  wait 50 rt 90 fd 100 wait 50 lt 90 fd 100 wait 50 rt 90 fd 100 rt 90 fd 200 rt 90  wait 500]


The model:

While it is possible to buy ready made vehicles and vehicle kits, these are much more expensive than vehicles built by the children and have nothing like the same impact with the children as vehicles that they have designed and built for themselves.

There is no need to buy an expensive kit. In fact the children will learn much more if they design and build the vehicle themselves. This is an ideal STEM project.

See the page on Motor Control for essential background information as well as the plans below for a self build line following vehicle. The same basic chassis can be used for all three  vehicle projects on this page.  The motors and swivel wheel mount were glued on with a hot glue gun.

For the the first two projects the model is simpler, not needing an LED and light sensors, it consists of:

> a rectangle sheet of 2mm MDF (12 x 20 cm)                                                                        

> two, 200:1 ratio, geared motors

> two 5 or 6 cm diameter wheels

> a swivel wheel

> 6V battery pack with switch

> Kitronic motor board

> two resistors

> a micro:bit

While it is possible to buy a reasonably priced 'kit' from Kitronik I am not in favour of basing STEM projects on kits.  The aim of a well thought out STEM curriculum should be to challenge children to come up with their own designs which they can build, test and improve. 

A kit does not provide anything like the same learning experience so does not teach STEM so effectively.

Note that the design on the right includes an LED and two LDRs. These are for the line following vehicle project and are not required for the PPV and the RCV projects. 

The vehicles in the picture below were all designed and built by Year 8 children who took great delight in individualising them. They were proud of what they had achieved and were able to take their models home to show friends and family. Children do not feel this sense of ownership when working with kits. 

Cost of self build models - under £10 (excluding cost of Kitronik motor board and micro:bit).

Motor control board

Note that the micro:bits shown controlling the vehicles in these pictures have been plugged into an additional motor control board (n this case one made by Kitronik). Motor control boards make it easier to connect components to the brass edge strip of the micro:bit. More importantly in this case they have enabled the pupils to boost the voltage powering the motors to 6 volts. The output voltage directly from the micro:bit is only 3 volts so not sufficient to power 6 volt motors and most servos.

There are two motor output terminals - Motor 1 and Motor 2:

Motor 1  is controlled by micro:bit output pins 8 & 12.  Pin 8 on, pin 12 off  will turn the motor in one direction.  Pin 8 off, pin 12 on  will turn the motor in the other direction. 

Never turn both pins on at the same time.


Motor 2  is controlled by micro:bit output pins 0 & 16. Pin 0 on, pin 16 off  will turn the motor in one direction.  Pin 0 off, pin 16 on  will turn the motor in the other direction. 

Never turn both pins on at the same time.


You will need to experiment as the direction the motor turns will depend on the way it has been connected to the motor terminal block on the control board. If the motor turns the wrong way, debug by either editing your code or switching the wires round on the motor terminal block.





Broken BeeBots:

Don't throw away broken BeeBots. Open them up, connect the motors to a Kitronik motor board, add a battery pack and micro:bit. You now have an excellent test chassis for vehicle control projects.

            Watch the video below to see it in action.


This is a partial block code script for the first part of the robot's route.


The algorithm can be summarised as:

repeat 3 [fd 200  rt 90]


Can you recreate this script using the MakeCode editor? You can switch between Block and Python code by clicking on the tanw


Or try coding a micro:bit using micro:bit Python by following the hint below.

micro:bit Python Editor          



#  Move forward(turn both motors on)

pin8.write_digital(1)

pin12.write_digital(0)

pin0.write_digital(1)

pin16.write_digital(0)

sleep(5000)

# Make a left turn (turn  Motor 2 off)

pin8.write_digital(0)

pin12.write_digital(0)

sleep(2000)

#  Move forward(turn both motors on)

pin8.write_digital(1)

pin12.write_digital(0)

pin0.write_digital(1)

pin16.write_digital(0)

sleep(5000)

# Make a left turn (turn  Motor 2 off)

pin8.write_digital(0)

pin12.write_digital(0)

sleep(2000)

Bugs, errors and faults.

Things in the world of physical computing rarely go according to plan. Not first time at least and particularly for beginners. Much of the learning comes from fault finding and correcting.

The most common faults are:


Remote control vehicle

Computer controlled vehicles are always a popular project with young children.  The radio controlled vehicle is a relatively simple project that has enormous impact.

Two micro:bits are needed for each vehicle, one is used as the hand held controller and the other is used to control the motor board.   Pin0 on the hand held controller is used to connect an ON/OFF switch.    

In my school the all of these vehicle projects are taught as STEM projects that combine an understanding of circuit electricity with programming knowledge and design and making skills.

Task:

To build a vehicle that can be driven remotely via a hand held device that uses wireless signals to communicate with the vehicle.


The link below will take you to a complete and self contained workshop designed to teach children how to programme a two vehicle, remote control, buggy using Python code.

Stop and reverse:

My pupils wanted to add two additional push switches, one to stop the vehicle and one to put the vehicle in reverse they added this script to the vehicles while True loop for a push switch connected  between pin1 and 3V (to stop the vehicle) and a push switch connected  between pin2 and 3V (to make it reverse).


    if pin1.read_digital() == 1:

        radio.send('st')

        sleep(50)

    if pin2.read_digital() == 1:

        radio.send('bk')

        sleep(50)

A corresponding script must be written for the motor board controller.

 

elif msgin == 'st':

# ------turn both motors off

pin8.write_digital(0)

pin12.write_digital(0)

pin0.write_digital(0)

pin16.write_digital(0)

sleep(50)

elif msgin == 'bk':

# ------turn both motors off

pin8.write_digital(0)

pin12.write_digital(1)

pin0.write_digital(0)

pin16.write_digital(1)

sleep(50)


Robot Wars Club


The micro:bit is an outstanding device for controling 'fighting robots'.  The video below was taken at a school Robot Wars club.

Your robot is eliminated if you are pushed out of the arena, immobilised or have your balloon popped.

Last robot standing wins!


Flippers and axes

Pupils in the Robot Wars club wanted to arm their robots by using a servo to add a flipper or an ax tp their fighting robots. The code below shows how the server can be programmed using micropython. It is also possible to program the server using MakeCode blocks. 

from microbit import *

import radio

radio.on()


def set_servo_angle(pin, angle):

    duty = 26 + (angle * 102) / 180

    pin.write_analog(duty)


angle = 90

set_servo_angle(pin1, angle)


while True:

    msgin = radio.receive()

    if msgin == 'flip':

        angle = 135

        set_servo_angle(pin1, angle)

        sleep(50)

    else:

        angle = 45

        set_servo_angle(pin1, angle)

        sleep(50)

N.B.  The angle will vary according to the position of the flipper on the vehicle - some experimentation will be needed.


To trigger the flipper, this code has to be added to the hand held controller's while True loop for a push switch connected  between pin1 and 3V.

if pin1.read_digital() == 1:

radio.send('flip')

sleep(50)

A much more sophisticated version of the RCV project.

Line following vehicle

Ongoing research and development into driver-less vehicles is constantly newsworthy and children are fascinated by the concept.

The LFV (line following vehicle) project is a very simple way of giving children an insight into the way feedback control systems can be employed in driverless vehicle technology.

See the plans at the top of this page for ideas on the construction of the models.



Task:

To build and program a vehicle that can drive itself by following a line drawn on the road surface.


Algorithm:

Repeat forever

     if light sensor left is off turn motor left off

     else turn motor left on

     if light sensor right is off turn motor right off

     else turn motor right on


Model:


A 6 volt battery pack is used to power the micro:bit and the motor board. 


Left side:

The left hand motor is connected to Motor 1.

The left hand LDR is connected between Input 1 (P1) and GND.

A resistor is connected to Input 1 between P1 and 3V to create a potential divider (I would not explain the functioning of a potential divider to KS3 children unless you are sure that they will understand) .


Right side:

The  right hand motor is connected to to Motor 2.

The right hand LDR is connected between Input 2 (P2) and GND.

A resistor is connected to Input 2 between P2 and 3V.

An LED is connected to Power to provide light for the two LDRs.

The image shows a test-bed circuit for the left side of the LFV. 

Note the fixed resistor across Input 1 to create a potential divider.  

The motor has a right angle 200:1 gear box. 

The LDR is pointed down to pick up light reflected off the 'ground'.

When testing, move this back a forth over the black line and experiment with different heights. 

When the LDRs are installed under the chassis you will need extra illumination from a bright, white LED.

Testing:

When testing, I find it simplest to use a strip of black insulating tape stuck to a light coloured table top. There must be strong contrast between the line and the colour of the 'ground'.

During testing, the LFV may not behave as expected as variations in the LDR, the distance between the LDR and the line, the light level in the room, the brightness of the LED, the line colour and the ground colour will all effect the value that needs to be set for the analogue inputs.


This is an excellent opportunity to teach the children about calibration. The optimum analogue input value can be found by:

A) Trial and improvement - keep adjusting the input value and testing until the LFV behaves as expected.

B) Adding a block to your program to print out the analogue input value. By  moving the vehicle from side to side, across the line, and making a note of the input values when the LDR is over ground and when it is over the line.  From these results you can determine the optimum analogue input vale to set in your control program.

C) Replacing the fixed resistor with a potentiometer. This will allow the sensitivity to be tweaked without the need to amend the code in the program.

D) Simple tuning can be achieved by adding small beads below the swivel wheel mount to raise the front of the vehicle slightly or by moving the LDRs up or down a millimetre or two. These are fine design improvements that the children should be making for themselves.


The algorithm shown below is the one used to control the LFV in the video clip above.  Note that the number hard coded into the script (in this case 900) will depend on the resistance of the LDR, how close the LDRs are to the floor surface and ambient light conditions. The actual number will need to be found (calibrated) by experimentation. 

The learners need to know about calibration. This skill is essential when designing analogue control systems.

Micro Python script:

from microbit import *


while True:

    if pin1.read_analog() > 950:

        pin8.write_digital(0)

        pin12.write_digital(0)  

    if pin2.read_analog() > 950:

        pin0.write_digital(0)

        pin16.write_digital(0)

    if pin1.read_analog() < 950:

        pin8.write_digital(1)

        pin12.write_digital(0)  

    if pin2.read_analog() < 950:

        pin0.write_digital(1)

        pin16.write_digital(0)