Social Distance Detector

As Richard Meier, a famous American architec, claims that 30 inch between two persons is the ideal distance to interact each other socially, I made a detector which  indicates the “social distance”.   Simply, it lights a  green LED  when the other person is about 30 inch away from you.  However, it lights a red LED on and green LED off when your opponent is too close(means YOU ARE TOO CLOSE!!), or there will be no LED lights on when the other person is too far away.    In addition, I wish there is a gender sensor so that if the other person has opposite gender and he/she comes close to you, then Arduino lights “Pink” LED on rather than red~~  :-)




* Arduino Code * 

  1. /*   -Social Distance Detector- 
  2. This is a distance detector which detects an object in about 30 inch and light a green LED, but it lights a red LED if it is nearer than about 20 inch.
  3. I used Arduino with a PING))) ultrasonic sensor from
  4. -Dae Hong Kim
  5. */
  6. int ultraSoundSignal = 5;  // ultra sonic signal pin.
  7. int ledGreen = 8; // LED green connected to digital pin 8
  8. int ledRed = 10; // LED red connected to digital pin 10
  9. unsigned long val;  //unsigned value for the length of pulse from sonic sensor
  10. void setup(){
  11.   Serial.begin(9600);  // set the braud rate to 9600
  12.   pinMode(ledGreen, OUTPUT);  // set digital pin for LED green as output
  13.   pinMode(ledRed, OUTPUT); // set digital pin for LED red as output
  14. } // end of setup()
  15. unsigned long getValue(){
  16.   pinMode(ultraSoundSignal, OUTPUT);  // switch sonic signal pin to output
  17.   digitalWrite(ultraSoundSignal, HIGH); // send high pulse
  18.   digitalWrite(ultraSoundSignal, LOW); // send low pulse
  20.   pinMode(ultraSoundSignal, INPUT); // switch sonic signal pin to input  
  21.   return pulseIn(ultraSoundSignal, HIGH);  // read a pulse on sonic signal pin. Returns the length of the pulse in microseconds.
  22. /* pulseIn() starts timing when the pin receives HIGH, then stop timing when it receives LOW.*/
  23. } // end of getValue()
  24. void loop(){
  25.   val = getValue();  // append the value of the pulse length to val
  26.   Serial.println(val);  // print the siganl value on the screen
  28.   if ((val >= 3000) && (val < 5000)){  // if object in front of the sensor is about 30 inch range, LED green on
  29.     digitalWrite(ledGreen, HIGH);
  30.     digitalWrite(ledRed, LOW);
  31.   }
  33.   else if (val < 3000){  // if object is less than about 20 inch, LED red on
  34.     digitalWrite(ledGreen, LOW);
  35.     digitalWrite(ledRed, HIGH);
  36.   }
  38.   else{  // if object is further away than, all the LED light off
  39.     digitalWrite(ledGreen, LOW);
  40.     digitalWrite(ledRed, LOW);
  41.   }
  43. }// end of loop()

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s