Measuring distance – infrared and ultrasonic

A distance sensor is the most important sensor for any robot. It's usually referred to as the "eyes" of a robot. Distance sensors are very useful as we can make systems that react based on how close we are to them or based on the presence of various obstacles.

There are two common technologies used in amateur distance sensing: infrared sensors, such as the classic Sharp IR, and ultrasonic sensors, usually called sonars. Now, let's build a distance-controlled LED!

Getting ready

To build a distance-controlled LED, we will need the following ingredients:

  • An Arduino board connected to a computer via USB
  • One LED
  • A Sharp infrared proximity sensor such as the GP2Y0A21YK or the GP2Y0A02YK0F

How to do it…

Connecting ...

Get Arduino Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.