Introduction: Proximity Hat

Are you prone to hitting your head, like me.

Even though I am below the average height I still hit my head a lot, especially when working on projects by leaning forward or lifting up and hitting my head.

Because of this I decided to make a hat with a proximity sensor and alarm in it.

I used some of the codes and settings from this other ultrasonic sensor instructable. https://www.instructables.com/id/UltraSonic-Proxim...

Then added the code for an LED and modified it to fit in a hat.

Step 1: Materials

Are you prone to hitting your head, like me. Even though I am below the average height I still hit my head a lot, especially when working on projects by leaning forward or lifting up and hitting my head. Because of this I decided to make a hat with a proximity sensor and alarm in it.

Materials needed At least 2 basic or decorative Baseball caps or other hats, one needs to fit inside the other. $3 each at Hobby Lobby

Arduino Nano, I ordered a 3 pack from Amazon $12 https://goo.gl/EiGoRz

I had also already purchased a 37 pc sensor kit $28 https://goo.gl/Prsx9s

But all you need from the kit is an Ultrasonic Sensor https://goo.gl/Prsx9s Active Buzzer https://goo.gl/Prsx9s and power connector or inline switch.

1 or more LEDs, what ever color you like.

9 volt battery

Soldering iron and electric solder 22 gauge coated copper or F-M wires. I used these https://goo.gl/Prsx9s and just cut the ends off if not needed.

Hot glue gun and glue sticks

Around 2 feet of Velcro, the same color as the hats would be best. 3ft roll $1.49 at Hobby Lobby for the different colors.

Drill and Drill bit that is as close as possible to the diameter of the LED.

Step 2: Wiring the Adruino Nano

Ultrasonic Sensor (4 pins on sensor)

Using F-M or solder wire

Gnd -> GND----------------------solder the GND on the sensor to GND on the Arduino Nano

Echo -> D6 --------------------solder the ECHO on the sensor to D6 on the Arduino Nano

Trig -> D7 ----------------------Solder the Trig on the sensor to D7 on the Arduino Nano

Vcc -> 5V-------------------------solder the Vcc on the sensor to the 5V on the Arduino Nano

Buzzer

Positive lead -> D3----------------Solder the positive wire to the D3 on the Arduino Nano

Negative lead-> GND-------------Solder the GND wire to one of the GND on the Arduino Nano

LED

Solder the 220 resistor to the negative lead of the LED, then solder the other end of the resistor to the wire going to the Arduino Nano and solder this end to the GND on the Arduino Nano

Positive lead ->D2-----------------------------solder to D2 on Arduino Nano

For the exposed wire I used heat shrink tubing to protect the exposed wire from shorting out.

9 Volt (optional solder a 9 volt connector to the Nano board for ground and power) I used the power connector that came in my kit since it already had an on/off button.

It had an input from a standard 9 volt connector and usb out to the Nano.

From the power supply I used a basic usb connector that was very flexible to fit inside the hat.

Trim all excess wiring from the solder joints on the Arduino Nano.

Step 3: Preparing the Hat

To prepare the hat for the Ultrasonic sensor I first decided where on the hat the sensor would work best for me.

I found that having it towards the front of the hat would be best for me.

I held the Ultrasonic sensor on the outside of the hat and traced around the circular ultrasonic sensor barrels to mark where I needed to cut.

Then I cut out the holes in the hat using scissors and a razor blade.

Then I placed the ultrasonic sensor through the holes in the hat to make sure it fit.

After trimming it some I then hot glued the sensor in place from the inside of the hat making sure the barrels of the ultrasonic sensor are pointing outside of the hat.

Step 4: Other Components

Since we have already connected and soldered the other components of the sensor to the Arduino Nano we can now start hot gluing them inside the hat.

Depending on the components you use and the type of hats your layout may be different.

First I found the location for the Arduino Nano and glued it into place.

Followed by the Active buzzer then power connector.

The 9 volt is not glued in place since it will have to be changed.

Try to keep the wiring as flat to the inside of the hat as possible.

I then used the usb cable to hookup the power supply to the arduino nano but had to unhook it to program the nano, afterwards to worked great.

Step 5: The Code

Here is the code I used, I started with the code from

then added in the code for the LED

#define trigPin 7

#define echoPin 6

#define buzzer 3

int sound = 250;

int pin2 =2;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(buzzer, OUTPUT);

pinMode(pin2, OUTPUT);

}

void loop() {

long duration, distance;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

distance = (duration/2) / 29.1;

if (distance <= 30) {

digitalWrite;

sound = 600;

}

else {

digitalWrite;

}

if (distance < 25) {

digitalWrite;

sound = 400;

digitalWrite(pin2, HIGH);

delay(500);

digitalWrite(pin2, LOW);

delay(500);

}

else {

digitalWrite;

}

if (distance < 20) {

digitalWrite;

sound = 350;

digitalWrite(pin2, HIGH);

delay(500);

digitalWrite(pin2, LOW);

delay(500);

}

else {

digitalWrite;

}

if (distance < 15) {

digitalWrite; sound = 250;

digitalWrite(pin2, HIGH);

delay(500);

digitalWrite(pin2, LOW);

delay(500);

}

else {

digitalWrite;

}

if (distance < 10) {

digitalWrite;

sound = 50;

digitalWrite(pin2, HIGH);

delay(250);

digitalWrite(pin2, LOW);

delay(250);

}

else {

digitalWrite;

}

if (distance < 5) {

digitalWrite;

sound = 50;

digitalWrite(pin2, HIGH);

delay(250);

digitalWrite(pin2, LOW);

delay(250);

}

else {

digitalWrite;

}

if (distance > 30 || distance <= 0){

Serial.println("Out of range");

noTone(buzzer);

}

else {

Serial.print(distance);

Serial.println(" cm");

tone(buzzer, sound);

}

delay(500);

}

You should be able to copy and paste the code directly into the Arduino software.

I tested it on both the Arduino Uno Rev 3 and Nano Rev3

Step 6: Adding the Second Hat

To hide the electronics and wiring I used another hat inside of the main hat.

This also helped cover the wires for the LED and let me angle it down so it would be more visible when active.

I drilled a small hole in the brim of the second hat an inch or so from the end, make sure the hole is almost the same size as the LED so it can be pushed through it.

Next I hot glued Velcro on the inside of the blue upper hat and around the outside of the red inner hat.

This helps to hold the hats together and hide the wiring.

Step 7: Decorating the Hat

To decorate my hat, or to cover up my mistakes in cutting the holes for the ultrasonic sensor.

I used some steampunk inspired gears that I hot glued onto the hat and sensor.

Be careful of anything you put over the ultrasonic sensor because it can narrow the field of view of the sensor or cause false readings.

Step 8: Using the Hat

I placed a fresh 9 volt battery in my hat to start.

Once I have the battery installed and the arduino programmed I turn the hat on from the button on the power supply. I made sure that I knew where the button was since it is hidden by the inner hat.

After it is on it doesn't do anything unless you lean towards an obstacle or walk under something.

As long as nothing is within 1 foot or 30cm of the ultrasonic sensor nothing happens.

Bit when an object is detected within 30cm the LED light will come on and start flashing the closer the object gets, followed immediately by the buzzer going off. The tone of the buzzer changes as objects get closer.

Now this will not detect fast moving objects so it is not recommended for any fast moving objects or obstacles.

I will update as I try this with other materials.

Thank you for your time.