PC Services"From Payroll to Body Scanners"Established 1994 |
PC Services (Electronics)Circuit Diagram Ultrasonic Distance Sensor HC-SR04 |
Tel: 0118 946 3634 |
Circuit Ultrasonic Range SensingSince my original findings some more detailed analysis has revised my analysis and not be swayed by other people's analysis. Some parts have been changed and the change is shown. I had a batch of these boards to test at least one was known to be faulty, so I did some work to get the tools to test and fix these boards, which resulted in these pages for students and others to follow. This section details with the electronics such items as
Previous Pages cover
OverviewFirst thing to understand is that the order of events is
This round trip or echo is also known as a PING from submarine and sea depth sensing. Measured Timings on HC-SR04This section breaks down the timings shown in above picture to show how the timings are made up, from images like the ones below. The detailed timings are shown for an object 9.5 cm away -
Version of HC-SRO4The HC-SR04 is a cheap Ultrasonic Distance Sensor available all over the price very cheap and fairly reliable, however its accuracy is +/- 3 mm. This accuracy means that anything less than 1 cm measurement is at best a guess.
HC-SRO4 Circuit DiagramAs stated before as I had a batch of these sensors to test and at least one had a faulty component for sure I did some reverse engineering side by side comparisons between working and failing units. Along with searchs online that got me to circuit descriptions and circuit diagrams, but these were earlier revisions of the circuit, but good starting points. The main sites you should also look at for alternative viewpoints are -
All the software examples use Arduino things like builtin functions pulseIn() or libraries like Ping or NewPing, whilst you can use these for your software as discussed in betterecho, I find these have too many overheads or issues. Having looked at the circuit diagrams on these sites and reverse engineering, I draw up a circuit in my CAD software and produced much smaller file size diagrams, that were easier for me to follow and use. The circuit is shown below and the link to a PDF version of the circuit. My version of circuit diagram is available in PDF version here (size 22 kB) or viewable on screen below ![]() HC-SR04 Circuit Diagram (click to enlarge) HC-SRO4 Circuit DescriptionThe Unit consists of three parts - microcontroller, Transmitter and Receiver (with associated amplifiers). Please use the circuit diagram above for reference to this description. Microcontroller U1The heart of the unit is is the EM78P153 8-bit microprocessor from Elan (U1). This handles
Transmitter U3On older revisions this was a MAX232, as of yet as the pin out is vastly different I am not sure what actual device it is as the numbers have been scrubbed off. It appears to be some form of transistor array device or Buffer device or ASIC. However some of its functionality has been found out.
Receiver U2The quad op-amp IC (U2) is a LM324 which is a fairly old low grade 1 MHz unity gain bandwidth device, with limited range I/O (outputs do not go to rails). It is a ubiquitous and cheap device. Considering some of the gain levels used in the stages means that 40 kHz signals are passing through stages with around 100 kHz bandwidth. Large offset errors may effect some of the stages as well, when gained up. The receiver is a chain of three op-amps as small signal stages all AC-coupled, being used in single rail configuration, the final stage is a variable threshold hysteris comparator with output switch. Each of the first three stages are an inverting amplifier or filter with positive input to mid-rail supply rail to apply offset for single power rail operation. the mid-rail supply is provided by R14, R15 and C6.
C1, C3 and C4 provide AC coupling between the stages. First stage (U2D, R1 and R2) is an inverting amplifier of the RX transducer signal, with gain around 5.6 (allowing for tolerances). The output is attenuated with reference to mid-rail by R3 and R4. Second stage (U2C, C2, C3 and R5) is a bandpass filter hopefully with tolerances centred around 40 kHz the frequency of the emitted pulses.
Third stage (U2B, R6 and R7) is another amplifier with gain of approximately 10. The last op-amp stage is a variable threshold hysteris comparator with output switch, the output witch is formed by a transistor in U3 and pullup resistor R17. This output is part of the feedback on the hysterisis comparator via R9. R10 and R16 si a potential divider to get the correct base voltage for the transistor in U3. The variable threshold comes from R13 and R12, with decoupling and ground path filtering by C8 and R11. One end of R13 is tied to mid rail for normal threshold, whilst a 'Threshold' signal from the micro via R12 pulls the threshold on pin 2 closer to ground, thus forcing the output higher and the transistor in U3 on, to clamp the signal to the micro during TX burst transmission. Thus avoiding false echos too early. Unfortunately I have found that problems in this area like R16 open circuit or bad (wrong value) parts like C8 can cause all sorts of problems with erratic readings. personally this would have been better with a proper Schmitt Trigger op-amp stage with HARD threshold control without C8 better timed from the micro from start of Trig pulse to end of TX burst (setting ECHO HIGH). Personally instead of changing the threshold, it would be better to clamp the input from the sensor by a FET across the sensor pins. Known Hardware Faults On Faulty Units
Previous Pages cover
Interested in something similar contact sales. |
© 2017 onwards by PC Services, Reading UK | Last Updated: 17th May 2018 |
If you encounter problems with this page please email your comments to webmaster |