Hat Detector

So my interactive clothing was a hat to alert you of someone/something getting close to you. The sensor was a little small so things had to get pretty close to trigger it. When the trigger gets set too close, the light starts to blink for 10 seconds and then resets. This was originally set with three sensors to get back, left, and right, but I couldn’t get to the sensors in time, so it was only one sensor. I tried to make the bread board and arduino pack as small as possible on this project, but I need to work on better and faster connections. 

Code:

 

/*
 * HAT DETECTOR
 */
int disPin1 = 0;    // select the input pin for the distance finder
int ledPin1 = 9;   // select the pin for the LED
int disVal1 = 0;       // variable to store the value coming from the sensor
int tooClose = 0;
int count = 0;
void setup() {
  pinMode(ledPin1, OUTPUT);  // declare the ledPin as an OUTPUT
}
void loop() {
  if(tooClose = 0) {
    disVal1 = analogRead(disPin1);    // read the value from the sensor
    if(disVal1 < 50) {                //Turn off LED for low/no activity
       digitalWrite(ledPin1, LOW);
    }
    if(disVal1 > 50 && disVal1 < 550) {
       digitalWrite(ledPin1, map(disVal1, 0, 600, 0, 255));
    }
    if(disVal1 >= 550) {              //Set tooClose value
      tooClose = 1;
    }
  else {                              //Set LED to flash when too close.
       digitalWrite(ledPin1, 600);
       delay(250);
       digitalWrite(ledPin1, LOW);
       delay(250);
       count++;
       if(count = 10) {
         count = 0;
         tooClose = 0;
       }
  }
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s