The IR Track Sensor is essentially an IR LED and an IR detector. It works by transmitting a beam of IR light downward toward the surface. In this lesson, we will show you how the IR Track Sensor works and how to use it with the Osoyoo Uno board.
First, please plug OSOYOO Magic I/O shield into UNO board:
Then connect the OSOYOO IR tracking sensor to the port D2 of the Magic I/O shield with 3-pin PNP cables as below digram (please put the switch on tracking sensor to D):
After above operations are completed, connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.Open the Arduino IDE and choose corresponding board type and port type for you project. Then load up the following sketch onto your Arduino.
const int trackingPin = 2; //the tracking module attach to pin 2 const int ledPin = 13; //pin13 built-in led void setup() { pinMode(trackingPin, INPUT); // set trackingPin as INPUT pinMode(ledPin, OUTPUT); //set ledPin as OUTPUT } void loop() { boolean val = digitalRead(trackingPin); // read the value of tracking module if(val == HIGH) //if it is HiGH { digitalWrite(ledPin, LOW); //turn off the led } else { digitalWrite(ledPin, HIGH); //turn on the led } }
A few seconds after the upload finishes, set it down on a piece of paper with a dark line (at least ½” wide). You may use a Sharpie Marker, electrical tape, or dark paint. When the module gets on a black line, it output high and the corresponding LED stays off; when it meets a white area, it outputs low and the LED lights up.
Note:
1.The black line should be wider than the IR track sensor.
2.The sensitivity of the infrared sensor is adjustable – you may adjust it by the potentiometer.
DownLoad Url osoyoo.com