Introduction: Proximity Sensing Hat

You will need:

  • 220-ohm resistor
  • Ultrasonic sensor
  • Arduino Uno board
  • 9 Volt Battery
  • Breadboard
  • Electrical tape or other fasteners
  • Jumper wires
  • Ziplock bag
  • Beanie
  • Needle and Thread

Step 1: Testing Your Equipment and Breadboarding

Before beginning the project it would be a good idea to first test your vibration motor and ultrasonic sensor separately. Calibrating the ultrasonic sensor ahead of time will also save you some trouble with the coding process. After confirming that all sensors work properly, you can move on to the breadboarding. I chose to solder the wires of my vibration motor to some stripped jumper wires in order to give it more stability. I also ordered breadboarding wire to cut down on the amount of loose wire that will need to be hidden inside the beanie.

Step 2: The Code

#include 
#include
#define trigPin 11
#define echoPin 10
#define motor 9
void setup() {
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin,INPUT);
    pinMode(motor, 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) && (distance<80))
  {
    analogWrite(motor, 80); 
  }else if(distance<30)
  {
    analogWrite(motor, 160);
      }else if(distance>80)
  {
       analogWrite(motor, 0);
  }delay(500);
}

Step 3: Assembly

After ensuring that the code works properly, you may begin to assemble the headgear by first securing the wires and placing the components into a ziplock bag with holes cut out for the sensor and battery port. I chose to use this beanie for the project because it has a large band that goes around it which allowed me to hide the components inside of it. Be sure to cut out holes in the headgear for the sensors as well. If you happen to cut away too much fabric, or just need some extra security, now would be the time to use the needle and thread. By sewing in between the sensor and through to the inside I was able to make my sensor secure enough to get accurate readings but flexible enough to move with the hat.