Full Code:- int trig = 7; int echo = 6; int timeInMicro; int distanceInCm; void setup() { Serial.begin(9600); // Initialize serial communication pinMode(trig, OUTPUT); pinMode(echo, INPUT); } void loop() { digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); timeInMicro = pulseIn(echo, HIGH); distanceInCm = timeInMicro / 29 / 2; Serial.println(distanceInCm); delay(100); } Aim of this Full code: Sends a sound pulse.->Measures the time for the pulse to return.->Calculates the distance based on the speed of sound.->Displays the distance to the object in centimeters. Lines :- digitalWrite(trig, LOW); delayMicroseconds(2); digitalWrite(trig, HIGH); delayMicroseconds(10); digitalWrite(trig, LOW); Explaination This part of the code is used to send a trigger signal to the ultrasonic sensor so that it emits an ultrasonic pulse. Here's a breakdown of each part: 1. digitalWrite(trig, LOW);: Sets the trig pin to LOW (0 volts) to ensure it starts with no signal. 2. delayMicroseconds(2);: Pauses the program for 2 microseconds to give a short delay after setting the trigger to LOW. 3. digitalWrite(trig, HIGH);: Sets the trig pin to HIGH (5 volts). This action starts the ultrasonic sensor's pulse, causing it to emit a burst of ultrasonic sound waves. 4. delayMicroseconds(10);: Holds the trig pin HIGH for 10 microseconds. This is the duration of the ultrasonic pulse sent by the sensor. 5. digitalWrite(trig, LOW);: Sets the trig pin back to LOW, ending the pulse. The sensor then waits for the sound waves to bounce back. In summary, this sequence of commands creates a brief 10-microsecond pulse that tells the ultrasonic sensor to emit sound waves for distance measurement. Lines:- timeInMicro=pulseIn(echo,HIGH); distanceInCm=timeInMico/29/2; Serial.println(distanceInCm); delay(100); Explaination:- This part of the code measures the time it takes for the ultrasonic pulse to travel to an object and back, then calculates and displays the distance in centimeters. Here's a breakdown of each line: 1. timeInMicro = pulseIn(echo, HIGH); This line waits for a pulse to be received on the echo pin and measures how long the pin stays HIGH (in microseconds). This time represents how long it took for the sound wave to travel to the object and bounce back to the sensor. 2. distanceInCm = timeInMicro / 29 / 2; Here, the measured time timeInMicro is converted into distance. Dividing by 29 gives the distance in centimeters for a round trip (since sound travels at roughly 29 microseconds per centimeter). Dividing by 2 gives the one-way distance from the sensor to the object. 3. Serial.println(distanceInCm); This line prints the calculated distance (in centimeters) to the Serial Monitor, allowing you to see the distance measurement on your computer. 4. delay(100); This line pauses the program for 100 milliseconds before starting the next measurement. This delay prevents the sensor from continuously reading too quickly. In summary, these lines measure the time of the ultrasonic pulse, calculate the distance to the object, and display it on the Serial Monitor. Formulae:- Speed of Sound: 340m/s = 29microsecon Distance in Cms=microseconds/29/2 Explaination of formulae:- This formula calculates the distance to an object based on the time sound takes to travel to it and return, using the known speed of sound. Explanation in Simple Terms 1. Speed of Sound: Sound travels at a speed of 340 meters per second (m/s). This is equivalent to 29 microseconds per centimeter. In other words, it takes 29 microseconds (millionths of a second) for sound to travel 1 cm. 2. Distance Formula: When we send an ultrasonic pulse from a sensor, it travels to an object and bounces back. The sensor measures the total travel time (round-trip) in microseconds. We use this time to calculate the distance to the object. 3. Distance Calculation in Centimeters: Distance = (time in microseconds) / 29 / 2 / 29 converts the total time into the round-trip distance in centimeters, since it takes 29 microseconds for sound to travel 1 cm. / 2 gives the one-way distance to the object (since the measured time includes the trip to the object and back). Example Calculation If the measured time is 580 microseconds, then: 1. Round-trip Distance: -> 580 microseconds/29 = 20cm (round-trip) 2. One-way Distance: 20 cm / 2 = 10 cm So, the object is 10 cm away from the sensor.
@techathome2 ай бұрын
♥
@SR-ok3suАй бұрын
What is round strip distance
@Lak2606Күн бұрын
the maximum my number is going to is 3, what is the error, code is working it goes down to 1 when i bring near but maximum is 3
@meskhetian6422 жыл бұрын
Hello, I have the same problem with LET’S UNBOX!, as you have stated, I checked the pins and replaced all the jumper wires, but it still does not work, it keeps repeating “0”. Would you possibly know what else is the problem?
@techathome2 жыл бұрын
This issue is because, signals from sensor are not reaching Arduino pins, - Check wire - Check connections - Replace sensor
@VENU_GAMING13 күн бұрын
Code: int trig=7; int echo=6; long x; long y; void setup() { Serial.begin(9600); pinMode(7,OUTPUT); pinMode(6,INPUT); } void loop() { digitalWrite(trig,LOW); delayMicroseconds(2); digitalWrite(trig,HIGH); delayMicroseconds(10); digitalWrite(trig,LOW); x = pulseIn(echo,HIGH); y = ((x/29)/2); if (y
@anithasshenoy666210 ай бұрын
Thanks for this video. I am not getting anything from the pulseIn() . Hence the distance is showing zero. I have two new modules. Both show the same result. What could be the reason ?
@techathome10 ай бұрын
Check the continuity of jumper wires, sometimes they will be faulty.
@anithasshenoy66629 ай бұрын
@@techathome I removed it from breadboard and connected directly. Now it is working. thks
@yamanjain9346 Жыл бұрын
Do you all were able to here audio after 3:42
@techathome Жыл бұрын
I checked now, Everything was fine before, Last week there was some copyright issue for background music. So we removed that. Somehow this explanation voice also got deleted.
@harunshankar6041 Жыл бұрын
@@techathome unable to hear after 3:42
@BromideBride4 ай бұрын
There is no audio description still. Maybe you can edit or add text description to the video.
@SR-ok3suАй бұрын
No
@amrabdlkadersabry56493 ай бұрын
How can i use ultra sonic sensor without delay in the code
@kapil409 Жыл бұрын
Ser_open() : can't set com- state showing uploading error
@techathome Жыл бұрын
Unplug and replug again and try. Also plug it to different com port.
@ramybrahim3188 Жыл бұрын
Thank you From Morocco
@techathome Жыл бұрын
Welcome
@easybreezy999Ай бұрын
Can u give any video about obstacles avoiding robot car
@techathomeАй бұрын
As of now we have not done any video on this. Will try to make it.
@itsSatvik59 Жыл бұрын
make another 20 parts, very nice videos
@techathome Жыл бұрын
Thank you. We will make more.. There are around 30 video as of now : kzbin.info/aero/PL4B0LEKY-jrT_fjOGkX_NZ52ZHZf8s9S-
@tharunraj8149 ай бұрын
Sketch uses 2526 bytes (7%) of program storage space. Maximum is 32256 bytes. Global variables use 188 bytes (9%) of dynamic memory, leaving 1860 bytes for local variables. Maximum is 2048 bytes. avrdude: ser_open(): can't open device "\\.\COM5": Access is denied. Failed uploading: uploading error: exit status 1
@techathome9 ай бұрын
unplug and re-plug the board
@kirans9395 Жыл бұрын
Why have you divided by? Due to 2 microsecond delay?
@krk1018 ай бұрын
We need half of the time taken by the sound. We get the total time, sensor to object and back. But we only need time taken to reach the object. So it's half.
@khannreactions33112 жыл бұрын
is there any way using vb form to connect that?
@Isanjay.13 Жыл бұрын
Bro its emergency can we write the same program for the project train accident prevention if not can u pls say the procedures how to write tomorrow is my science expo only the coding is pending can u pls help bro plssss
@techathome Жыл бұрын
Can u send request on mail, I am not completely clear with your project requirements: deepakhd20@gmail.com
@Bigbrainie3 жыл бұрын
Can we print the distance on lcd instead of serial? Where should I make the changes in code? If possible, please make a video. I am a beginner :-)
@techathome3 жыл бұрын
We have done tutorial on that, you can refer to below two video links: Lcd1 - kzbin.info/www/bejne/nKqvYptsZ7Z7gNU Lcd2 - kzbin.info/www/bejne/gqrYqpWZpLN4qdk
@Bigbrainie3 жыл бұрын
@@techathome Thanks bro, tutorial 17 helped me!
@techathome3 жыл бұрын
Welcome
@shrv20321 Жыл бұрын
@@techathome hello sir.
@shrv20321 Жыл бұрын
@@techathome code pahije hota ya vdo cha
@yourevolution78509 ай бұрын
Iska value itna fluctuate knyu kar rha he?
@shivufpv62484 жыл бұрын
Thanks bro 👍👊👌
@mrwildmouth5876 Жыл бұрын
Which board are you using ?
@techathome Жыл бұрын
Arduino Uno
@electro2585 Жыл бұрын
Your formula is wrong and is not working properly
@Bigbrainie3 жыл бұрын
I'm getting distance 0 on serial monitor everytime. What to do?
@techathome3 жыл бұрын
Check the pins connections of ultrasonic sensor and also replace the jumper wires
@Bigbrainie3 жыл бұрын
@@techathome ok I will try
@KnowPlants-52 жыл бұрын
@@Bigbrainie Did u solved it..
@Bigbrainie2 жыл бұрын
@@KnowPlants-5 yes
@hahahahahaha6647 ай бұрын
what is pinmode for??
@techathome7 ай бұрын
This is used to set the mode of the pin. Either you want to use particular pin as input or output. kzbin.info/www/bejne/e3uoq2mqarijg9k
@muninggamer762111 ай бұрын
how to increase the range of the ultrasonic sensor?
@techathome11 ай бұрын
It is not possible to increase the range with software. It depends on the specifications of ultrasonic sensor.
@KnowPlants-52 жыл бұрын
Bro. I am getting some values and o in between the values ..
@techathome2 жыл бұрын
If you are not inside its range, It will give some random values
@VivekBJha6 ай бұрын
Please can you give me pins in written form file is not opening
@techathome6 ай бұрын
Can u send mail: deepakhd20@gmail.com
@ushakiran8285 Жыл бұрын
can you explain the formula bro why should we divede it by 9?
@sreekanthneelam52682 ай бұрын
Code rar file is not opening
@techathome2 ай бұрын
You have to extract it
@ravikumarkankanala40924 ай бұрын
Sir sound is not coming
@techathome4 ай бұрын
Check the connections and jumper wires.
@TestCreate-v6g6 ай бұрын
Cant find the google drive
@techathome6 ай бұрын
Can u send mail request: deepakhd20@gmail.com
@bozakardude Жыл бұрын
the thing that shows the distance doesnt show up
@techathome Жыл бұрын
I didn't get your question.
@shyamsundar7784 Жыл бұрын
Good explanation
@techathome Жыл бұрын
Thank you
@pizafox126 ай бұрын
What program do you use?
@techathome6 ай бұрын
Arduino The link for code is in description
@narullah692 жыл бұрын
in second last line you haven't use semi colon ;
@techathome2 жыл бұрын
Oh, my be we have to update the code file
@scout3526 Жыл бұрын
Bro some 800 , 1000 values are getting displayed how to avoid those values .?
@techathome Жыл бұрын
If you go beyond the range it gives random values sometimes. This is basic code to understand the working. Use ultrasonic library, this issue might resolve. Download and install this one: downloads.arduino.cc/libraries/github.com/ErickSimoes/Ultrasonic-3.0.0.zip
@RarosKitchenАй бұрын
OUTPUT SHOWS ONLY ZERO
@techathomeАй бұрын
Might be connection issue. Check the jumper wires also, some wires will be faulty.
@sanjusingha17142 ай бұрын
No voice : 3:51 -5:45
@techathome2 ай бұрын
Due to copyright issues on background music, audio has been removed.
@sanjusingha17142 ай бұрын
@techathome oh.. so that's the reason
@godgajet6763 Жыл бұрын
help not working
@techathome Жыл бұрын
Check the connections
@Millionaire_001 Жыл бұрын
Bro don't use distance command
@nandikolasravani2498 Жыл бұрын
Code please
@techathome Жыл бұрын
I have provided the zip file link in description, download and extract.
@atiiveerjain5104 ай бұрын
Thanks
@techathome4 ай бұрын
Welcome
@chandru602210 ай бұрын
is it working
@techathome10 ай бұрын
yes
@devchaudhary5892 Жыл бұрын
I need ckt diagram
@techathome Жыл бұрын
Download the compressed file in description box and extract it
@adithyanvj29192 жыл бұрын
subscribed :-)
@hazimmuhammed5125 Жыл бұрын
There is no file at your google drive code section . Im reporting
@techathome Жыл бұрын
I have provided zip file : drive.google.com/file/d/1nBpfZG43UC30DHSi5e6XjFo3WjFhL3s1/view Download and extract it, you will get code and circuit.
@remogamer2029 Жыл бұрын
@@techathomeit's showing that the file is unsupported!