Ultrasonic Sensor

Ultrasonic Sensor Boards

If you connect a cheap 4 pin Ultrasonic Module as per this diagram, then you can safely connect it to your Pi BUT ONLY WITH THE RESISTORS IN PLACE

Using this arrangement in the diagramm you only need one spare GPIO pin to trigger it and receive the returned pulse.

So now you simply use it (assuming connected to pin 23)

Use Sonar23 followed by a wait 1 and then just use the sensor item sonar23 to get the distance measured in cm. Any pin can be used for this purpose and if you had several of them you could broadcast each of them in turn.
Alternatively, you can usebroadcast ultra23 which will tell your Raspberry Pi to continuously do a distance check every 1 second and update sensor item ultra23 with the results without any further need to do another broadcast