top of page
  • Writer's pictureKJ Ha

Invisible Distance

Inspiration


People all have their own personal boundaries. Although such boundaries are not readily visible by eyes, they have a significant influence on our social lives, helping us to maintain a healthy distance with others. I came up with a simple application that is analogous to the personal boundary using an ultrasonic distance sensor.


Execution


The ultrasonic distance is used as an input source to measure the distance between the sensor and the object. The measured distance is revealed by the three types of LED: red, yellow, and green. If the distance is larger than 20cm, the green LED will light up as a sign of a safety zone. If it gets shorter than 20cm but longer than 10cm, the yellow LED will light up as a sign of a mild warning. When the distance gets less than 10cm, the red LED will light up and it signifies that there might be a potential danger.


Schematic


Schematics.

Code


int trig = 12;

int echo = 11;

int redLed = 10;

int ylLed = 9;

int grLed = 8;


void setup(){

Serial.begin (9600);

pinMode(trig, OUTPUT);

pinMode(echo, INPUT);

pinMode(redLed, OUTPUT);

pinMode(ylLed, OUTPUT);

pinMode(grLed, OUTPUT);

}


void loop(){

long duration, distance;

digitalWrite(trig, LOW);

delayMicroseconds(10);

digitalWrite(trig, HIGH);

delayMicroseconds(10);

digitalWrite(trig, LOW);


duration = pulseIn(echo, HIGH);

distance = (duration/2) / 29.1;


if (distance > 20){

digitalWrite(redLed, LOW);

digitalWrite(ylLed, LOW);

digitalWrite(grLed, HIGH);

} else if (distance > 10){

digitalWrite(redLed, LOW);

digitalWrite(ylLed, HIGH);

digitalWrite(grLed, LOW);

} else {

digitalWrite(redLed, HIGH);

digitalWrite(ylLed, LOW);

digitalWrite(grLed, LOW);

}


Serial.print(distance);

Serial.println(" cm");

delay(500);

}





bottom of page