Ultrasonic Sensor Module (HC-SR04)

Ultrasonic Sensor Module (HC-SR04)

Ultrasonic Sensor
HC-SR04
TRIOE
IoT
Distance Measurement
Robotics

The HC-SR04 Ultrasonic Sensor is a widely used module for distance measurement. It works by emitting sound waves and calculating the time it takes for the echo to return. This sensor is often used in obstacle detection, robotics, and range-finding applications.

Quick Actions

2345

Downloads

789

Likes

Specifications

VCCPower supply (+5V)
GNDGround (-)
TRIGTrigger pin (sends an ultrasonic pulse)
ECHOEcho pin (receives the reflected wave)

Sample Code

#define TRIG_PIN 9 // Trigger pin connected to digital pin 9
#define ECHO_PIN 10 // Echo pin connected to digital pin 10

void setup() {
Serial.begin(9600);
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
}

void loop() {
long duration, distance;

// Send a 10-microsecond pulse to trigger the sensor
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);

// Read the echo pulse duration
duration = pulseIn(ECHO_PIN, HIGH);

// Calculate the distance in cm
distance = (duration / 2) / 29.1;

// Display the distance
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

delay(1000); // Wait for a second before the next reading
}

Crash Course: Using the Ultrasonic Sensor Module (HC-SR04)

Objective

Teach learners how to use the HC-SR04 ultrasonic sensor module to measure distances and integrate it with a TRIOE microcontroller.

Materials Required

  • HC-SR04 Ultrasonic Sensor Module
  • TRIOE
  • Breadboard and jumper wires
  • USB cable for programming the TRIOE
  • Ruler or tape measure (for calibration and testing)

Steps

1Understand the HC-SR04 Sensor

  • The HC-SR04 emits ultrasonic sound waves and calculates distance based on the time it takes for the echo to return.
  • Key Pins: TRIG: Trigger pin sends an ultrasonic pulse, ECHO: Echo pin receives the reflected wave.

2Set Up the Circuit

  • Connect the VCC pin to the TRIOE's 5V pin.
  • Connect the GND pin to the TRIOE's GND.
  • Connect the TRIG pin to Digital Pin 9 on the TRIOE.
  • Connect the ECHO pin to Digital Pin 10.

3Write and Upload the Code

  • Write the code provided in the sample code section.
  • Connect the TRIOE to your computer via USB.
  • Select the correct board and COM port in the Arduino IDE.
  • Click Upload to send the code to the TRIOE.

Video Tutorial: Using the Ultrasonic Sensor Module (HC-SR04)

Video Player Placeholder

Common Applications

Application 1

Description of application 1.

Application 2

Description of application 2.

Application 3

Description of application 3.