Distance Alert

Introduction: Distance Alert

This Distance Alert uses ultra-sonic to measure distance between the ultra-sonic and the obstacles faces it or what you may want.

it uses a led connected to an arduino uno board,as the obstacles be in range the led will light up.

Step 1: Prepare Your Connections

Step 2: Set Your Code to the Arduino Board

// Define pins for ultrasonic and buzzer

int const trigPin = 10; int const echoPin = 9;

int const ledpin = 13;

void setup() {

pinMode(trigPin, OUTPUT);

// trig pin will have pulses output

pinMode(echoPin, INPUT);

// echo pin should be input to get pulse width

pinMode(ledpin, OUTPUT); // buzz pin is output to control buzzering }

void loop() { // Duration will be the input pulse width and distance will be the distance to the obstacle in centimeters

int duration, distance;

// Output pulse with 1ms width on trigPin

digitalWrite(trigPin, HIGH);


digitalWrite(trigPin, LOW);

// Measure the pulse input in echo pin

duration = pulseIn(echoPin, HIGH);

// Distance is half the duration devided by 29.1 (from datasheet) distance = (duration/2) / 29.1;

// if distance less than 0.25 meter and more than 0 (0 or less means over range)

if (distance <= 25 && distance >= 0) {

// ledup

digitalWrite(ledpin, HIGH);

} else {

// Don't ledup

digitalWrite(ledpin, LOW);


// Waiting 60 ms won't hurt any one



Step 3: Have Fun :D

adjust the condition in the code to modify your distance alert.

have fun.

Be the First to Share


    • Pocket-Sized Speed Challenge

      Pocket-Sized Speed Challenge
    • Audio Challenge 2020

      Audio Challenge 2020
    • Maps Challenge

      Maps Challenge

    2 Discussions


    4 years ago


    On the connection diagram there is a LCD display, but in a code there is no line about its application.


    4 years ago

    Very cool! Thanks for sharing your code!