Using Sensors with a Raspberry Pi
Individual Component Sensors
- A passive infrared sensor or PIR detects movement. You have probably seen these before. You will most often find them in the corners of rooms for burglar alarm systems. Every object whose temperature is above absolute zero emits infrared (IR) radiation. The sensor measures the IR signature of the room it’s in, and then watches for any changes. Any object moving through the room will disturb the IR signature, and will cause a change to be noticed by the PIR module.
- A Light Dependent Resistor or photocell is a component whose resistance will change depending on the intensity of light shining on it. It can therefore be used to detect changes in light. They are commonly used with street lighting, to make streetlamps turn on when it gets dark at night and off when it gets light in the morning.
- An air quality sensor is used to determine air quality by detecting polluting gases. When air enters the sensor, it is energised by a small heater which allows its electrical resistance to be measured. This is done by passing a low level of electricity across a small gap of energised air. The more contaminated the air is, the less resistance it has and the better it will conduct electricity. The output of the sensor is therefore an analogue voltage that goes up and down according to how contaminated the air is. The more contaminants, the lower the potential difference (voltage) across the sensor.
Want to keep
Raspberry Pi Foundation online course,
Teaching Physical Computing with Raspberry Pi and Python
- A gyroscope measures the orientation of an object. You may have seen a large one as a desktop toy. It has three separate axes pointing in different directions, so it can detect turning in all three directions. On a boat these directions are called pitch (the front of the boat rocks up and down), yaw (the front of the boat swings left and right), and roll (the boat rolls so that the right side is higher or lower than the left).
- An accelerometer measures an object’s increase in speed (acceleration). At rest, it will measure the direction and force of gravity, but in motion it measures the direction and force of the acceleration acting on it — as if you were swinging it around your head on a rope. Because accelerometers can detect the direction of gravity, they are often found in devices that need to know when they are pointing downwards, such as a mobile phone or tablet. When you turn the screen sideways the accelerometer inside detects that the direction of gravity has changed, and therefore changes the orientation of the screen.
- A magnetometer is used to measure the strength and direction of a magnetic field. Most often they’re used to measure the Earth’s magnetic field in order to find the direction of North. If your phone or tablet has a compass, it will probably be using a magnetometer to find North. They are also used to detect disturbances in the Earth’s magnetic field caused by anything magnetic or metallic; airport scanners use them to detect the metal in concealed weapons, for instance.
- A temperature sensor is used to measure hot and cold. It’s exactly like the thermometer that you would put in your mouth to take your own temperature, except it’s an electronic one built into the Sense HAT and reports the temperature as a number in Celsius.
- A humidity sensor measures the amount of water vapour in the air. There are several ways to measure it, but the most common is relative humidity. One of the properties of air is that the hotter it is, the more water vapour can be suspended within it. So relative humidity is a ratio, usually a percentage, between the actual amount of suspended water vapour and the maximum amount that could be suspended for the current temperature. If there is 100% relative humidity, it means that the air is totally saturated with water vapour and cannot hold any more.
- A pressure sensor (sometimes called a barometer) measures the force exerted by tiny molecules of the air we breathe. There’s a lot of empty space between air molecules, and so they can be compressed to fit into a smaller space; the more air is squeezed into a space, and the smaller the space, the higher the pressure. This is what happens when you blow up a balloon. The air inside the balloon is slightly compressed and so the air molecules are pushing outwards on the elastic skin; this is why it stays inflated and feels firm when you squeeze it. Likewise, if you suck all the air out of a plastic bottle, you decrease the pressure inside it, and so the higher pressure on the outside crushes the bottle.
Explorer HATThe Explorer HAT add-on board for the Raspberry Pi has useful input and output components built in as well as some useful sensors. In particular, it has eight capacitive touch pads.
- A capacitive touch sensor detects when the metal pads connect with a person or object carrying a small electrical charge. Touching one of the eight capacitive touch pads on the Explorer HAT triggers an event, just like pressing a switch or button. Anything conductive, such as plants, fruits, and graphite pencils, can be attached to these sensors and become buttons.
Teaching Physical Computing with Raspberry Pi and Python
Our purpose is to transform access to education.
We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.
We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.