How to use a ping sensor to control a servo?

How do I control a servo using a ping sensor? I am using an arduino uno and don't know what the code would look like. I want to make it so that when the Ping sensor measures 5cm, the servo opens... lets say 10 degrees clockwise or another example would be if it meausers 10cm, the servo would open 20 degrees clockwise. I hope this helps. If there is something you don't understand, please share. Thanks :smiley:

Well the best way is to just learn how each device works separately. One is an input device, the ping sensor. Learn how to wire it up. Try out some of the example sketches and libraries that use that device. Then learn to use the output device, the servo. There are plenty of example sketches. Once you have a good understanding of each device on it's own and how they are used in a sketch, you should have little trouble combining them into one sketch that performs as you wish.


Okay, thanks for the help. :smiley: