|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
|
|
#1
|
|||
|
|||
|
HC-SR04 Ultrasonic Distance Sensor wiring and programming
Ok, so here it goes. Stupid question time.
I am trying to find information about utilizing the HC-SR04 ultrasonic distance sensor in a FIRST Robotics FRC situation with the RoboRIO. Last year our seasoned programmer could not figure out how to use it and wound up giving up. He has since graduated and moved on to college and a computer science future. That was using C++. He told me that the four wire configuration was not compatible with RoboRIO and would have to use an arduino to translate. This year I have a transfer team member that is up on programming in Java and I once again asked about the HC-SR04 and was told "Oh that is an arduino only sensor". And yet I see articles regarding the "Venerable HC-SR04" sensor but found nothing on how to wire it or program for it. The sensor seems pretty standard, VCC: +5VDC Trig : Trigger (INPUT) Echo: Echo (OUTPUT) GND: GND What is it about this sensor that keeps it from being used with a RoboRIO? |
|
#2
|
|||
|
|||
|
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming
Seems like you would:
VCC: +5VDC Trig : Trigger (INPUT) - DIO<mm> Echo: Echo (OUTPUT) - DIO<nn> GND: GND To use the sensor you would: 1) Reset a Timer to 0 2) Set DIO<mm> to high 3) wait 10us 4) Set DIO<mm> to low 5) See if DIO<nn> is High 6) If high, read Timer, otherwise back to 5 (abort after 1 second) 7) Distance is per the formula Alternative to 5-7 (which also serves as a double check), see how long DIO<nn> is held high. |
|
#3
|
|||||
|
|||||
|
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming
LabVIEW has an example of how to use this sensor. It comes in the FRC Update package if you install LabVIEW.
You could use that as a guide and port the example to Java. |
|
#4
|
|||
|
|||
|
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming
So the SRF04 and the HC-SR04 are the same sensor?
|
|
#5
|
|||
|
|||
|
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming
NI RoboRio Manual states:
DIO, PWM, and Relay Lines The NI roboRIO provides the following DIO lines: • 3.3 V general-purpose DIO lines on the MXP • 3.3 V digital lines on the DIO, I2C, and SPI ports • 5 V digital lines on the PWM and Relay ports. HC-SR04 Specs State: VCC = +5VDC Trig = Trigger input of Sensor Echo = Echo output of Sensor GND = GND Is the variation between 3.3v (roboRIO output) and 5v (sensor requirement) where the problem may lay? Parameter Min Typ. Max Unit Operating Voltage 4.50 5.0 5.5 V |
|
#6
|
|||
|
|||
|
Re: HC-SR04 Ultrasonic Distance Sensor wiring and programming
If you need 5v, the AIO ports are 5 volts. Use 1v and 4v as the threshold, with 1-4 undefined.
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|