The sensor sends
A sound wave travels out.

MY FIRST SMART ROBOT: DETECT AN OBJECT AND BLINK AN LED!
MISSION 01 · PREDICT
Let's teach Arduino to see how close an object is.
Bring your hand close. What will the robot do?
MISSION 02 · LISTEN
This sensor sends out sound and listens for the sound to come back.
What happens when your hand moves closer?
MISSION 03 · GATHER
Every part has a job. Tap the button to meet them one at a time.
MISSION 04 · CONNECT
Follow the wires carefully. The correct connections help your robot work!
MISSION 05 · LIGHT UP
The LED is our robot's light. The resistor helps protect it.
MISSION 06 · UNDERSTAND
The robot listens, thinks, and then acts.
A sound wave travels out.
It returns from your hand.
It checks the distance.
MISSION 07 · THINK
The Arduino needs instructions, just like a person following directions.
Which example should make the LED blink?
MISSION 08 · INSTRUCT
Here is the complete program. Your presenter will unpack it aloud.
const int trigPin = 9;
const int echoPin = 10;
const int ledPin = 13;
long duration;
float distance;
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH, 30000);
if (duration == 0) {
distance = -1;
} else {
distance = duration * 0.0343 / 2;
}
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
if (distance > 0 && distance <= 15) {
digitalWrite(ledPin, HIGH);
delay(250);
digitalWrite(ledPin, LOW);
delay(250);
} else {
digitalWrite(ledPin, LOW);
delay(100);
}
}MISSION 09 · TEST
One careful step at a time.
MISSION 10 · CHALLENGE
Choose an answer for each quick challenge.
MISSION 11 · IMAGINE
Distance sensing is useful far beyond our classroom.
Sense when a parking space is free.
Open a door when someone comes near.
Help a robot notice what is ahead.