Arduino Opto Switch Module from old printer

You can find optical switches on many electronic devices. I found a couple of them when I disassembled a hp1510 printer.
Next, I will show you how to salvage opto switches from old devices and transform them into opto switch modules for Arduino.

An opto switch is composed of two parts: the emitter (marked with E) and sensor (marked with S).
The emitter is an infrared led and the sensor is a phototransistor that turns on when hit by a light beam.

After you take apart the opto switch from the device, there are some changes to make to transform it into a usable Arduino module. The pinout of the optical switch module will be Signal, Ground, Vcc.

The connections you will have to make are:

Emitter led (marked with E)

  • The Bottom pin from the emitter (usually black wire) is the ground.
  • The upper pin (usually red wire) is VCC and should be connected through a 220 Ohm resistor to Arduino VCC.

Sensor (marked with S)

  • The upper pin (usually green wire) from the sensor is ground and it is connected to ground together with the black wire of the emitter.
  • The bottom pin (can be a white wire) from the sensor, is positive and should be connected to +5v through a 10k resistor and to Arduino digital pin 3.
    After soldering all the components together, the next step is to test the optical switch module. We will receive feedback from the module in two ways: output sent to the Serial Monitor and blinking a led.
  • connect the long leg of the led to Arduino D7 through a 270 Ohm resistor
  • connect the short leg of the led to ground
  • connect the signal pin of the opto switch module to the Arduino D3
  • connect the Vcc pin of the module to Arduino VCC
  • connect the ground pin of the module to Arduino ground

The digital pin 3 on Arduino will be low when is no obstacle between emitter and sensor and high when the light is blocked.

After you made the connections between Arduino and the opto switch module, upload the following sketch to Arduino using Arduino Studio.
Open the Serial Monitor from Arduino Studio and set the baud rate to 9600 baud.
You can test the opto switch module bypassing an obstacle between emitter and sensor.

const int LED_PIN = 7;

void setup()
  pinMode(LED_PIN, OUTPUT);

void loop()
  if  (digitalRead(OPTOSWITCH_PIN) == 0)  
    // There is no obstacle between emitter and sensor
    digitalWrite(LED_PIN, HIGH);
    digitalWrite(LED_PIN, LOW);