*Note: this simplified circuit diagram does not quite match the physical layout of the pins. If you look closely at the ‘Top View’ schematic in the datasheet you will notice that the Collector (3) and Emitter (4) are physically located the other way around – which makes the wiring a little more messy.
The 220 ohm resistor between the +5V and Anode drives the IR LED input’s Forward Voltage in the range 1.2 – 1.5V at around 20mA. The 4.7K ohm resistor between the +5V and (3) Collector gives us a nice wide voltage change when an object is placed in the gap between the IR LED (1) (2) and the Detector (3) (4). I measured 96.5mV open and 5.31V closed. This gives a very sharp and reliable OFF/ON, LOW/HIGH, 0/1 digital input. Hooking up to an ANALOG input (A0) on my Arduino DUE showed values from the low 20′s open to 1023 closed – perfect!
So, how did I get that circuit diagram and those resistor values? I have to admit, I phoned a friend. My mate Ashley who actually understands this stuff explained the calculations like this:
- Look at the ‘Forward Voltage’ Vf on data sheet which shows 1.2V typical to 1.5V max at 20mA. (5V-1.2V)/.02A = 190Ohm. 220Ohm is close enough.
- Look at the ‘Light Current’ Il on datasheet 1.0 – 10 Ma. To get a nice strong voltage change across (3) Collector and (4) emmitter calculate the resistance required to leave about .5V with gap open. At 1mA the calculation is (5V-.5V)/.001A = 4500 Ohm.