Ultra sonic range finder problems

Today I tried to write a program(using robot C) for the ultra sonic range finder, and the program did not work. I tried writing the sensor value to the lcd display, but the only value that I got was negative 1. The input is plugged into digital port one, and the output is plugged into digital port two(on a vex edr cortex.) I am wondering of it is a hardware issue or is it a programing issue?

Did you setup the Ultrasonic sensor in the robot configuration? Would you mind posting your code for us to review?

Also, there are several threads with programming examples if you do a search on the word Ultrasonic .

Try flipping the wires.

#pragma config(Sensor, dgtl1, sonarSensor, sensorSONAR_inch)

 while(SensorValue(sonarSensor) > 10  || SensorValue(sonarSensor) == -1)		
   {                                                                       
        sonar_value = SensorValue(sonarSensor);  .
       clearLCDLine(0);                          
       displayLCDPos(0,0);                      
       displayNextLCDString("Sonar: ");          
       displayNextLCDNumber(sonar_value);        
    motor[rightMotor] = 80;
        motor[leftMotor] = 80;
       }

Hi All
I tried flipping the wires and the value stayed at -1

Probably not the issue, but there is a period at the end of the line setting sonar_value.

Sorry, that was a typo. I have a new sensor coming from vex today to rule out hardware.

I assume there is something for it to sense within 10 feet? It will return -1 at < 1.5" and > 115".

yes with no affect on the number when changing the distance

What material is it looking at?
-1 is the generic ROBOTC number for invalid data. Could mean a lot of things.

Hi All
Thanks for your feedback. I was able to make it work. One of the pins on an extension cable pushed back slightly preventing it from fully engaging with the cortex. Also thank you Doug for your great videos. They have been a great help.

Heh, thank you for sitting through them. :slight_smile: