Introduction: Personal Space Meter

About: I am a queer, transgender, nonbinary, and mixed-race picture book writer/illustrator. As a young person, I didn’t have the words to explain the big feelings I had about my identity and relationships. It is so …



Distance in cm is displayed on the board based on readings from an ultrasonic sensor. When an object comes within 20 cm from the sensor, the buzzer sounds.


I have a friend who really doesn't like it when people get too close. I made this personal space meter that lets people know when they need to back off. It can also be used to measure distance in the dark.

Step 1: Getting the HC-SR04 to Work

Another Instructables user posted this 'ible on using the HC-SR04. Their 'ible uses an LED as a distance indicator. It was a great starting point, but I removed references to the serial monitor in the final version because I wanted this to work on battery. I've found that the LinkIt can be finicky because it needs the serial monitor to be open for the rest of the code to work if there are any references to the serial monitor. For testing purposes, go ahead and let the board print to the serial monitor

The HC-SR04 has 4 pins labeled: VCC, Trig, Echo, Gnd.

On your board:

  • Connect VCC to +5V
  • Connect Gnd to GND
  • Connect Trig to 8 //any digital port is okay, but this design uses 8
  • Connect Echo to 7 //any digital port is okay, but this design uses 7

On your computer, make a new Arduino sketch and paste:

#define trigPin 8 // declare pins used
#define echoPin 7 // declare pins used

void setup()
{Serial.begin(9600); //this reference to the serial monitor will later be commented out

pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);}

void loop()
{long duration, distance;

digitalWrite(trigPin, LOW);


digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1; //distance in cm

int out = distance;

Serial.println(out); //this reference to the serial monitor will later be commented out


Try it out:

Upload code, then open the serial monitor. Try moving a box or your hand closer or further from the sensor. Do the values change? If so, let's move on to adding a display.

Step 2: Using a 7-segment Display

Disconnect everything from the LinkIt and plug in the shield. The Shield is super convenient because it just fits right on top of the LinkIt. Match up the pins with the bottom of the board (there will be a couple extra inputs on the ports side of the LinkIt. This is okay.) There are some great examples already. This version is based on the SPI Basic example. Their version has a loop and the board acts as a counter. Try out their basic example to test out the functionality of the display.

After you have the display working, go ahead and plug the ultrasonic sensor into the same pins as the previous step. Add a buzzer with a ground wire connected to GND and the other wire connected to 3. Download and try the attached code.

Good luck! The finished Personal Space Meter should let folks know in cm how far away the nearest object is and beep when something is too close (<=20 cm, but you can change it in the code.)

Wearable Tech Contest

Participated in the
Wearable Tech Contest

Tech Contest

Participated in the
Tech Contest