VexCode Sonar

Is the “Sonar” referenced in VexCode the Ultra Sonic Range Finder 276-2155?
Does the second wire from the sensor just get plugged into the (3) wire port on the brain?

Yes the sonar is the Ultra Sonic Range Finder. In VEXcode if you type like: Sonar sonar = Sonar(Brain.ThreeWirePort.A); it will automatically the output to port B. However, you can only do this with the “odd” ports (A, C, E, F). Hope this helps and good luck this season!


It works!!! Thank you for the heads-up odd numbered ports.

1 Like

This isn’t working for us. Anyone have working sample code in c++ for a simple Sonar Rangefinder program?

Are you using vcs this season, because if you are I highly recommend that you switch to VEXcode. VEXcode is basically vcs but it hasn’t been discontinued. In VEXcode one of the sample programs is displaying the output of the ultrasonic sensor. In this code it shows how to display the range so with that you should be able to implement it into any other code.

Good luck this season!!

We are using VexCode Text to write our programs. Where can I find the displaying output of the ultrasonic sensor sample program?


It should be under example programs when creating a new program.

Good luck!

Found it and got it working. Thank you for the help!

I don’t think you can name it sonar though. I think you need something like

vex::sonar sonar1 = Sonar(Brain.ThreeWirePort.A)

when I was just using the name sonar without the 1 I was getting an error.

Yeah you can’t. Sorry for not letting you know in advance