Documentation Index
Fetch the complete documentation index at: https://learn.pcbcupid.com/llms.txt
Use this file to discover all available pages before exploring further.
Interfacing an Ultrasonic Sensor with GLYPH-C6
Introduction
Ultrasonic sensors are electronic devices that calculate the target’s distance by emission of ultrasonic sound waves and convert those waves into electrical signals. The speed of emitted ultrasonic waves is faster than the audible sound. Working Principle of Ultrasonic sensor Ultrasonic sensor working principle is either similar to SONAR or RADAR which evaluates the target/object attributes by understanding the received echoes from sound/radio waves correspondingly. This guide will help you interface an HC-SR04 Ultrasonic Sensor with a GLYPH-C6 board. The HC-SR04 has mainly two essential elements- the transmitter and receiver. Using the piezoelectric crystals, the transmitter generates sound, and from there it travels to the target and gets back to the receiver component. The HC-SR04 Sensor emits ultrasonic waves at a frequency of around 40,000 Hz (though the actual frequency may vary slightly). These waves travel through the air until they encounter an object in their path. Upon hitting the object, the waves bounce back to the sensor. By measuring the time, it takes for the ultrasonic pulse to travel to the object and return, and knowing the speed of sound in air (approximately 340 meters per second at room temperature), you can accurately calculate the distance between the sensor and the object. To initiate the ultrasound emission, we set the Trig pin to a High state for 10 microseconds. This action triggers the transmission of an 8-cycle ultrasonic burst, traveling at the speed of sound. Immediately after sending this burst, the Echo pin goes high, indicating its readiness to receive the reflected wave from any objects in the vicinity. If there’s no object or reflected pulse detected, the Echo pin will return to a low state after 38 milliseconds due to a timeout. If there is a reflected pulse, causes the Echo pin to transition to a low state before the 38-millisecond timeout. By measuring the duration for which the Echo pin remains HIGH, we can ascertain the distance traveled by the sound wave, and consequently, the distance from the sensor to the object. The formula for calculating distance using the HC-SR04 sensor is: Distance = (Time taken by the wave to return(T) x Speed of sound(S) ) / 2 S corresponds to Sound speed = 343 measured in m/sec This formula divides the time by 2 because the wave travels from the sensor to the object and back again, so the total distance traveled is twice the distance between the sensor and the object. Here is a concise summary of its characteristics:- Power Supply: +5V DC
- Quiescent Current: < 2mA
- Working Current: 15mA
- Effectual Angle: < 15
- Ranging Distance: 2cm – 400 cm
- Resolution: 0.3 cm
- Measuring Angle: 30 degrees
- Trigger Input Pulse width: 10uS TTL pulse
- Echo Output Signal: TTL pulse proportional to the distance range
- Dimensions: 45mm x 20mm x 15mm
Step 1: Hardware Required
- Glyph Boards
- HC-SR04 Ultrasonic Sensor
- Jumper wires
- Breadboard (optional)
Step 2: Circuit Diagram
Connect the HC-SR04 sensor to the GLYPH-C6 board using the following pin configurations:- VCC to 5V (Standard HC-SR04 requires 5V)
- GND to GND
- TRIG to GPIO 18
- ECHO to GPIO 15
Step 3: Code Setup
- Open Arduino IDE
- Enter the following code into the Arduino IDE
Step 4: Upload the Code
- Connect the Board
- Connect your GLYPH board to your computer
-
Select the Board and Port
Do the following settings in your Arduino IDE,
Tools > Board > esp32 > Pcbcupid GLYPH C6
Tools > Portand select the port connected to your GLYPH.Tools > USB CDC on Boot >Enabled
- Upload the Code
- Click the upload button (➡️ icon) or use the shortcut
CTRL + Uin Arduino IDE to upload the code to the board.
Step 5: Check the Output on Serial Monitor
The Serial Monitor will display the distance to the detected object in cm as well as inches