brillianttechnoz
Published © GPL3+

Led distance measurement using ultrasonic sensor and aurdino

After making this project you see distances using leds

BeginnerFull instructions provided14,119
Led distance measurement using ultrasonic sensor and aurdino

Things used in this project

Hardware components

LED (generic)
LED (generic)
×10
Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

schematic for led distance measurement using ultrasonic sensor and aurdino

Code

code for led distance measurement using ultrasonic sensor and aurdino

C/C++
copy and paste it in aurdino ide
int trig = 10;
int echo = 11;
int led1 = 13;
int led2 = 12;
int led3 = 9;
int led4 = 8;
int led5 = 7;
int led6 = 6;
int led7 = 5;
int led8 = 4;
int led9 = 3;
int led10 = 2;


void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, INPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(2, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  long duration, distance;
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  distance = (duration / 2) / 29.1;

  if (distance >= 10)
  {
    digitalWrite(led1, HIGH);
  }
  else
  {
    digitalWrite(led1, LOW);
  }

  if (distance >= 20)
  {
    digitalWrite(led2, HIGH);
  }
  else
  {
    digitalWrite(led2, LOW);
  }

  if (distance >= 30)
  {
    digitalWrite(led3, HIGH);
  }
  else
  {
    digitalWrite(led3, LOW);
  }

  if (distance >= 40)
  {
    digitalWrite(led4, HIGH);
  }
  else
  {
    digitalWrite(led4, LOW);
  }

  if (distance >= 50)
  {
    digitalWrite(led5, HIGH);
  }
  else
  {
    digitalWrite(led5, LOW);
  }

  if (distance >= 60)
  {
    digitalWrite(led6, HIGH);
  }
  else
  {
    digitalWrite(led6, LOW);
  }

  if (distance >= 70)
  {
    digitalWrite(led7, HIGH);
  }
  else
  {
    digitalWrite(led7, LOW);
  }

  if (distance >= 80)
  {
    digitalWrite(led8, HIGH);
  }
  else
  {
    digitalWrite(led8, LOW);
  }

  if (distance >= 90)
  {
    digitalWrite(led9, HIGH);
  }
  else
  {
    digitalWrite(led9, LOW);
  }

  if (distance >= 100)
  {
    digitalWrite(led10, HIGH);
  }
  else
  {
    digitalWrite(led10, LOW);
  }

}

Credits

brillianttechnoz

brillianttechnoz

3 projects • 3 followers

Comments