My Profile Photo

Adel Zaalouk

Researcher | Coder | DevOpsEr | IoTer | Organizer | Motto: \"To Live is to add value\"

The Super-Human Project: Distance-Sense

Alright, so recently I decided to use sensor for different applications. Sensors are a great way to hear, see, and even feel things that we as humans can’t see or hear. This post is the first in a long series to come about making, circuits, and the discovery of the world of things around use.

My latest project was to use an ultrasonic sensor to detect distance. This can have many applications, below you can find a GIF of the components:


So what are the components I used to make this happen:

  • A Pi, you can use any model, I used a 3B in my case
  • Male-Female (if direct connection from Pi), Male-Male Jumper Wires (if using a Cobbler)
  • An Ultrasonic sensor (normal or water-proof)
  • To regulate voltage output from the sensor to the input GPIO, you will need either a logic shifter from 5 to 3V, or build your own voltage divider and do the math (you will need resistors if you choose the voltage divider).
  • A breadboard (optional)
  • A Cobbler for a nicely structured board (optional)

The sensor has 4 main pins:

  • Vcc, thats your input voltage (if you chose 5v don’t forget to regulate!)
  • Gnd, thats your negative terminal
  • Trigger, to trigger the scavenge signal (or thats how I call it, more below)
  • Echo, to receive result from the scavenge signal, and notify the board.

How does an ultrasonic sensor work?

You do know that a bat is blind right, so how does this blind genius catch its prey? it simply has an ultrasonic built-in sensor.

First it triggers a sound signal to scavenge for preys. Once the sounds signal hits the poor un-lucky prey, it returns back to the bat. The bat then does some built-in biological calculations and knows exactly where the prey is.

The biological calculations are based on the below equation:

All what it needs to do is calculate the Round-Trip-Time (RTT), then divide by two to get the time to reach prey. Then the freaking genius bat just needs to plug this value of time, in the distance equation above to get the distance. If you are asking how does it know that the speed of sound is constant and has a value of 343m/s? well, besides being a genius, it happens to know how to use Google.

The code can be written in any pi-friendly language.

Have a nice Day!