Table of Contents

How to use Ultrasonic Sensor with Arduino in PictoBlox Software

Arduino Ultrasonic Sensor
Example Description
This example is designed for grade 7 students to learn how to use an Ultrasonic Sensor with Arduino and PictoBlox block coding! In this activity, students will measure the distance between the sensor and nearby objects. When an object comes within a specified range, the built-in LED on the Arduino board turns ON automatically. This project introduces distance sensing and decision-making using sensors.

Introduction

Ultrasonic sensors are used to measure the distance between the sensor and an object without physical contact. They work by sending ultrasonic waves and receiving the reflected echo. In this activity, we will use an Ultrasonic Sensor to detect nearby objects and control the Arduino’s built-in LED based on the measured distance. 

Setting Up the Hardware

  1. Open PictoBlox 
  2. Create a new project in Block Coding
  3. Keep the default sprite Tobi on the stage
  4. Go for the board and select the board Arduino UNO
    Arduino Connect
  5. Connect the Arduino board to the computer using a USB cable.
  6. Connect the Ultrasonic Sensor to the Arduino board. 
  7. Connect the Trig pin(Green) to ~9 and the Echo(Yellow) pin to 8 according to the circuit diagram.
  8. Connect the VCC pin to 5V and the GND pin to GND on the Arduino.
    Circuit Connection of Arduino UNO with Ultasonic Sensor
  9. The built-in LED connected to Digital Pin 13 will be used as the output indicator. 
  10. Ensure all connections are secure before uploading the program. 

Step-by-Step Block Coding Guide 

  1. Add the Arduino Start Block
    Arduino-UNO-Starts-Up
  2. Add a Forever Loop from the control pallet
    Forever
  3. Add the If-Else Block from the control pallet
    If-Else-with-Forever
  4. Add the comparison operator (<) and set the value to 10.
    Operator-in-If-Else-with-Forever
  5. The Arduino checks whether an object is less than 10 cm from the Ultrasonic Sensor.
    • From the Arduino category, drag the “get ultrasonic sensor distance (cm)” block and place it in the condition section of the if-else block.
    • Trig Pin = 9
    • Echo Pin = 8
      Ultrasonic-Sensor-in-Operator-in-If-Else-with-Forever
  6. When an object is detected less than 10 cm, the LED connected to Pin 13 turns ON.
    • From the Arduino category, drag the “set digital pin output as” block.
    • Digital Pin = 13
    • Output = HIGH
      High-Ultrasonic-Sensor-in-Operator-in-If-Else-with-Forever
  7. Add another “set digital pin output as” block inside the else section.
    Digital Pin = 13
    Output = HIGH
    HighLow-Ultrasonic-Sensor-in-Operator-in-If-Else-with-Forever
  8. Connect the Arduino board to the computer and upload the block code. 
  9. Move an object closer to the Ultrasonic Sensor and observe the built-in LED. 

Output

 

Conclusion

In this activity, we learned how to use an Ultrasonic Sensor to measure distance and control the Arduino’s built-in LED based on the detected distance. This project demonstrates how sensors can be used to detect objects and make automated decisions in robotics and smart systems.