Skip to main content

Interfacing Raspberry Pi 3 with an Ultrasonic Sensor (HC-SR04) - English & Marathi

Introduction

The HC-SR04 ultrasonic sensor is used to measure distance by sending and receiving ultrasonic waves. In this tutorial, we will interface the HC-SR04 sensor with Raspberry Pi 3 to measure the distance of an object.

HC-SR04 рдЕрд▓्рдЯ्рд░ाрд╕ोрдиिрдХ рд╕ेрди्рд╕рд░ рдЕрд▓्рдЯ्рд░ाрд╕ोрдиिрдХ рддрд░ंрдЧ рдкाрдард╡ूрди рдЖрдгि рдк्рд░ाрдк्рдд рдХрд░ूрди рдЕंрддрд░ рдоोрдЬрдг्рдпाрд╕ाрдаी рд╡ाрдкрд░рд▓ा рдЬाрддो. рдпा рдЯ्рдпूрдЯोрд░िрдпрд▓рдордз्рдпे, рдЖрдкрдг HC-SR04 рд╕ेрди्рд╕рд░рд▓ा Raspberry Pi 3 рд╢ी рдЬोрдбूрди рд╡рд╕्рддूрдЪे рдЕंрддрд░ рдХрд╕े рдоोрдЬाрдпрдЪे рддे рд╢िрдХू.


Components Required | рдЖрд╡рд╢्рдпрдХ рдШрдЯрдХ:

1. Raspberry Pi 3

2. HC-SR04 Ultrasonic Sensor

3. Jumper Wires

4. Breadboard


Circuit Diagram | рд╕рд░्рдХिрдЯ рдЬोрдбрдгी:


Connections:

- HC-SR04 VCC → 5V (Pin 2)

- HC-SR04 GND → GND (Pin 6)

- HC-SR04 Trig → GPIO23 (Pin 16)

- HC-SR04 Echo → GPIO24 (Pin 18)





Python Code | рдкाрдпрдерди рдХोрдб:

import RPi.GPIO as GPIO

import time

GPIO.setmode(GPIO.BCM)

TRIG = 23

ECHO = 24

GPIO.setup(TRIG, GPIO.OUT)

GPIO.setup(ECHO, GPIO.IN)

def measure_distance():

    GPIO.output(TRIG, True)

    time.sleep(0.00001)

    GPIO.output(TRIG, False)

    while GPIO.input(ECHO) == 0:

        pulse_start = time.time()

    while GPIO.input(ECHO) == 1:

        pulse_end = time.time()    

    duration = pulse_end - pulse_start

    distance = (duration * 34300) / 2  # Convert to cm

    return round(distance, 2)

try:

    while True:

        dist = measure_distance()

        print(f"Distance: {dist} cm")

        time.sleep(1)

except KeyboardInterrupt:

    GPIO.cleanup()

}


Explaination | рд╕рдордЬाрд╡рдгी:

1. The Trig pin sends a short ultrasonic pulse.

2. The Echo pin receives the reflected wave.

3. The time taken for the wave to return is used to calculate the distance.


Trig рдкिрди рдЕрд▓्рдЯ्рд░ाрд╕ोрдиिрдХ рдкрд▓्рд╕ рдкाрдард╡рддो, рдЖрдгि Echo рдкिрди рддो рдкрд░рдд рдпेрдгाрд░ा рд╕िрдЧ्рдирд▓ рдк्рд░ाрдк्рдд рдХрд░рддो. рд╡ेрд│ेрдЪ्рдпा рдЖрдзाрд░े рдЕंрддрд░ рдоोрдЬрд▓े рдЬाрддे.



Running the Code | рдХोрдб рдЪाрд▓рд╡िрдгे:

1. Save the script as `ultrasonic.py`

2. Run the script:

    python ultrasonic.py



Output | рдЖрдЙрдЯрдкुрдЯ:

Distance: 10.5 cm

Distance: 10.4 cm

Distance: 10.6 cm


Conclusion | рдиिрд╖्рдХрд░्рд╖:

Now, you have successfully interfaced the **HC-SR04 ultrasonic distance sensor** with Raspberry Pi 3! 


рдЖрддा рддुрдо्рд╣ी HC-SR04 рдЕрд▓्рдЯ्рд░ाрд╕ोрдиिрдХ рд╕ेрди्рд╕рд░рд▓ा Raspberry Pi 3 рд╕ोрдмрдд рдпрд╢рд╕्рд╡ीрдкрдгे рдЬोрдбрд▓े рдЖрд╣े! 

Stay tuned for the next sensor tutorial! ЁЯЪА | рдкुрдвीрд▓ рд╕ेрди्рд╕рд░ рдЯ्рдпूрдЯोрд░िрдпрд▓рд╕ाрдаी рддрдпाрд░ рд░рд╣ा! ЁЯЪА


Comments

Popular posts from this blog

IOT : GARDEN WATER SPRINKLER SYSTEM

IoT projects have gained immense popularity due to their ability to leverage the power of interconnected devices and data to create innovative solutions across various domains. IoT projects involve integrating sensors, actuators, and communication technologies to enable the seamless exchange of data between physical devices and the internet. These projects range from simple DIY experiments to complex industrial applications, each offering unique opportunities to transform our lives and improve efficiency. Whether it's creating a smart home automation system, monitoring environmental conditions, optimizing energy usage, or developing intelligent transportation systems, applications of IoT open up a world of possibilities for innovation and connectivity. By harnessing the potential of IoT, we can build intelligent and interconnected systems that revolutionize industries, enhance daily life, and pave the way for a more efficient and sustainable future. In this project we will be using...

TOUCH PLATE BASED DOOR BELL

Title:  Touch plate based door bell  Circuit:  Components: IC 555 Resistors: 1 M, 100k, 330 ohms Transistor: BC547  PN2222A Capacitor: 10n 1 Copper plate : as touch plate. A 6v battery An LED / Ic UM66 Description: This is the simple circuit for touch plate based security system. In this project what basically done is, circuit detects stray voltages produced by mains voltage and electrostatic built  up in the room.If sufficient static voltage is detected by the plate then chip will charge up. Transistor BC 547 or PN2222A is used basically to increase the sensitivity.In place of led just connect IC um 66(melody IC). Applications: In homes, of course. This can be specially used in places like hospitals, when patients need to call doctor by himself.

POWER BI - THE ARCHITECTURE

Power BI Architecture: A Comprehensive Guide to Building Effective Data Analytics Solutions     Understanding Power BI Architecture: Power BI's architecture comprises four main components, each playing a pivotal role in the data analytics process: Data Sources:   Power BI connects to a wide range of data sources, including databases, cloud services, Excel files, web services, and more. This versatility enables organizations to consolidate their data from various systems into a single dashboard. Data Transformation:   Once the data is sourced, it undergoes transformation and cleaning processes to make it suitable for analysis. Power BI's Power Query Editor provides a user-friendly interface to manipulate, filter, and shape data according to specific requirements. Data Model:   The heart of Power BI's architecture lies in its data model, whic...