Arduino IR Detection (TCRT5000)


May 29, 2018 by aubreykloppers

This is quite an interesting one:

Files you will need:

What it does:

When you have nothing over the sensor, the BLUE LED is lit, when you have something over the sensor, the RED LED is lit.

Ardiono CODE:

const int irPin = 2; // Define the IR pin
const int ledRED = 7; // Red LED pin
const int ledBLUE = 6; // Blue LED pin
int irState = 0;

void setup() {
 // initialize the LED pin as an output:
 pinMode(ledRED, OUTPUT);
 pinMode(ledBLUE, OUTPUT);
 // initialize the IR pin as an input:
 pinMode(irPin, INPUT);
 // Switch on Serial Console:

void loop() {
 // read the state of the IR value:
 Serial.println(irState); // Check the state (Digital, will be 1 or 0) in Serial Console.
 irState = digitalRead(irPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
 if (irState == HIGH) {
 // turn LED on:
 digitalWrite(ledRED, HIGH);
 digitalWrite(ledBLUE, LOW);
 //delay(1000); //Keep the RED LED on for one second.
 } else {
 // turn LED off:
 digitalWrite(ledRED, LOW);
 digitalWrite(ledBLUE, HIGH);

The Fritzing schematic:


You can find a 4 second YouTube video here:

2 thoughts on “Arduino IR Detection (TCRT5000)

  1. j cooperider says:

    Please indicate what resistors you used and please complete schematic with missing connections to LED anode & phototransistor cathode


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

counter for wordpress
%d bloggers like this: