Using IR Sensor (TCRT 5000) With Arduino and Program to Remove Noise

About: I love making and flying RC planes.

In this instructable, basic circuitry for TCRT 5000 IR sensor and its working is discussed. a major focus of this instructable is on making a program which enables it to remove all kind of ambiance noise. So after using this method IR sensor need not be calibrated for different ambiance condition.

If you don't want to read complete instructable then go through this video:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Working of IR Sensor:

Distance measuring is very easy using IR sensor.
A beam of IR is transmitted to target and reflected beam is captured by the photodiode.

Photodiode measures the intensity of light (here mostly IR light). IR diode does not measure intensity of just IR light but it is also sensitive to visible light.

here, Intensity of IR light recorded by photodiode represents the distance between target and sensor.

Closer the target is the higher intensity of light is recorded and reduces with increase in distance.

Step 2: Making Circuit for Sensor:

we are driving out photodiode using a basic circuit. we can also use op amp based more accurate and better method for precise measurement.

IR LED is connected with 100 Ohm of the resistor in series to digital pin of Arduino. and the photodiode is connected to 5k Ohm of the resistor in series to 5v of supply and signal is taken out from it which goes to the analog input pin of Arduino.

Step 3: Checking Circuit:

Upload this code to arduino.

void setup()





void loop()

{ digitalWrite(6,HIGH);



Serial.println(a); }

Now turn ON serial plotter and move some target in front of the sensor. The plot also should move as per movement of the target displacement.

The problem with this method:

  • Measurement is ambiance sensitive. any change in light can ruin measurement.

For example, if we calibrate sensor at morning can not be used for evening. And even in indoor if we turn ON - Off room light, calibration get changed.

Step 4: Sources of Noise and Solution:

there are various sources of noise like:

  • IR radiation from the sun: the sun transmits a huge portion of IR radiation to earth. which captured by IR photodiode and reading is no more correct.
  • Indoor lighting: IR photodiode does not capture just IR light but also senses visible light transmitted by room lights.
  • Heat source: All heat source emits some sort of radiation which is captured by IR photodiode. the amount of this radiation so error depends upon temperature and size of a body.

These sources emit IR radiation, which is captured by IR Photodiodes. so the error is added to our measurement.


Ascan be shown in the third image,

If we turn ON led than photodiode measures noise+signal and if led turn Off photodiode receives just noise.

The difference in between this two values will give denoised data.

If we take two reading very fast enough denoising would get better.

attached code can be used to get pure/denoised data from the sensor.

Step 5: Testing Code for Denoising and Application

These pictures show RAW data, noise value and pure signal. you can also refer the video in which output from the sensor in presence of flashing light as well as static noise.

this approach can be used in line follower so that we do not need to calibrate sensor every time we use. it also can be used in some bots where IR sensor is used for the same advantage.

Arduino Contest 2016

Participated in the
Arduino Contest 2016

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    14 Discussions


    Question 6 months ago on Step 2

    Why did we connect the analog pin to the collector and not the emitter? Shouldn't the collector get data from digital pin?


    1 year ago

    For those people who recieved "a" not declared error :

    Add a "int" in front of the code a=analogRead(A3);

    It will look like this:

    int a=analogRead(A3);


    1 year ago

    a not declared ????


    Question 1 year ago

    Please give the code for denoising tcrt5000


    Question 1 year ago on Step 3

    When I upload this code to arduino it tells me that 'a' has not been declared?


    1 year ago

    Well, on the schematic drawing you show the photo-transistor in common emitter circuit.
    In that configuration, output will move from a high to low with more
    light over it as the resistance of the PT will get lower. What you
    measure though indicates you had it actually connected incommon collector circuit,

    ref: (circuit configurations)


    2 years ago


    I have TCND5000 Reflective Optical Sensor with PIN Photodiode Output.

    I think function of this same as tcrt5000.

    here I am connecting Anode of IR Led to 5v with 100ohm of resister and collecter is also connect to 5v with 5k ohm resister.and cathode of both connects to ground.

    the output is taken from the collector of photo transistor which I connect to Arduino Pin of A1.

    when I open a serial terminal I get constantly 98 98 98.........

    this value is not changing if I take any object near to TCND5000.

    help me. is there I need to connect any Op-amp IC.


    Reply 2 years ago

    It is serial plotter from Arduino IDE. Just update your Arduino IDE it is not available in older version.


    2 years ago

    Can this be done with an analog circuit ?

    What terms can I use to search about this argument ?
    Sorry for my noobness and thank you.

    2 replies

    Reply 2 years ago

    yes . This code is inspired from that circuit only called "Lock-In amplifier". this is very useful system to extract data (of known frequency) from extremely noisy signal.