How to use Arduino Rangefinder with VEX Robot?

Hi, complete noob here. I’m making a robot for class and I want to use an ultrasonic range finder, but the teacher only has the Arduino HC-SR04 (rather than the VEX rangefinder). Would it be possible to use this piece along with the other VEX hardware, (and if so, how?)


Ya that should work. Configure it like a Vex ultrasonic in the software and plug the trig and echo pins into different digital ports.

I’m going to add a note from past experience with an Arduino rangefinder. (I think the same one, but I don’t have access to it now to check.) Periodically it would spit out really, really high values. This was true even when stationary and looking at a huge, flat, stationary surface. It seemed to err more often than the typical error rate I’ve heard discussed with rangefinders. So if you’re searching for above a certain value or, as my student was, for a sudden change it can be problematic. The solution I gave to him was a simple filter. Just check against more than one recent value, like the last two or three. Basically, if you take the smaller of two or the median (not mean!!!) of three, a single large value becomes irrelevant.

Thanks, and what should I do with the ground and VCC?

Connect to the power and ground of either echo or target. Doesn’t matter.

I am now experiencing issues with the values the rangefinder returns. I put Echo and Trig on the left in ports 8 and 9, VCC in the center for 8, and Ground on the right. Using the Forward until Close Proximity sample program I have found that the sensor does not seem to be returning values, only -1. Is there any trouble shooting method I can use to find returned values?

Swap echo and trigger.

Like this?

Yup that should be right. Input/trigger should be the lower number port according to

Use this simple sample program

#pragma config(Sensor, dgtl8,  Sonar,          sensorSONAR_mm)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

#pragma DebuggerWindows("debugStream")
task main()
		writeDebugStreamLine("Sonar Value is  %d",SensorValue[Sonar]);

You can use that but not in official VEX competitions as it is not a vex part.

He says its for a class and was wondering if it could work at all.

It’s still only returning a value of -1.