The HC-SR04 is an ultrasonic distance measuring sensor module. It is commonly used for measuring distances and detecting obstacles in various applications, such as robotics, home automation, and industrial projects. The sensor works on the principle of ultrasonic sound waves.
Here's a basic overview of how the HC-SR04 sensor works:
Ultrasonic Transmitter: The sensor has an ultrasonic transmitter that emits short pulses of ultrasonic sound waves.
Ultrasonic Receiver: It also has a receiver that listens for the echo of the transmitted ultrasonic waves.
Distance Calculation: The sensor calculates the time taken for the ultrasonic waves to travel to the target object and back. Using the speed of sound in the air, it then calculates the distance to the object.
Output: The sensor provides an output in the form of a pulse width or a voltage signal that corresponds to the measured distance.
The HC-SR04 typically has four pins:
VCC (Power): Connects to the positive power supply (5V or 3.3V).
Trig (Trigger): Sends a short pulse to trigger the sensor to transmit ultrasonic waves.
Echo: Receives the echo signal and outputs a pulse whose width corresponds to the distance.
GND (Ground): Connects to the ground of the circuit.
ESP32 and other microcontrollers are often used to interface with the HC-SR04 sensor, making it a popular choice for hobbyists and developers working on projects involving distance measurement or obstacle avoidance. The sensor's simplicity, low cost, and ease of use contribute to its widespread popularity in the maker community.
ESP32 board:
The ESP32 is a powerful microcontroller developed by Espressif Systems. It's renowned for its integrated Wi-Fi and Bluetooth capabilities, making it a popular choice for various IoT (Internet of Things) applications.
HC-SR04 ultrasonic Sensor
The HC-SR04 is an ultrasonic distance measuring sensor module.
Jumper Wires:
For making temporary connections and wiring between components.
Breadboard:
A breadboard is a useful tool for creating temporary electronic circuits. It allows you to connect components without soldering.
This represents the connections between the HC-SR04 ultrasonic sensor and the ESP32 board:
- Connect the VCC(+) pin of the HC-SR04 ultrasonic sensor to the 3.3V pin on the ESP32 board.
- Connect the Trig pin of the HC-SR04 ultrasonic sensor to GPIO16 pin on the ESP32 board.
- Connect the Echo pin of the HC-SR04 ultrasonic sensor to GPIO17 pin on the ESP32 board.
- Connect the GND(-) pin of the DHT22 sensor to any ground (GND) pin on the ESP32 board.
To measure the distance using an HC-SR04 sensor with an ESP32 board using MicroPython, you need to install the MicroPython firmware on your ESP32 and then write a Python script to interface with the sensor. Here's a simple example code :
1- Flash your ESP32 with MicroPython using this file esp32-20210902-v1.17.bin.
2- import this library : hc-sr04
3- Create a new Python script and write the following code:
1 2 3 4 5 6 7 8 9 10 11 12 |
import machine from hcsr04 import HCSR04 import time # inistalize the HC-SR04 sensor sensor = HCSR04(trigger_pin=16,echo_pin=17,echo_timeout_us=1000000) while True: # Calculate distance in centimeters between the HC-SR04 sensor and an object distance = sensor.distance_cm() # Display the distance int the console print('distance= ',distance,' cm') time.sleep_ms(100) |
This program continuously measures the distance between the HC-SR04 and the object sensor and prints the result.
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info