Introduction: LED Distance Sensor

If you are interested in how does the reversing radar work, you can make yourself an ultrasonic reversing radar program. It's an easy one to make. Also, you can make it into different kinds of Distance Sensor.

Step 1: What You Will Need

An Arduino Leonardo

An Ultrasonic

Three LEDs

Eight Circuits

Step 2: Where Should the Wire Stay

Step 3: Find a Box to Put In

Any box you find can do it, but it must fit in the Arduino and the ultrasonic. Whatever it is large or tiny, as long as the Arduino won't break make it as you like.

Step 4: Coding

Here is my code, and you also can look it on here

https://create.arduino.cc/editor/nc29/e901a9ee-663...

int UltrasonicSensorCM(int trigPin, int echoPin) //Ultrasonic Sensor Code Auto Generated Return CM max distance 200{

long duration;

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(20);

digitalWrite(trigPin, LOW);

duration = pulseIn(echoPin, HIGH);

duration = duration / 59;

if ((duration < 2) || (duration > 200)) return false;

return duration;

}

void setup(){ // put your setup code here, to run once:

Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

digitalWrite( 11 , LOW ); //set ultrasonic sensor trigPin

pinMode( 2 , OUTPUT); // sets the digital pin as output

pinMode( 3 , OUTPUT); // sets the digital pin as output

pinMode( 4 , OUTPUT); // sets the digital pin as output

}

void loop(){ // put your main code here, to run repeatedly:

Serial.print( UltrasonicSensorCM( 11 , 12 )); //print message

Serial.print(" "); //print a blank

Serial.println();

if ( UltrasonicSensorCM( 11 , 12 ) > 10 ) {

digitalWrite( 2 , LOW ); // sets the digital pin on/off

digitalWrite( 3 , LOW ); // sets the digital pin on/off

digitalWrite( 4 , LOW ); // sets the digital pin on/off

}

if ( UltrasonicSensorCM( 11 , 12 ) < 10 ) {

digitalWrite( 2 , HIGH ); // sets the digital pin on/off

digitalWrite( 3 , HIGH ); // sets the digital pin on/off

digitalWrite( 4 , HIGH ); // sets the digital pin on/off }

delay( 100 ); // waits a few milliseconds

}

Step 5: Done