Devices & Components
Arduino Uno Rev3
Breadboard (generic)
5 mm LED: Red
Ultrasonic Sensor - HC-SR04 (Generic)
Male/Female Jumper Wires
Resistor 1k ohm
5 mm LED: Green
Hardware & Tools
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Software & Tools
Arduino IDE
Project description
Code
Code
c_cpp
This is the code of this project. Copy paste this code to your Arduino IDE.
1#define Trigpin 7 2#define Echopin 8 3#define low_led 9 4#define high_led 10 5float distance; 6int duration; 7int ll = 700; 8 9void setup() { 10 pinMode (Trigpin, OUTPUT); 11 pinMode (low_led, OUTPUT); 12 pinMode (high_led, OUTPUT); 13 pinMode (Echopin, INPUT); 14 Serial.begin(9600); 15 Serial.println ("Welcome To Distance Meter"); 16 Serial.println ("Coded By Jevins Annson"); 17 digitalWrite (low_led, LOW); 18 digitalWrite (high_led, LOW); 19} 20 21void loop() { 22 digitalWrite(Trigpin, LOW); 23 delayMicroseconds(2); 24 digitalWrite(Trigpin, HIGH); 25 delayMicroseconds(10); 26 digitalWrite(Trigpin, LOW); 27 duration = pulseIn(Echopin, HIGH); 28 distance = duration * 0.034 / 2; 29 delay (ll); 30 Serial.println (" "); 31 Serial.print ("Distance = "); 32 Serial.print (distance); 33 Serial.print (" CM"); 34 Serial.println (" "); 35 36 if (distance>=30) 37 { 38 Serial.println ("Nobody Is Infront Of the Sensor"); 39 digitalWrite (low_led, HIGH); 40 delay (500); 41 digitalWrite (low_led, LOW); 42 delay (500); 43 digitalWrite (low_led, HIGH); 44 } 45 else 46 { 47 Serial.println ("Someone Is Infront Of the Sensor"); 48 digitalWrite (high_led, HIGH); 49 delay (100); 50 digitalWrite (high_led, LOW); 51 delay (100); 52 digitalWrite (high_led, HIGH); 53 delay (100); 54 } 55} 56
Downloadable files
Circuit Diagram
This is the Circuit Diagram of this project. Assemble your project by following this circuit diagram.
Circuit Diagram
Circuit Diagram
This is the Circuit Diagram of this project. Assemble your project by following this circuit diagram.
Circuit Diagram
Comments
Only logged in users can leave comments