School Project Report : Smart Distance Measurement Using Ultrasonic Sensor and Raspberry Pi Pico

School Project Report : Smart Distance Measurement Using Ultrasonic Sensor and Raspberry Pi Pico

🎯 Objective

To design and implement a simple yet intelligent distance measurement system using the Raspberry Pi Pico microcontroller and an ultrasonic sensor (HC-SR04). The aim is to understand how ultrasonic sensing works and how it can be integrated into modern electronics for real-world applications like robotics, parking sensors, and object detection.


🧠 Why I Chose This Project

Because I wanted to explore the magic behind how robots “see” things without eyes! Ultrasonic sensors work like a bat’s echolocation—super cool, right? Plus, the Raspberry Pi Pico is affordable, easy to use, and fun to program with MicroPython. I wanted to combine them into something useful and fun.


🧰 Components Used

ComponentQuantityPurpose
Raspberry Pi Pico1Brain of the project
Ultrasonic Sensor HC-SR041To measure distance using sound
Breadboard1Easy prototyping without soldering
Jumper Wires6–8For connections
USB Cable1To power and program Pico
Computer (Thonny IDE)1Writing and uploading MicroPython code

🔬 Working Principle+

The HC-SR04 ultrasonic sensor sends out a trigger pulse of 40kHz. This sound wave bounces off an object and returns to the sensor. The sensor calculates the time taken and uses the speed of sound to compute the distance: Distance (cm)=Time (μs)×0.03432\text{Distance (cm)} = \frac{\text{Time (μs)} \times 0.0343}{2}Distance (cm)=2Time (μs)×0.0343​

The division by 2 is because the sound travels to the object and comes back.


🧪 Circuit Diagram

(Insert a neat Fritzing-style diagram if possible or draw it manually and label clearly)

Basic Connections:

  • VCC → 3.3V on Pico (Pin 36)
  • GND → GND (Pin 38)
  • Trig → GP3 (Pin 5)
  • Echo → GP2 (Pin 4)

distance measurement using ultrasonic sensor

Raspberry Pi PICO Pinout

raspberry pi pico pinout

👨‍💻 Code (MicroPython)

from machine import Pin, time_pulse_us
import time

TRIG = Pin(3, Pin.OUT)
ECHO = Pin(2, Pin.IN)

def measure_distance():
TRIG.low()
time.sleep_us(2)
TRIG.high()
time.sleep_us(10)
TRIG.low()

pulse_duration = time_pulse_us(ECHO, 1)
distance = (pulse_duration * 0.0343) / 2
return distance

while True:
dist = measure_distance()
print("Distance: {:.2f} cm".format(dist))
time.sleep(1)

🎉 Results

When objects were placed in front of the sensor at different distances, the readings printed on the screen were accurate and real-time. Here’s a sample:

Object Distance (cm)Sensor Output (cm)
1010.2
2019.8
3030.1

🔍 Observations

  • The sensor gives stable results between 2 cm to 400 cm.
  • Needs quiet environment (no loud sound or wind) for best accuracy.
  • Distance fluctuates slightly when objects are irregular or soft (like cloth).

📈 Applications in Real Life

  • Obstacle avoidance in robotics
  • Automatic parking sensors in cars
  • Smart dustbins that open when you approach
  • People counters or intruder alerts

🤯 What I Learned

  • How ultrasonic sensors use sound waves to measure distance
  • How to code in MicroPython and run it on a Raspberry Pi Pico
  • Basics of electronics prototyping using breadboards
  • Importance of precision timing in sensors

💡 Ideas for Improvement

  • Add a buzzer or LED to give audio/visual alerts
  • Display readings on an OLED screen
  • Build a mini obstacle-avoiding robot using this sensor
  • Send data wirelessly using Wi-Fi (ESP8266 or Pico W)

🏁 Conclusion

This project helped me combine coding, electronics, and creative thinking to build something that works like a tech gadget in real life! It showed how simple sensors can make our devices “smarter.” The Raspberry Pi Pico is an excellent platform for such beginner-level innovations.


📸 Photos of My Project (optional but highly recommended)

Attach 2–3 pictures of:

  • The final working setup
  • Sensor close-up
  • Output on Thonny IDE terminal

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *