Automated Social Distancing Tin Foil Hat

Introduction: Automated Social Distancing Tin Foil Hat

Are you paranoid about catching covid? Need to get groceries

before the store closes in an hour but not looking forward to the crowds? Fear not, this hat uses and ultrasonic sensor and Arduino uno to alert you and others when they are too close and need to back away. it even rotates to makes sure you are protected from all angles (while looking fabulously ridiculous with a spinning robot on your head).

the hat is made out of mostly household materials besides the electronics and can be built in short period of time. I consider it version 1 and eventually plan to make an updated version with more permanent parts and a pir sensor.

As of now, the ultrasonic sensor sits on the rotating servo on top of the hat scanning for close objects. If someone is too close, it will light leds and make buzzing noises. The lights are places behind signs on the hat warning people to back away when they turn on. You can use more or fewer leds than the suggested depending on your preference.



1. Arduino Uno

2. 9g Micro Servo

3. 1K Ohm Resistor

4. 9v Battery and clip

5. Ultrasonic Sensor - HC-SR04

6. LED - Basic Yellow 5mm X2

7. LED - Basic Red 5mm x3

8. LED – Basic green 5mm

9. switch

10. 330 Ohm Resistors

11. Npn transistor

12. Passive buzzer

13. BreadBoard

14. Jumper Wires Pack - M/M

hat materials and tools:

1. 3 plastic containers

1 round head-shaped one,

one small rectangle large enough to fit the uno and breadboard, at least 4 in,

one larger rectangle that will fit over the circular container

2. Tin foil

3. Tape

4. Glue

5. Foam board

6. Paint

7. Translucent plastic sheets

8. Scissors

9. Soldering iron (optional)

2. Building the circuit

Step 1: Building the Circuit


of these parts I left on breadboards but you can solder or not solder whatever is convenient for you. I originally planned to use an Arduino nano to save space, but unfortunately, the package is still on its way. The schematic shows only one led of each color, but I attached more in parallel to go behind the warning signs in front of the hat. I also added a switch and leads to the battery to fit with the Arduino.

Step 2: The Code

The ultrasonic sensor sits on top of the rotating servo so that it can scan the entire area around you. If someone is close but not too close, the yellow leds will light and a low tone buzz goes off. If they get even closer, the servo stops and the sensor focuses in on them, emitting a louder beep and lighting the red leds. Distance is calculated in cm and can be adjusted to personal preference.


Servo myservo;

int servopin = 9; //servo

int pos = 0;

const int trigPin = 11; //trigger

const int echoPin = 10; //echo

int rledpin = 8; //red leds

int yledpin = 7; //yellow leds

int gledpin = 6; //green led

int buzpin = 5; //buzzer

int x;

long duration;

int distance;

void calcDistance(void);

void setup() {

// put your setup code here, to run once:


pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output

pinMode(echoPin, INPUT); // Sets the echoPin as an Input


pinMode(gledpin, OUTPUT);

pinMode(yledpin, OUTPUT);

pinMode(rledpin, OUTPUT);

digitalWrite(gledpin, HIGH);

pinMode(buzpin, OUTPUT);


//--------------function calculates distance and controls lights and buzzer depending on results

void calcDistance(){

digitalWrite(trigPin, LOW);


digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance= duration*0.034/2;



if(distance >= 300){

//ledonpin = gledpin;


digitalWrite(rledpin, LOW);

digitalWrite(yledpin, LOW);


if(distance>150 && distance<300){

//ledonpin = yledpin;


digitalWrite(rledpin, LOW);

digitalWrite(yledpin, HIGH);

tone(buzpin, 800, 1000);



if(distance <= 150){

//ledonpin = rledpin;

Serial.println("TOO CLOSE");

digitalWrite(rledpin, HIGH);

digitalWrite(yledpin, HIGH);

tone(buzpin, 1500, 1000);


if(x == 0){//if the obect is too close, the servo stops rotating until it is further away

pos = pos-15;



pos = pos+15;





void loop() {

for (pos = 0; pos <= 180; pos += 15) { //goes from 0-180 stopping every 15 degrees to calulate distance








for (pos = 180; pos >= 0; pos -= 15){









Step 3: Make the Hat Base

The hat uses three plastic tins, one to fit your head, which should probably be somewhat circular in shape, a small square one to hold the electronics, and a larger square one to display the signs over the circular tin. Use tin foil for decoration and to make the circular hat fit snug.

to make the signs:

the signs will go on the front of the hat. Take some translucent plastic (I used plastic cut out of a cat litter box) and write whatever social distancing message you want to show. Paint around the outline of the letters with light paint and when the lights turn on it will better illuminate the letters.

Step 4: Prepare to Put the Circuit in the Hat

First stack the battery on the Arduino, I cut out a foam board guide to hold it and keep it from touching other components.

Next place the breadboard on top, move the wires around so that everything fits neatly together, it may take some playing with. Its goot to cluster the leds in front so they are visible and leave an open space on the board for where the servo will go.

Step 5: Put the Circuit in the Hat

Cut a hole in the top of the small plastic box so that the servo and leds stick out and the base of the Arduino sits on the top of the larger plastic container. Run the wires for the servo, yellow leds, red leds, and ultrasonic sensor through the hole.

Put the sensor on top of the servo. I glued a foam board guide to the servo and attached the sensor with a rubber band, although feel free to use something more permanent.

for the finishing touches, glue the signs on the front of the rectangle parts of the hat. Curve them a bit so that there is room for the leds behind them.

Step 6: Wear the Hat

That’s it! Put the hat on, flip the switch and look wonderfully paranoid with your glowing, beeping, automated social distancing hat!

thanks, and let me know if you have any questions, comments, or suggestions!

Silly Hats Speed Challenge

Participated in the
Silly Hats Speed Challenge

Be the First to Share


    • 3D Printed Student Design Challenge

      3D Printed Student Design Challenge
    • Metal Contest

      Metal Contest
    • Make it Move Challenge

      Make it Move Challenge



    1 year ago

    Ha! Very nice, and functional too! : )