ULTRASONIC
Adding distance sensors to projects
Les Pounder merges two low-cost, yet complex ultrasonic sensors to create one must-have Pi-powered gadget that anyone can use.
OUR EXPERT
Les Pounder is associate editor at Tom’s Hardware and a freelance maker for hire. He blogs about his adventures and projects at bigl.es.
YOU NEED
>Pimoroni 4
Letter pHAT
>HC-SR04P
>DS18B20
>4.7K Ohm resistor
>Breadboard
>Four-pin screw terminal
>Pimoroni Hacker HAT
>5x M2F jumper wires
>2x M2M jumper wires
>Code: https:// github.com/ lesp/LXF-Four-Letter-Sensors/ archive/ refs/ heads/ main.zip OUR EXPERT YOU NEED
T he Raspberry Pi is blessed with a plethora of sensors, but there are two that sum up how easy it is to work with them on the Pi. Ultrasonic sensors measure distances using a pulse of sound. A little science and maths can give us fairly accurate distances, enabling our robots to “see” the world, and providing contactless user interfaces for projects. Temperature sensors, such as the DHT11, DHT22 and the DS18B20 are easy-to-use instruments for gauging temperature and humidity. The DS18B20 also has a waterproof variant that can be submerged in liquids (what’s the decay heat of a cup of tea, say?).
These sensors can be used to log data to graphs, databases or even used as inputs for a game. But in this tutorial we want quick hits of data, and for that we need a simple output device. This is where the trusty sevensegment display comes into its own. Pimoroni’s Four Letter pHAT is not a new HAT for rude words (I’m disappointed – Ed), rather we have four seven-segment LED displays that can be used to show alphanumeric characters. In this tutorial we’ll display the distance from an object, and the current temperature.