My First Smart Robot
Loading...
R MY FIRST SMART ROBOT
ROBOTICS LAB 30–40 MIN 1 / 11

MY FIRST SMART ROBOT: DETECT AN OBJECT AND BLINK AN LED!

MISSION 01 · PREDICT

Can Your Robot Detect Your Hand?

Let's teach Arduino to see how close an object is.

Bring your hand close. What will the robot do?

THE LED BLINKS! NOTHING HAPPENS!

HAND → SENSOR

MISSION 02 · LISTEN

Meet the Magic Eyes

This sensor sends out sound and listens for the sound to come back.

What happens when your hand moves closer?

The sound has a shorter journey. The sound has a longer journey.

HC-SR04
sound wave

MISSION 03 · GATHER

Meet Our Robot Parts

Every part has a job. Tap the button to meet them one at a time.

UNO
Meet the Parts

MISSION 04 · CONNECT

Let's Connect Our Sensor

Follow the wires carefully. The correct connections help your robot work!

ARDUINO
UNO
ULTRASONIC
Show Connections

MISSION 05 · LIGHT UP

Let's Connect Our LED

The LED is our robot's light. The resistor helps protect it.

  • Pin 13 → resistor → LED long leg
  • LED short leg → GND
Blink the Light

long leg

MISSION 06 · UNDERSTAND

How Does It Work?

The robot listens, thinks, and then acts.

1

The sensor sends

A sound wave travels out.

2

The sound bounces

It returns from your hand.

3
R

Arduino decides

It checks the distance.

HAND CLOSE → LED BLINKSHAND FAR AWAY → LED OFF
Try It!
Press Try It to see the robot react.

MISSION 07 · THINK

Let's Make the Robot Smart

The Arduino needs instructions, just like a person following directions.

If an object is within 15 cm, blink the LED. Otherwise, turn it off.

Which example should make the LED blink?

Hand at 8 cmLED blinksHand at 25 cmLED stays off

MISSION 08 · INSTRUCT

Our Robot's Instructions

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

Time to Test Our Robot!

One careful step at a time.

  1. Connect the Arduino to the computer.
  2. Open Arduino IDE.
  3. Copy the code.
  4. Select Arduino Uno and the correct port.
  5. Click Verify.
  6. Click Upload.
  7. Move your hand in front of the sensor.

High five! Your robot is ready.

LED not blinking?Check the wires.Check the LED direction.Check that the code uploaded successfully.

MISSION 10 · CHALLENGE

Can You Outsmart the Robot?

Choose an answer for each quick challenge.

1 / 3

MISSION 11 · IMAGINE

Where Can We Use This?

Distance sensing is useful far beyond our classroom.

Smart parking

Sense when a parking space is free.

Automatic doors

Open a door when someone comes near.

R

Obstacle robots

Help a robot notice what is ahead.

R
You built a smart robot!Sense it. Think it. Make it happen.
Previous Use the arrows to explore Next