An infrared proximity sensor works by shining infrared (IR) light out and detecting the intensity of light that’s reflected. If something relatively reflective is quite close to it, the sensor will see a strong reflection, and as that thing gets farther away, the intensity will fall off. The effective range for the LTH 1550-01 (ioRef #0237) is maybe 1–20cm (0.5–8”), depending on the ambient light level.

The circuit

IR proximity sensor schematic.

This part simply packages two components right next to each other: an infrared-emitting LED, and an infrared-sensing phototransistor. Looking at the schematic, you can see that you’re always keeping the IR emitter powered, using a 220Ω resistor to limit the current that flows through it.

Attached to the phototransistor’s emitter pin, we build a voltage divider using a 5.6kΩ resistor to get a good read of the output value using an Arduino analog input pin.

Arduino code to read an analog value and print via the serial monitor

This is generic code for doing an analog read of an input pin and reporting the results to the Serial Monitor.


const int PHOTORESISTORPIN = A0; // shortcut to refer to the photoresistor pin later

void setup() {
  pinMode(PHOTORESISTORPIN, INPUT); // we will be reading the photoresistor pin as an input
  Serial.begin(9600); // starts serial communication at 9,600 baud (the rate)
}

void loop() {
  int readVal; // initialize a new integer to store the photocell value
  readVal = analogRead(PHOTORESISTORPIN); // do the analog read and store the value
  Serial.println(readVal); // push the most recent value to the computer
  delay(50); // slow the loop down a bit before it repeats
}