Curriculum
Course: Dustbin Project
Login
Text lesson

About the Project

Aim

To measure the distance of an object using an HC-SR04 ultrasonic sensor and display the measured distance on the Serial Monitor.

Components Required

  • Arduino Uno
  • HC-SR04 Ultrasonic Sensor
  • Jumper Wires
  • USB Cable

Theory

The HC-SR04 ultrasonic sensor works by transmitting ultrasonic sound waves and measuring the time taken for the echo to return after striking an object. Using this time, the Arduino calculates the distance between the sensor and the object.

Working

  1. The Arduino sends an ultrasonic pulse through the TRIG pin.
  2. The sound wave travels through the air and reflects back after hitting an object.
  3. The ECHO pin receives the reflected wave.
  4. Arduino measures the time taken for the wave to return.
  5. Using the speed of sound, the distance is calculated.
  6. The calculated distance is displayed on the Serial Monitor.

Output

The Serial Monitor continuously displays the distance between the sensor and the object in centimeters.

Example:

 
Distance = 50 cm
Distance = 32 cm
Distance = 18 cm
Distance = 10 cm
×
×

Cart