Jump to content

Component: Ultrasonic (HCSR04) (Audio): Difference between revisions

From Flowcode Help
No edit summary
m Text replacement - "style="background-color:#EAE1EA;"" to "class="mtx-class-propfolder""
 
(14 intermediate revisions by 2 users not shown)
Line 5: Line 5:
|-
|-
| width="20%" style="color:gray;" | Version
| width="20%" style="color:gray;" | Version
| 1.0
| 9.0
|-
|-
| width="20%" style="color:gray;" | Category
| width="20%" style="color:gray;" | Category
Line 12: Line 12:




==Ultrasonic (HCSR04) component==
==Ultrasonic component==
This  board  has  both  an  ultrasonic  transmitter  and receiver.  When the Trig pin is set high for 10uS, the transmitter sends eight 40KHz pulses.  The Echo pin goes high about 2ms later.  The duration of the Echo pin is measure when it goes high, and a distance is then calculated based on the high duration. The distance of objects in a range of around 3cm to 2.75m can be determined.  
This  board  has  both  an  ultrasonic  transmitter  and receiver.  When the Trig pin is set high for 10uS, the transmitter sends eight 40KHz pulses.  The Echo pin goes high about 2ms later.  The duration of the Echo pin is measure when it goes high, and a distance is then calculated based on the high duration. The distance of objects in a range of around 3cm to 2.75m can be determined.  


==Component Source Code==
==Version information==


Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Ultrasonic_HC_SR04.fcfx FC_Comp_Source_Ultrasonic_HC_SR04.fcfx]
Library Version, Component Version, Date, Author, Info
9, 9.0, 30-07-24, MW, Fixed a (499) undefined symbol error


Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Ultrasonic_HC_SR04.fcfx FC_Comp_Source_Ultrasonic_HC_SR04.fcfx]


==Detailed description==
==Detailed description==




Line 46: Line 49:


==Examples==
==Examples==




Line 70: Line 75:
{{Fcfile|HC-SR04 Distance Sensor Demo.fcfx|HC-SR04 Distance Sensor Demo.fcfx}}
{{Fcfile|HC-SR04 Distance Sensor Demo.fcfx|HC-SR04 Distance Sensor Demo.fcfx}}


==Macro reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDistance'''
|-
| colspan="2" | Sends a pulse and processes the echo. Returns a object distance in cm 
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}








==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | OutputTrig Pin
|-
| colspan="2" | Pin used for controlling the output pulse 
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | Input Echo Pin
|-
| colspan="2" | ADC channel used to monitor the echo 
|}==Macro reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDistance'''
|-
| colspan="2" | Sends a pulse and processes the echo. Returns a object distance in cm 
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}








