Arduino IR Detection (TCRT5000)

Leave a comment

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:
 Serial.begin(9600);
}

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:

IR

You can find a 4 second YouTube video here:

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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

%d bloggers like this: