09 March 2022
TCRT5000 IR sensor module is tested through the Arduino NANO board. The code was found on a website for the Arduino UNO board and modified for the NANO board.
// Dr. Tariq Javid as of 07 March 2022
// Arduino Nano ---> TCRT5000
// Modified code from https://github.com/DIY-Machines/TCRT5000
const int pinIRd = 0; // D0 Digital input
const int pinIRa = A0; // Analog input
const int pinLED = 13; // Builtin LED
int IRvalueA = 0;
int IRvalueD = 0;
void setup()
{
Serial.begin(9600);
pinMode(pinIRd,INPUT);
pinMode(pinIRa,INPUT);
pinMode(pinLED,OUTPUT);
}
void loop()
{
IRvalueA = analogRead(pinIRa);
IRvalueD = digitalRead(pinIRd);
if (IRvalueD == LOW) { // Detection
digitalWrite(LED_BUILTIN, HIGH);
}
else { // No Detection
digitalWrite(LED_BUILTIN, LOW);
// IRvalueD == 1;
}
Serial.print("Digital Reading = ");
Serial.print(IRvalueD);
Serial.print("\t Analog Reading = ");
Serial.print(IRvalueA);
Serial.print("\n");
// delay 1 sec
delay(1000);
}
No comments:
Post a Comment