The infrared sensor used in Lesson 12 and some projects is a simple, 3-pin device. Yet a common complaint from students is, "it doesn't work."
Most often this is because the schematic diagram is interpreted as a pictorial. The schematic diagram in Lesson 12 appears to show the middle lead of the sensor going to the Arduino digital pin and the two outside pins going to +5 volts and ground. THIS IS WRONG! Remember, a schematic is not a pictorial.
Earlier in the Lesson is a picture of an IR sensor that identifies which lead has which number. Here's how to determine which lead goes where:
- Hold the sensor in your hand with the raised "bump" or circle facing you, and the leads going down. You are now looking at the front of the sensor.
- Look at the lead to your LEFT. It is number 1 and is to be connected to the Arduino digital pin.
- Look at the lead in the MIDDLE. It is number 2 and is to be connected to ground.
- Look at the lead to your RIGHT. It is number 3 and is to be connected to +5v.
CAUTION: incorrect connection can damage an infrared sensor. By damaged is meant won't work and should be thrown away.
HOW TO TEST AN INFRARED SENSOR
To test your IR sensor you need a voltmeter and a working infrared remote control, such as might be used for a television set. The steps are:
- Connect the IR sensor pin 1 (the LEFT one as it faces you) to the positive lead of the voltmeter.
- Connect the IR sensor pin 2 (the MIDDLE one) to ground on the Arduino.
- Connect the IR sensor pin 3 (the RIGHT one as it faces you) to +5v on the Arduino.
- Connect the voltmeter negative lead to ground on the Arduino.
- Connect the Arduino to power. Plugging it into a computer's USB port is an easy way to do this.
- Set the voltmeter to read DC voltage with a range greater than 5 volts.
- Look at the voltage being displayed on the voltmeter. It should be very close to 5 volts. By "very close" is meant within 1/10th volt.
- While watching the voltmeter point the remote control at the IR sensor then press and hold one of the buttons. If the voltage drops significantly the sensor is working. By dropping significantly is meant the voltage is 4.8 volts or lower.