Skip to content
Osief
Osief
  • Home
  • About Us
  • Contact Us
Osief
Osief
  • (360 Radar)using (Arduino uno) Ultrasonic sensor(HC-SR04) & servo motor
  • About Us
  • Connection of (servo motor)& control it with an (Arduino Uno),in 3 different angle
  • Contact Us
  • Count from 0 to 9 on a common cathode 7-segment display, using Arduino uno
  • Count from 0 to 9 on a common cathode 7-segment display,using Arduino uno 
  • Create a “watch” or clock on an LCD screen connected to an Arduino Uno with an I2C converter
  • Display (Arabic text) on an (LCD screen) connected to an Arduino Uno using an I2C converter
  • display moving text from left to right on an LCD screen connected to an Arduino Uno with an I2C converter
  • Display text with a fade-out effect on an LCD screen connected to an Arduino Uno using an I2C converter,
  • Display(any Pictures)on(0.96″ OLED)connected to(Arduino Uno)using I2C communication
  • Distance measurement of an (object) using an HC-SR04 (ultrasonic sensor) with an Arduino Uno
  • Electrical & Electronic
  • Home
  • How to change Name and password of Bluetooth Module
  • How to display any(moving emoji)on (0.96 inch I2C OLED display)using Arduino uno
  • Measure (Voltage) using (Arduino uno) only !!
  • One Master / one slave using I2C Protocol control six  LED arduino uno
  • Project for (Restricted area).To measure the distance using an Arduino Uno, HC-SR04 ultrasonic sensor, and display the results on an I2C-connected LCD with specific conditions for LED indications and text display
  • Scrolling text for(0.96″ OLED)connected to(Arduino Uno)using I2C communication
  • secondary
  • test gif
  • To control (3LED) ON/OFF using Remote control & Arduino uno, IR receiver
  • To control (LED) ON/OFF using (WiFi Module EPS 8266)
  • To control (three AC Bulb) using an Arduino Uno, (Relay Module) & (Bluetooth module)
  • To count from 0 to 1000 very fast and display the count on an LCD screen connected to an Arduino Uno via an I2C converter
  • To create a radar-like system using an Arduino Uno and a servo motor controlled by the HC-SR04 ultrasonic sensor
  • To display “anything” on an (LCD screen) connected to an (Arduino Uno) using an (I2C converter)
  • To display (1234) on 4-digit 7-segment display using Arduino uno 
  • To display text that slides into place on an LCD screen connected to an Arduino Uno using an I2C converter
  • To display text with a (fade-in) effect on an (LCD screen) connected to an Arduino Uno using an I2C converter
  • To measure the distance of an object using an HC-SR04 ultrasonic sensor and display the results on an LCD screen connected via an I2C converter
  • To write directly from a (keyboard) to an LCD screen connected to an Arduino Uno via an I2C converter
  • youtube Channel

 

كيفية قياس المسافة لجسم ما بواسطة حساس

(HC-SR04) مع استخدام

(Arduino Uno)

Distance measurement of an (object) using an HC-SR04 (ultrasonic sensor) with an Arduino Uno

code:

const int trigPin = 9;
const int echoPin = 10;

void setup() {
Serial.begin(9600); // Initialize serial communication
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}

//  ▄▄▄▄▄▄▄▄▄   ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄▄▄▄▄▄▄▄▄▄  ▄▄       ▄▄ 
// ▐░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░▌     ▐░░▌
//▐░█░█▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀▀▀  ▀▀▀▀█░█▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░▌░▌   ▐░▐░▌
//▐░▌▐░▌    ▐░▌▐░▌               ▐░▌     ▐░▌          ▐░▌          ▐░▌          ▐░▌       ▐░▌▐░▌▐░▌ ▐░▌▐░▌
//▐░▌ ▐░▌   ▐░▌▐░█▄▄▄▄▄▄▄▄▄      ▐░▌     ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌          ▐░▌       ▐░▌▐░▌ ▐░▐░▌ ▐░▌
//▐░▌  ▐░▌  ▐░▌▐░░░░░░░░░░░▌     ▐░▌     ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌          ▐░▌       ▐░▌▐░▌  ▐░▌  ▐░▌
//▐░▌   ▐░▌ ▐░▌ ▀▀▀▀▀▀▀▀▀█░▌     ▐░▌     ▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀ ▐░▌          ▐░▌       ▐░▌▐░▌   ▀   ▐░▌
//▐░▌    ▐░▌▐░▌          ▐░▌     ▐░▌     ▐░▌          ▐░▌          ▐░▌          ▐░▌       ▐░▌▐░▌       ▐░▌
//▐░█▄▄▄▄▄█░█░▌ ▄▄▄▄▄▄▄▄▄█░▌ ▄▄▄▄█░█▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄ ▐░▌ ▄        ▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄█░▌▐░▌       ▐░▌
// ▐░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌▐░▌       ▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░▌       ▐░▌
//  ▀▀▀▀▀▀▀▀▀   ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀  ▀         ▀▀▀▀▀▀▀▀▀▀▀  ▀▀▀▀▀▀▀▀▀▀▀  ▀         ▀
 
 

void loop() {
// Clear the trigger pin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);

// Send a 10μs pulse to trigger the HC-SR04
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

// Read the pulse duration from the echoPin
long duration = pulseIn(echoPin, HIGH);

// Calculate the distance (in cm) based on the speed of sound (343m/s)
float distance = (duration / 2.0) * 0.0343;

// Print the distance to the serial monitor
Serial.print(“Distance(Free Palestine): “);
Serial.print(distance);
Serial.println(” cm”);

delay(1000); // Update the distance reading every second
}

// ██████  ███████ ██ ███████ ███████     ██████  ██████  ███    ███ 
//██  ████ ██      ██ ██      ██         ██      ██    ██ ████  ████ 
//██ ██ ██ ███████ ██ █████   █████      ██      ██    ██ ██ ████ ██ 
//████  ██      ██ ██ ██      ██         ██      ██    ██ ██  ██  ██ 
// ██████  ███████ ██ ███████ ██      ██  ██████  ██████  ██      ██ 

0sief

Copyright © 2025 Osief | Powered by Astra WordPress Theme