Ultrasonic Sensor

My team last minute is using a Ultrasonic Sensor. It’s in analog and my code is fine. Initializing it by using, echoLocation = new AnalogInput(3);. Can’t figure out Volts to Distance and when I get the volts nothing is changing. It’s just printing, 0.007324218. It’s not moving no matter what I do.

What ultrasonic sensor? What distances is it rated for? If the object in front is placed too far forward or too close, you may get weird output.

Additionally, check to make sure you have the right port number. Analog inputs will read a small input value (on the order you’re seeing) if nothing is plugged in.

Volts to distance is pretty easy to figure out with linear sensors. For ease of view, just plot a series in a spreadsheet program like excel. Grab 12, 24, 36 inches for example. Put them in a line graph.

Then just use the algebraic formula, y = mx where me represents the linear voltage step. So, given that m = y/x, it should be pretty easy for you to see when you have it correct as the numbers should match your plot.

Before any of that actually works out, you need to have a voltage that is actually reading correctly from the sensor…which if you have a steady value yours is not.

Use the LiveWindow widget in Shuffleboard to view the voltage (will still work when the robot is disabled). Put something in front of the sensor, move it around, force the voltage to change until you see exactly which analoginput is the one your sensor is plugged into.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.