Controlling LED's Using Ultrasonic Distance Sensor

Hackster.ioLearning Hardware Community. Projects× Log inSign up ProjectsProjectsChannelsChannelsNewsContestsEventsVideos ×

Embed the widget on your own site

Add the following snippet to your HTML:

Controlling LED's Using Ultrasonic Distance Sensor

Turns the 2 LED's on and off by calculating the distance of the object from the Ultrasonic Sensor.

Read up about this project on Hackster.io

Controlling LED's Using Ultrasonic Distance Sensor

blackpanda8563 25,893
  • Overview
  • Things
  • Story
  • Schematics
  • Code
  • Credits
  • Comments(2)
blackpanda856blackpanda856Published © GPL3+Controlling LED's Using Ultrasonic Distance Sensor

Turns the 2 LED's on and off by calculating the distance of the object from the Ultrasonic Sensor.

IntermediateFull instructions provided25,893Controlling LED's Using Ultrasonic Distance Sensor

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
  • Buy from Newark
  • Buy from store.arduino.cc
  • Buy from Adafruit
  • Buy from Arduino Store
  • Buy from CPC
Breadboard (generic)
Breadboard (generic)
×1
  • Buy from Newark
  • Buy from SparkFun
5 mm LED: Red
5 mm LED: Red
×1
5 mm LED: Green
5 mm LED: Green
×1
Resistor 1k ohm
Resistor 1k ohm
×2
Male/Female Jumper Wires
Male/Female Jumper Wires
×1
  • Buy from Newark
  • Buy from Adafruit
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires

Story

ThisisaBeginnerproject. The green led glows and red led switches off when the object is a particular distance far from the UltrasonicDistanceSensor.

The red led glows and green led switches off when the object is a particular distance near to the UltrasonicDistance Sensor.

YouTubeChannel:J4Jevins

Link :- https://youtube.com/J4Jevins

Read more

Schematics

Circuit Diagram

This is the Circuit Diagram of this project. Assemble your project by following this circuit diagram.

Code

  • Code

Code

C/C++This is the code of this project. Copy paste this code to your Arduino IDE.#define Trigpin 7 #define Echopin 8 #define low_led 9 #define high_led 10 float distance; int duration; int ll = 700; void setup() { pinMode (Trigpin, OUTPUT); pinMode (low_led, OUTPUT); pinMode (high_led, OUTPUT); pinMode (Echopin, INPUT); Serial.begin(9600); Serial.println ("Welcome To Distance Meter"); Serial.println ("Coded By Jevins Annson"); digitalWrite (low_led, LOW); digitalWrite (high_led, LOW); } void loop() { digitalWrite(Trigpin, LOW); delayMicroseconds(2); digitalWrite(Trigpin, HIGH); delayMicroseconds(10); digitalWrite(Trigpin, LOW); duration = pulseIn(Echopin, HIGH); distance = duration * 0.034 / 2; delay (ll); Serial.println (" "); Serial.print ("Distance = "); Serial.print (distance); Serial.print (" CM"); Serial.println (" "); if (distance>=30) { Serial.println ("Nobody Is Infront Of the Sensor"); digitalWrite (low_led, HIGH); delay (500); digitalWrite (low_led, LOW); delay (500); digitalWrite (low_led, HIGH); } else { Serial.println ("Someone Is Infront Of the Sensor"); digitalWrite (high_led, HIGH); delay (100); digitalWrite (high_led, LOW); delay (100); digitalWrite (high_led, HIGH); delay (100); } }

Credits

blackpanda856

blackpanda856

2 projects • 4 followersFollow ContactContact

Comments

Related channels and tags
  • Communication
  • Communication
  • Kids & Family
  • Kids & Family
  • Lights
  • Lights
  • arduino
  • communication
  • data collection
  • kids
  • lights
  • monitoring
  • tracking
  • ultrasonic sensor

Tag » Arduino Hc-sr04 Led