12. Advanced control Systems

The micro:bit is an excellent device on which to build control systems. The facility to read analogue data from a range of different sensors makes it an extremely flexible device.

Feedback is an important concept in control systems. This is true even of biological control systems where it is known as homoeostasis. The purpose of the system is to keep the quantity being measured at a stable level or default value.

The control of glucose levels in the human body is a good example. As blood glucose levels rise the body secretes insulin. This causes the removal of glucose from the blood. As glucose levels fall below the default level less insulin is secreted so blood glucose levels rise.

Feedback control systems work as a closed loop in which the output has an effect on the input quantity being measured which in turn controls the output. Think of the thermostat that controls your central heating system. As the temperature rises above the default setting the thermostat turns off the heating. The temperature falls. Once the temperature falls below the default setting the thermostat will turn the heating on again and the temperature will rise.


There is an important concept that underpins such (homeostatic) control systems. If a single default value is used to switch an output on and off, this will never be satisfied so the system will continuously switch. To solve this problem two default values are used, an upper one and a lower one. The idea is that the system is kept somewhere between the two by introducing 'hysteresis' or a lag between the switching points.

Task:

To make an automated fan that will come on when the temperature exceeds a default value of 20 degrees Celsius. The fan must turn off when the temperature falls below the default value.


Algorithm:

When a button is pressed begin to monitor the temperature

Repeat forever

record the value of the thermistor

display the value

if the value is less than the default value

display the message 'too cold'

turn the fan off

if the value is greater than the default value

display the message 'too hot'

turn the fan on


Model:

The fan is a 3 volt motor with a plastic propeller attached.

The sensor is a thermistor.


PXT Editor script:


Analog input using a potentiometer


Learn about analog inputs using a potentiometer connected to the micro:bit from the

Written By: Cherie Tan

The picture below shows a potentiometer connected to a micro:bit. In this case the signal (sig) input is connected to pin0

The two scripts shown below, block code and python will take and display a reading at pin0 when button A is pressed.

Irrigation System

Follow the link below to access a video which outlines a feedback control system.

The system measures soil humidity and controls an irrigation pump to provide water to the soil when it is needed.

Irrigation system