Distance sensors are the most important sensors for any robot. It is often called the \"eye\" of a robot \". Distance sensors are very useful because we can react depending on how far we are from them or the presence of various obstacles. There are two common techniques for amateur distance sensing: infrared sensors, such as the classic sharp infrared and ultrasonic sensors, which are often called sonar. Now, let\'s build a distance. controlled LED! Build a distance- To control the LED, we need the following parts: it is easy to connect a clear IR. Maybe that\'s why it\'s so popular. Follow the following simple steps to connect one: the following code will read the value of the sensor, print it on the serial connection, and change the LED strength Using PWM to match the distance: first, we build- In the LED, for the second hand analog port where we connect the sharp infrared sensor: in the settings () Function, we only start the serial connection. We don\'t need to declare the LED pin as output because we use the analogy () Function, no declaration is required: in the loop () Function, the sensor of the continuously read value adopts analogRead ()function; Then we print it on the sequence: Because the PWM takes the value between 0 and 255 and the analog reading () The function returns a value from 0 to 1023, and we divide the value of analogRead () When we use it in analogy () : There is a huge market for distance sensors, with hundreds of different models. In general, we can find infrared sensors in the cheap amateur area. Such as sharp IR- Or ultrasonic sensors. The infrared sensor has a very narrow induction beam. This means that it can detect objects in tight places without interfering with other objects. However, if an object is too thin or has holes in its body, the sensor beam may go through it and give the wrong reading. Ultrasonic sensors commonly referred to as sonar use sounds higher than normal hearing frequencies to detect distances. It does this by sending out a short sound pulse and waiting for it to return. It measures the time it takes for the sound to propagate, bounce the object, and then return the sensor. Because the speed of the sound is known, the total time returned by the sound depends on the distance from the object. This creates a very wide induction beam. It is useful in many applications, especially when we need to detect large and complex objects. However, if we have an object in two ranges, the wide beam produces interference. It will always detect a closer one. One important thing to keep in mind is that the infrared sensor depends on the color of the object being measured, while sonar, in addition to the shape and distance of the object, is generally not affected by the parameters. More topics about sensors such as noise reduction, accelerometer or GPS can be found in my Arduino development manual.