David Hannaford's robot pages.


A robot needs sensors to be able to interact with its environment.

As humans we are familiar with touch, sight, hearing, taste, smell, balance and movement, temperature and various internal senses such as pain and hunger.

Here are some equivalent robot sensors that you may want to use:


A micro-switch or touch switch can be used to detect an object that is touched and is easily interfaced into an electrical circuit or microprocessor. Being just a single electrical on/off switch it is easy to use but provides limited information.

Force sensors typically provide a variable resistance or voltage based on the applied load. They normally exploit the piezzo electric effect to provide their output. Unfortunately they are quite expensive so are not normally suitable for hobby robots.

There are many pressure sensors available which measure the pressure of a gas or liquid. These can be used to provide touch by connecting them to a bladder with is squashed as the force is applied. They are still quite expensive but you may be able to salvage one from a tyre pressure gauge or other similar device.

Touch can also be detected by using capacitive or inductive effects. As two plates are pushed together the capacitance between them increases. Also by making a magnet move further into a coil its inductance will increase. Both of these effects can be measured and therefore exploited.


There are many ways of making a robot see, but the difficult part is interpreting what is seen. Let's consider active and passive devices

Active devices are typically where we send a beam of light out from the robot and detect what bounces back.

Our beam could be a LED or small laser such as the low power ones used in laser pointers, and it can be white, coloured (most commonly and cheaply red) or out of the visible spectrum (typically Infra Red).

Our beam may be fixed and wide or narrow, or may scan across and back like radar. A narrow beam will be able to more accurately detect a smaller object, but a wider beam will provide broader protection if it is just being used to check that the robot does not bump into an object ahead.

Using Infra Red provides some immunity to interference from the ambient natural light. Another means of achieving this is to modulate the beam with a specific frequency and filter the results coming back for that frequency. At the simplest level we can just measure the ambient light with the beam switched off and then again with it on and subtract one from the other to remove the effect of the ambient light.

To detect the beam coming back we will typically use a photodiode or phototransistor. A photodiode produces a voltage based upon the amount of light striking it, whereas a phototransistor which is usually more sensitive uses the incoming light to regulate the current flowing through it, which can then be used to vary the voltage across a resistor. In either case we can detect or measure this voltage to know that our beam has bounced back.

So what can we infer from this information? Certainly we can get an idea of the direction of an object - within the limits of the width of the beam, but as light travels very fast (at 186,000 miles per second) we cannot use the time for the beam to come back to us to measure the distance unless the objects are a long way away. However, if we have an idea of the reflectivity of the object being sensed we can measure the amount of returned light to get the distance. We can also use triangulation from more than one sensor or a sensor that detects where a spot of light appears on it to triangulate the distance.

Passive devices can include photodiodes and transistors as mentioned above, but also cover linear optical arrays, camera chips and similar devices. In essence they measure what they see at whatever level of detail this is. At a simple level a photodiode or phototransistor with a coloured filter in front of it can see an object of that colour, which can be useful in some applications. A photodiode or phototransistor can also detect the level of ambient light in the direction that it is pointing, which can be used to detect where the light is brightest, or spot a flashing light, or even just be used to know if it is day or night.

Linear optical arrays are in effect a line of phototransistors on one chip. They can have a few dozen detectors or hundreds but they will be read out serially. Optical arrays and camera chips always need some sort of lens in front of them to focus the image onto the detector. A linear array with a lens in front of it is often used for reading bar codes, but can also be used to "see" what is in front of it with a better resolution than just using a phototransistor. Having to read out all of the detectors in the chip serially means that it takes a lot longer to process the data from a chip and you have to use a microprocessor to do this, but it does give a lot more information about what is being seen. The line of sensors on an optical array chip can provide a full image if the sensor or the robot that carries it rotates.

Camera chips, in black and white or colour, at various resolutions will capture a lot of information about what they see, but take the most resources and are the most complex to interpret the data. Typically a camera chip will be able to feed up to 30 images per second and will deliver image levels and colour information (if present) on at least 76800 pixels (quarter VGA) per frame, so take quite a bit of processing power. If you have a mainly static image and are perhaps detecting changes between frames or just looking for clear simple outlines you have a chance of being able to do this in real time, but if you want to control a fast moving robot it is much easier if you can do it with active reflective sensors which you are likely to be able to read and processed around 30 times more frequently.


Whilst robots can easily be fitted with microphones the difficulty is, as it was with sight, in interpreting what is heard. If you have a need to detect a specific frequency sound or to differentiate between some simple sounds then this is feasible, but interpreting speech for instance is not viable currently beyond recognising simple commands.

Another use of hearing however is to use it actively as bats do to detect and locate objects. To do this we (and bats) use ultrasonics which are the frequencies (typically around 40 kHz or more) above those that people can directly hear.