==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
==Macro reference==
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | OutputTrig Pin
|-
| colspan="2" | Pin used for controlling the output pulse 
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | Input Echo Pin
|-
| colspan="2" | ADC channel used to monitor the echo 
|}==Macro reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
===GetDistance===
{| class="mtx-class-macrotable wikitable"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDistance'''
| width="90%" class="mtx-class-macrohead" | '''GetDistance'''
|-
|-
| colspan="2" | Sends a pulse and processes the echo. Returns a object distance in cm 
| colspan="2" | Sends a pulse and processes the echo. Returns a object distance in cm 
Line 151: Line 101:
| width="90%" style="border-top: 2px solid #000;" | ''Return''
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
|}




==Property reference==
==Property reference==


{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
{| class="mtx-class-macrotable wikitable"
|-
| width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]]
| width="90%" class="mtx-class-macrohead" | '''Properties'''
|-
|-
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" | Type
|-
| colspan="2" |  
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-7-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| width="90%" | Use Timer Interrupt
|-
|-
| colspan="2" | For 8bit PICs resuls the timer interrupt  is recomened for increased accuracy 
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
Line 172: Line 130:
|-
|-
| colspan="2" | ADC channel used to monitor the echo 
| colspan="2" | ADC channel used to monitor the echo 
|}==Macro reference==
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" align="center" | [[File:Fc9-comp-macro.png]]
| width="10%" align="center" | [[File:Fc9-type-15-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''GetDistance'''
| width="90%" | Rollover Time
|-
|-
| colspan="2" | Sends a pulse and processes the echo. Returns a object distance in cm 
| colspan="2" | Maximim rollover time in seconds. Make sure its the lowest value posisble without going below 0.018 0.018 = 18ms which equates to a distance of 310 cm 
|-
|-
| width="10%" align="center" class="mtx-class-propfolder" | [[File:Fc9-conn-icon.png]]
| width="90%" class="mtx-class-propfolder" | Timer Settings
|-
|-
| width="10%" align="center" style="border-top: 2px solid #000;" | [[File:Fc9-u16-icon.png]] - UINT
| width="90%" style="border-top: 2px solid #000;" | ''Return''
|}
==Property reference==
{| class="wikitable" style="width:60%; background-color:#FFFFFF;"
|-
|-
| width="10%" align="center" style="background-color:#D8C9D8;" | [[File:Fc9-prop-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-16-icon.png]]
| width="90%" style="background-color:#D8C9D8; color:#4B008D;" | '''Properties'''
| width="90%" | Timer
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="90%" | OutputTrig Pin
|-
|-
| colspan="2" | Pin used for controlling the output pulse 
| colspan="2" | Timer Peripheral to use to monitor the passage of time. 
|-
|-
| width="10%" align="center" | [[File:Fc9-type-5-icon.png]]
| width="10%" align="center" | [[File:Fc9-type-21-icon.png]]
| width="90%" | Input Echo Pin
| width="90%" | Bit Depth
|-
|-
| colspan="2" | ADC channel used to monitor the echo 
| colspan="2" | Number of bits in the timer peripheral. 8-bit timers can count from 0-255 before overflowing. 16-bit timers can count from 0 to 65535 before overflowing. 
|}
|}
==Component Source Code==
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_Ultrasonic_HC_SR04.fcfx FC_Comp_Source_Ultrasonic_HC_SR04.fcfx]
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_Ultrasonic_HC_SR04.fcfx FC_Comp_Source_Ultrasonic_HC_SR04.fcfx]

Latest revision as of 14:37, 13 July 2026

Author Matrix TSL
Version 9.0
Category Audio


Ultrasonic component

This board has both an ultrasonic transmitter and receiver. When the Trig pin is set high for 10uS, the transmitter sends eight 40KHz pulses. The Echo pin goes high about 2ms later. The duration of the Echo pin is measure when it goes high, and a distance is then calculated based on the high duration. The distance of objects in a range of around 3cm to 2.75m can be determined.

Version information

Library Version, Component Version, Date, Author, Info
9, 9.0, 30-07-24, MW, Fixed a (499) undefined symbol error


Detailed description

No detailed description exists yet for this component

Examples

HC-SR04 Distance Sensor Demo.fcfx







Macro reference

GetDistance

GetDistance
Sends a pulse and processes the echo. Returns a object distance in cm 
- UINT Return


Property reference

Properties
Type
 
Use Timer Interrupt
For 8bit PICs resuls the timer interrupt is recomened for increased accuracy 
OutputTrig Pin
Pin used for controlling the output pulse 
Input Echo Pin
ADC channel used to monitor the echo 
Rollover Time
Maximim rollover time in seconds. Make sure its the lowest value posisble without going below 0.018 0.018 = 18ms which equates to a distance of 310 cm 
Timer Settings
Timer
Timer Peripheral to use to monitor the passage of time. 
Bit Depth
Number of bits in the timer peripheral. 8-bit timers can count from 0-255 before overflowing. 16-bit timers can count from 0 to 65535 before overflowing. 

Component Source Code

Please click here to download the component source project: FC_Comp_Source_Ultrasonic_HC_SR04.fcfx

Please click here to view the component source code (Beta): FC_Comp_Source_Ultrasonic_HC_SR04.fcfx