HCSR04 Ultrasonic Sensor With Arduino in 3 Minutes!

preview_player
Показать описание
Welcome to our quick and informative guide on using the HCSR04 Ultrasonic Sensor with Arduino! In just 3 minutes, you'll learn everything you need to know to get started with this versatile sensor and unleash its potential in your projects.
The HCSR04 Ultrasonic Sensor is a key component for measuring distance accurately without physical contact, making it perfect for robotics, automation, and various DIY projects. In this concise tutorial, we'll walk you through the setup process step by step, ensuring you grasp the basics in no time.
From wiring the sensor to your Arduino board to coding the logic for distance measurement, we've got you covered.

Written tutorial:

Smart Blind Stick:

Arduino Radar System:

Smart Dustbin:
Рекомендации по теме
Комментарии
Автор

const int trig = 6; // Trigger pin
const int echo = 7; // Echo pin

long totaltime;
long distance;

void setup() {
pinMode(trig, OUTPUT); // Set trig pin as output
pinMode(echo, INPUT); // Set echo pin as input
Serial.begin(9600); // Start serial communication at 9600 baud rate
}

void loop() {
// Clear the trig pin by setting it LOW
digitalWrite(trig, LOW);
delayMicroseconds(2);

// Trigger the sensor by setting the trig pin HIGH for 10 microseconds
digitalWrite(trig, HIGH);
delayMicroseconds(10);
digitalWrite(trig, LOW);

// Read the echo pin and calculate the time it takes for the echo to return
totaltime = pulseIn(echo, HIGH);

// Calculate the distance (in cm) based on the speed of sound (343 m/s)
distance = totaltime * 0.034 / 2;

// Print the distance to the Serial Monitor
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");

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

ChaitanyaDewangan-hwxt
Автор

can you pls making video digital measuring tool with this.
pls be note i am not an electronic student. i am hobbyist.

suggest to do with mini beardboard or without bearboard with wiring picture is easy to understand for me

baala
Автор

Thanks mate. Please continue making such great content.

abdullahnasir
Автор

Hey man your videos are awesome and your channel is where I want mine to be in the future! I am wondering if you have any feedback for my videos and channel? Thanks it means a lot!!

MatthewCarlsen