In a previous episode of Cooking with Team 279, we covered how to use the MCP300x series Analog to Digital Converters (ADC) to read an analog signal and get a digital value back to use in the Pi.
One common, and inexpensive analog sensor type that may be used is the TCRT5000. These can be found very cheaply on Amazon and other sites. Note, if you search, you’ll find both a TCRT5000 and a TCRT5000L. The only difference between them is the “L” version has long leads.
The sensor combines an IR LED with an IR Sensor. These are attached to any circuit just as if they were individual components. The plastic package that binds them together simply ensures that the LED and Sensor are both angles to bounce an IR beam off an object to detect it. Note that the object most be pretty close! The sensor only works out to a couple centimeters (the data sheet notes it’s range from 0.2mm to 15mm). So if you need to detect something that is far away, this is not the right sensor to use. However, given it’s price and ease of use, it’s a good sensor for learning how to work with this general type of sensor.
Note that one end of the plastic housing is beveled on the corners. The wiring diagram below and in the datasheet shows the bevels to ensure you know which way to orient the sensor.
To use the sensor, power the LED and the sensor from 5V. Because you’re using 5V to drive this, make sure your ADC is using 5V as its reference voltage instead of 3.3V
Use a 220Ohm resister on the LED (or similar value.. higher value will limit it’s “brightness”, and use a 10K ohm resister on the sensor, as we don’t need much current and can limit it overall. Attach both of those resisters to ground.
Between the sensor negative lead and the resister, you connect the lead back to the ADC’s input channel. So, in the below diagram, where it says “To ADC Input”, it would connect to CH0 or CH1 on the MCP3002 shown below.
See the Analog to Digital episode for more information on using the MCP3002 (or 3008)
Once you’ve wired it up, and setup a program to read the analog value, you can move an object, or even your finger close to the sensor to see how it changes. When nothing is in front of the sensor, it should read close to zero (probably 20-40), and when your finger or the object is at the most effective reflective range, it should read >900 (out of the maximum 1023)