A great advantage of using a beam of sound is that because sound travels relatively slowly (340m/sec) it is possible to not only detect approximate direction but also to obtain the distance from the object by measuring the time taken for the beam to return. An ultrasonic beam will travel to and back from an object 17cm away in one millisecond, which means that for objects up to about a meter away this is suitably fast and provides a very accurate assessment of distance. What you gain in accuracy of distance you lose in accuracy of direction as the beam spreads out quite a bit, but again if you want to be able to detect anything ahead of your robot this can be an advantage. Ultrasonic senders and receivers (typically sold in matched pairs) are quite cheap and very easy to interface to electronic circuits and microprocessors.

Taste and smell

Whilst there are a few chips that can detect specific substances or gases there is little here that is of use for most hobby robot builders.

Balance and movement

There are plenty of sensors available to help us to detect changes in speed or direction.

At the very simplest, motion detectors or tilt switches use mechanical methods to detect when a pendulum or liquid changes its position. These are often found as detectors in car alarms and are useful for monitoring basically static objects, but have limited use for a robot that is moving itself.

Speed of movement can be measured by a sensor on the drive system or a separate detector in contact with the ground. This sensor can be optical, magnetic or mechanical. Older PC mice have a rubber ball inside which rotates 2 axles at right angles, each of which has a slotted wheel attached to it. A light shines through the slotted wheel to provide a train of pulses for each axis. Components can be salvaged from old mice to attach to drive systems as sensors or similar items can be easily fabricated from a printed disk with lines on it, a phototransistor and a LED.

As well as using an optical disk you can get a similar effect with a small magnet and a hall sensor. This detects the change in magnetism as a magnet on the drive system rotates. It can even be set up to count the teeth passing a hall sensor on a metallic gear wheel.

Some electric motors have optical or magnetic encoders built into them which can provide a stream of between 1 and 512 pulses for every rotation of the motor shaft. These are normally pretty expensive but can occasionally be found on ebay or similar auction sites at reasonable prices. They provide a very compact solution which is easy to interface to microprocessors. Putting a sensor on the motor shaft is usually easy and gives more information than an equivalent one on the wheels if the drive is through some sort of gearbox, but more pulses need more processing so as always there is a case that more is not always better. The only problem with a speed sensor on the motor or on the drive wheels is that if the ground is uneven or the acceleration is high then the wheels may slip and you only get a reading of the motor wheel speed, not of the actual speed of the robot. Sensors on wheels that are not being driven have less problems but if you have an all wheel drive robot then you may not have this option avaialable.

Another way of overcoming this problem is to use an accelerometer. An accelerometer is an electronic device that, as its name implies, detects acceleration, i.e. it detects a change in speed in one direction. A 2 axis accelerometer will provide outputs from 2 accelerometers set 90 degrees apart, so are able to detect any change in speed within a plane. A 3 axis accelerometer add another one at 90 degrees to enable full directional motion change detection in all directions, up, down, forward, back and sideways. You probably only need a 3 axis device if you are building flying robotics.

Note, however that accelerometers only tell you about a change in speed, not the basic speed itself, so to derive current speed you need to repeatedly add up the readings to get an estimate of the current actual speed. Due to even small inaccuracies this is also likely to give errors when applied over a reasonable period of time.

A gyro tells you about rotation. Electronic devices are now available that give you direction, rate of change of direction and related parameters. These are small, easily interfaced to microprocessors and becoming cheaper. Accelerometers and gyros are what your Wii device uses in the paddle that you hold.


Temperature is easy to measure both with resistors that change their value with temperature or more specialised sensor chips. Temperature can be sensed remotely at short distances and could perhaps be used for instance to detect the difference between an inanimate object and a live one. Temperature sensors normally have quite slow response times up to several seconds so again are not very helpful for fast moving objects.

Pain and hunger

The nearest robot equivalents to pain and hunger are detecting faults, warning conditions and situations such as low power.

It is very useful to monitor the battery voltage if your robot is not connected to a mains supply. Some components will start to behave erratically or stop working if their voltage drops below given critical values and some rechargeable batteries will be damaged if current continues to be drawn when their voltage drops below specified values. If we detect this before it happens the robot can alert the owner to plug it in or it can find a power socket by itself or at worst case can shut itself down so that no or very little power is being drawn.

A lot of our robots will have a microprocessor using a regulated power supply at 3.3 or 5 volts and have an analogue to digital converting input. If we arrange for 2 resistors to be placed across the battery after the on/off switch to divide the battery voltage by 2 or 3 at the mid-point between the resistors, so that it comes below the microprocessor supply voltage then we can use an analogue to digital input to measure this voltage and initiate the required action when it drops below a critical level

Other warning systems can detect if motors are drawing too much current for too long - perhaps because a motor has stalled due to being unable to move whatever it is connected to, or because the robot has run into an object and doesn't know this. Sensors that tell us that actuators have reached the limit of their travel can also be useful to stop us trying to drive them further.