O'Reilly logo

Arduino Development Cookbook by Cornel Amariei

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required