Vex Ultrasonic Sensor not responding

I’ve downloaded the Sensor Test code from the VexLabs site and have it compiled and running on my Vex controller. I have the Optical Encoder, Line Follower sensor, and Light sensor all working properly. I’m not getting any response from the Ultrasonic sensor.

I’m using MPLAB, C18 compiler, and Vex version of IFI Loader. I’m using the Vex_library_auton_debug.lib library. In the IFI Loader’s Com Terminal Window I see everything responding properly but no response from the Ultrasonic Sensor.

Is there any way to tell if this sensor is dead?


OK, I have it working now. Either it’s working because I reseated the connectors or most likely I happened to lean into the robot at the right distance for the sonic sensor’s test code to cause the led to go on. It seems to have a narrow band of distance at around one foot that it is responding to. I was most likely either too close or too far away for the test code to display when I tried earlier.


how well does the sensor work for you? ie distance how close to a target can you get and how far?

The documentation claims 3cm up to 3m range. The source code toggles an LED when the values are (fltHiResCounter >= 16) && (fltHiResCounter <= 19). This seems to correspond with about the distance I was standing away from the sensor. 16cm to 19cm may not be the exact distance but seems to be close to where I am when it turns on and off.

I have added some printf statements to my code that print out once a second and the values seem close to distances I would expect. I still have more testing to do.


If you need extra help with the SONAR range finder you can take a look at the driver I wrote. I found that the Vex Range Finder was generally a better product than the Parallax unit. Both are equally accurante but the Vex unit had a longer range. Since the Vex unit has the protective covering it’s ready to be mounted on a robot.

I would watch out for your use of printfs while using a range finder. I would keep the printfs at about 1/second. Otherwise, I have experienced poor distance accuracy.

Bringing this thread back from the dead…

I am just starting to use the Vex ultrasonic module, but haven’t had much luck. The inventor manual insert pages give different information than the sample code. The former implies that the “output” wires go to the output port of the Vex controller, and the “input” wires go to the interrupt port. However, the sample code says that the “input” wire goes to digital output 11, and the “output” wire goes to interrupt 1.

I’ve tried both ways (hopefully not a bad idea), and neither work. In the sample code “ultrasonictest.ecp”, the PrintToScreen doesn’t execute because my terminal window doesn’t display anything. If I comment out all of the ultrasonic function calls, the PrintToScreen call works properly.

Can someone please shed some light on this discrepancy?

Input to digital port 11, output to Inter 1 is correct.

int distance;


while (1) {
distance = GetUltrasonic(1,11);
PrintToScreen(“Distance = %d\r”,distance);

That should do it.