Ultrasonic sensor

How to compare the analog values of a potentiometer with the distance measured by an ultrasonic sensor?

If you know how to read the potentiometer value and you know how to measure the distance, just put them into variables and use an if statement to compare them.

Though since analog values are 0 to 1023 and distances are usually measured in cm or mm perhaps there is more to the question than you've told us?


 if (x < y) do_something();  //choose appropriate logical operator

Appears to be related to this post. Threads should be merged.

I have a question regarding the ultrasonic sensor, can you please help me out.

So the problem is that I have an ultrasonic sensor and a potentiometer and I want to set the ultrasonic sensor distance limit using a potentiometer and once the ultrasonic distance has attained the distance limit (that we have set using the potentiometer) I want to stop the ultrasonic sensor.

Can you please help me out, I have searched a lot about this but still not able to figure out anything.

It's unlikely that you will find code that exactly matches your requirements.

Why don't you start by showing what you have been able to do. Do you have the ultrasonic sensor working? Show your code (using the code tags...see </> in toolbar). Can you read the potentiometer? Show that code, too.

Also, read up on the map function - that will help you convert your potentiometer reading to your distance limit (although you could also just do it using math...can you think of how that would be done?) And if you don't know much about programming (how much DO you know?), then you should also read that reference section's info on control structures. Then go here and read all of the sections on basics and control structures.

Calibrate. Turn the potentiometer, measure the distance.