Get Started with Ultrasonic Sensors and Arduino: Step-by-Step Wiring & Code Guide

preview_player
Показать описание
Ready to add an ultrasonic sensor to your next Arduino project?

In this Arduino tutorial, I’ll break down everything you need to know to get started—from how ultrasonic sensors actually work (yes, like a mini sonar for your projects!) to wiring it all up step-by-step. Then, I’ll walk you through each line of Arduino code so you can see exactly how we get distance measurements on the Serial Monitor, displaying distances in both centimeters and inches.

Ultrasonic sensors are best known for obstacle-avoiding robots, but they’re also perfect for adding some high-tech magic to props, interactive exhibits, or any project where you want lights, sounds, or movements to respond to distance.

In this Ultrasonic Sensor with Arduino Tutorial:
▶︎ How does an ultrasonic sensor work?
▶︎ How to calculate distance using the ultrasonic sensor's echo location abilities?
▶︎ How to wire an ultrasonic sensor to an Arduino Uno
▶︎ How to write Arduino code to get distance in cm and inches and display it on the serial monitor

▶︎▶︎ Subscribe for Arduino Tutorials & Projects Delivered to Your Inbox
- Crystal-clear wiring diagrams
- Copy-paste ready code
- Pro tips for troubleshooting
- Code packs to inspire epic builds

▶︎▶︎ JOIN my Engineering Artists Discord Community
- Live Workshops
- Arduino Project Build & Code-alongs
- Small Group Office Hours
- Personalized Project Support

🛒 BUILD YOUR OWN Ultrasonic Sensor with Arduino Project:

🎬 VIDEO CHAPTERS: Read Distance with an Ultrasonic Sensor and Arduino
0:00 Welcome
0:08 What is an Ultrasonic Sensor?
1:02 Parts of an Ultrasonic Sensor
1:32 Ultrasonic Sensor Pinout
1:56 How to Connect an Ultrasonic Sensor to Arduino
2:52 How does an Ultrasonic Sensor Work?
4:10 How to Calculate Distance using an Ultrasonic Sensor?
6:32 Arduino Code Line-by-Line Explanation
12:33 Reading Distance in CM and IN on the Serial Monitor
14:21 Get the Arduino Code
14:27 Join my Community for Live Events & More Code!

💬 Have any questions or want to share your own experiences, tips and advice about using an ultrasonic sensor with Arduino to read distance? Drop a comment below – I love hearing from you!

🔔 If you find this video helpful, please hit that like button 👍 and consider subscribing to my channel for more Arduino/props/robot tutorials, tips, and tricks. Your support helps me create more content like this!

Some links included here are to affiliate sites. If you purchase something through them, I may earn a small commission — which costs you nothing! I am very grateful for your support when you use my links to make a purchase.

#arduino #ultrasonicsensor #arduinocode #arduinoproject #arduinotutorial #arduinoprogramming
Рекомендации по теме
Комментарии
Автор

Back in 1985 I built a robot with a rotating sonar system, using ultrasonic transducers very similar to those used today. While rotating, the sonar was pulsed once every degree. Over one weekend I spent a lot of time testing my sonar with my head a few feet from the sonar system. I had no idea that a 40KHz pulse, which you cannot hear, could damage my hearing, but that is what happened. In one weekend, I permanently damaged my hearing and it has only gotten worse over the last 35 years. Later I calculated the SPL (sound pressure level) of that sonar’s output pulse from the amplitude of the signal and its data sheet. I found the sound output of that transmitter was about 125 db. On my current robot I have three HD-SR04 boards which I use for collision avoidance. I measured the amplitude of the transmitter signal and from the 40T/R transducer data sheet I calculated the SPL of the 40KHz output sound of the HD-SR04 to be about 115db, which is still loud enough to damage your hearing. So please keep your head far away from the front of the sonar board.

bobrowland
Автор

Was literally hoping you'd do do a project with this because I want to use it. Thank you, love your channel!

thatboy
Автор

Rachel: This was the best tutorial I've had thus far. It was useful, well explained, and you shared the code while I was following. I'm a retired teacher, and this is my style of learning. Please slow down your dictation by a few microseconds (see, I learned). I am very anxious to learn more using the UltraSonic sensor.

PRR
Автор

What's up Rachel ! Loved watching you fixing cars on tv, so glad you have this channel!

Thunderbyrd.
Автор

I don't know why you have low views your video's are so helpful I'm beginner but understood it easily. I hope i could access your live workshop.

gamingwithtasir
Автор

Rachel...I subscribed for the content, but I stay to soak up your boundless enthusiasm!

ronaldcarey
Автор

Much better video than the last one I saw. Easy to follow, good continuity. Good reading rhythm😀👍👍.
You could tell you put a lot of time in the prep work, to help us follow along. Mike

miketrissel
Автор

I'm just getting started with arduino (my first kit arrives today!) And I'm already planning a mousetrap box using these sensors, some sort of door closing apparatus, alarm and light. Big project for a 50 year old who's never coded anything in his life. 😂

indiedavecomix
Автор

The very first setting of trigPin to low should only needed to be done once, so could by just in fron of the loop. This saves some processing time.

jansmit
Автор

You could add sound and different note pitch at different distance.

wilson_joe
Автор

Your videos are so easy to follow and you make things so easy to understand. Could you do a video on relays?

jaykay
Автор

brains and beauty a perfect date you are, love the channel

jurgenbussche
Автор

another brilliant video, cheers mate!

shakejones
Автор

I love watching your videos, they are easy to understand, even though english is not my mother tongue. About the last question, I have a bit of a fun example, it's from "My little pony", in the episode "It's about time". Loved watching MLP with my daughter, now she is more into games, which is equally good. 😊

ShefaliE
Автор

Check out this nerdy information from this gorgeous lady. Rachel, you're doing some nice work, as always. Proclaims aside, notwithstanding one way or the other, I've enjoyed your work over time. Years later, I realize I may have missed something, but I'd like to see you vroom vroom again.
AirHammer out!!

airhammer
Автор

who wouldn't go back to HS if she was the teacher! great job. I tried this on my entry gate but doesn't work on detecting people.

TheUnofficialMaker
Автор

Rachel, I am slowly dying while I await the next Youtube tutorial on pairing the ultrasonic sensor/Arduino with other functions. I have a project in which I wish to use the Ultrasonic to start Arduino to run a series of 12 volt LED signal sets (i.e. green, yellow, red). I need you next tutorial . I'd hate to break up our engagement over such a small thing.

PRR
Автор

Thank you very much, always wondered how it worked

steverileyretired
Автор

You are great! Thanks for all the info ❤

anamariasalazar
Автор

you are so much fun! Even when you send me back to High School.🌹🌹🌹🌼

stevendemonnin