User Tools

Site Tools


Sidebar

electronics:sensor

Using the TCRT1000 and TCRT5000

Both components consist of an IR-LED and a photo transitor. The TCRT1000 is smaller and a bit less sensitive.

Datasheets: TCRT1000, tcrt5000

TCRT1000

  • R1 controls the LED current: lower R1 = more light
  • R2 controls the output voltage (sensitivity): higher R2 → more volts
  • The sensor is sensitive to direct ambient light. A high LED current improves the ratio LED light vs ambient light. A nominal value of 20 mA is optimal, this gives R1=220 Ohm. (I've tried 220, 1K and 4K7 (20, 4 and 1 mA)
  • When R2 is high (e.g. 22k), the sensor is quite sensitive to ambient light, an it detects white objects up to 2-3 cm. I found 2k2 to be a better value (much less sensitive to ambient light, detection range 5-10 mm
  • When connecting the output directly to a digital input, the switch threshold is not well defined (0.5-1.5 V, depends on hardware)
  • It is much better to measure the output with a ADC: trigger level is well known, can be calibrated for ambient light and can be changed without hardware modifications!

Test circuit and software

The above circuit was controlled by an Arduino (Nano V3, 5Volt). The power (5V in schema) was connected to a digital output The output was measured by an analog input

breadboard

Code

The software loops as follows

  1. switch power on
  2. wait 100 us
  3. switch sync output on (to show measuring moment on oscilloscope)
  4. measure
  5. light red/yellow/green LED depending on voltage (easier to check sensitivity)
  6. wait 100 us

Before measuring it is necessary to wait a little to let the sensor output voltage settle. 0.1 ms is more than enough.

In this way, about 5000 measurements are made every second! Reading 96 sensors on one input using multiplexing for the LED can easily be achieved in a fraction of a second.

int power=12;   // power to sensor
int sample=11;  // debug: we sample on rising edge
int measure = A7;  // analog sensor voltage (1023 = 5 V)
 
int green=2, yellow=3, red=4;
 
void setup() {
  pinMode(power, OUTPUT);
  pinMode(sample, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(red, OUTPUT);
 
  Serial.begin(9600);
  Serial.println("reset");
}
 
int cnt = 0;
float scale = 5./1024;      // scale factor ot volts
void loop() {
  digitalWrite(power, 1);   // power to led and transistor
  delayMicroseconds(100);   // wait for output to settle
 
  digitalWrite(sample, 1);  // make sample moment visible on scope
  int val = analogRead(measure);
  float volt = scale * val;  // sensor voltage 
  digitalWrite(red,    volt>0.8);
  digitalWrite(yellow, volt>1.3);
  digitalWrite(green,  volt>1.8);
  digitalWrite(sample, 0);
 
  digitalWrite(power, 0);
  delayMicroseconds(500);
  cnt = (cnt+1)%100;
  if (cnt==0) { Serial.println(volt,3); }
}

Measurements

  • A threshold of 1.3 V worked reliably in this setup (tcrt5000, white material). This should be tested with the actual sensors and materials.
  • Simple cheap hardware is good enough (arduino = 3 euro, allows 5000 10bit measurements per second)
  • The following measurements were made on a bright day near a window. The sensor was oriented sensitive side up. In this situation ambient light is not an issue (output voltage low, 0.3 V)
  • When the sensor is oriented towards a light source (window or light bulb), the sensor voltage increases to 0.5 - 1.5 V, making it very difficult to realize reliable proximity readings.
  • The response of the sensor is dependent on the color (near infrared reflectivity) of the target.
  • A threshold of 1.3 V worked reliably in this setup (tcrt5000, white material). This should be tested with the actual sensors and materials.

Circuit

Response to ambient light

Response to white plastic at 8-10 mm

Response to white plastic at 20 mm

Notes

Possible hardware architecture:

  • Read sensors with Arduino, manage Arduino by Raspbery Pi (serial communication by UART or I2C), use Raspberry to communicate with rest of the world (Python, WiFi, BT)
  • Read sensors by Raspberry (but it has no native ADC?)
  • Use a more advanced 'Arduino like' controller. Small low power low cost ESP32 boards have all the features: WiFi, ADC, BT, can be programmed in micropython (TODO: try this?). I my opinion the is a great choice: will allow direct interface via BT to mobile devices.
electronics/sensor.txt · Last modified: 2019/05/24 17:23 (external edit)