
Sea Voyage
Robo Explorers 2
Ultrasonic Sensor
What is an Ultrasonic Sensor?
An ultrasonic sensor is a special device that can measure distance without even touching anything! It works by sending out sound waves (that we can’t hear) and waiting to hear them bounce back—just like a bat or a dolphin navigating in the ocean!
Think of it like shouting into a cave and waiting for your echo to return. The longer it takes for the sound to come back, the further away the cave walls are!
Senses objects without touching them!
Works in the dark, unlike cameras!
Used in robots, cars, and even smart gadgets!
The Physics Behind Ultrasonic Sensors!
Let’s break it down!
1. Sending Out Sound Waves
The Ultrasonic Sensor has two small cylinders—one is a speaker (Transmitter), and the other is a microphone (Receiver).
The transmitter sends out an ultrasonic pulse (like a tiny clicking sound).
2. Waiting for the Echo
The sound wave travels through the air until it hits an object (like your hand ✋).
The sound bounces back to the sensor’s receiver (microphone).
3. Measuring the Time
The sensor calculates the time it took for the sound wave to return.
Using the speed of sound (343 m/s), the Arduino calculates how far away the object is!
Formula Used:
Distance=(Time Taken×0.034)÷2
Why divide by 2? Because the sound wave travels to the object and back!
Real-Life Use Cases of Ultrasonic Sensors!
Car Parking Sensors:
Ever heard a car beep faster as you get close to a wall? That’s an ultrasonic sensor!
Robot Navigation:
Robots use ultrasonic sensors to avoid obstacles so they don’t crash!
Automatic Doors:
Supermarkets use ultrasonic sensors to detect when someone is nearby and open the door!
Game Controllers:
Some VR and motion-based games use ultrasonic sensors to track hand movements!
Blind Assist Devices:
Some smart walking sticks use ultrasonic sensors to help visually impaired people detect obstacles!
How to connect Ultrasonic Sensor on the Blue Elixer Board
Code Breakdown: Ultrasonic Sensor + SMD LEDs
Now, let's use an ultrasonic sensor with SMD LEDs to create a light-up distance tracker!
1. Defining Sensor and LED Pins
We define the pins where the ultrasonic sensor and LEDs are connected.
2. Setting Up the Pins in setup()
What’s happening?
The trigger pin sends ultrasonic waves (OUTPUT).
The echo pin listens for the returning wave (INPUT).
The LEDs are set to OUTPUT so we can control them.
3. Measuring Distance with the Ultrasonic Sensor
How It Works?
A small pulse (10µs) is sent from the trigger pin.
The echo pin listens for the reflected sound wave.
The Arduino calculates the distance using the speed of sound.
4. Lighting Up LEDs Based on Distance
What’s happening?
If an object is very close (<10cm) → ALL LEDs light up!
If it’s a bit far (10-40cm) → 3 LEDs light up.
If it’s far away (>40cm) → Only 1 LED stays on.
This is how parking sensors work in cars!
What You’ll See!
Video of Happening
Move your hand or an object in front of the ultrasonic sensor.
The SMD LEDs will light up based on how close you are!
Fun Activity!
In this activity, we’ll create a magic gate that opens and closes automatically based on how close an object (or your hand) is to an ultrasonic sensor!
How does it work?
If nothing is nearby (distance > 40cm) → The servo stays at 0° (gate is closed ).
If something is very close (distance < 10cm) → The servo moves to 180° (gate opens! ).
It’s just like an automatic door at the supermarket!
The Code: Ultrasonic Sensor + Servo Motor!
Code Breakdown (How It Works!)
Pin Setup
We define the ultrasonic sensor’s pins (trigPin and echoPin).
We define the servo motor’s pin (9) to control it easily.
Setting Up the Components in setup()
The ultrasonic sensor and servo motor are initialized.
The servo starts at 0° (closed position).
Measuring Distance with the Ultrasonic Sensor
The trigger pin sends a 10-microsecond ultrasonic pulse.
The echo pin listens for the returning wave.
The Arduino calculates the distance using the speed of sound!
Moving the Servo Based on Distance
If something is very close (<10cm) → The servo moves to 180° (gate opens ).
If nothing is nearby (>40cm) → The servo moves to 0° (gate closes ).