Project 6 Black or white
1.Introduction
Have you seen a line tracking smart car? That is a car going along a line with specific color. In this lesson, we will learn how to achieve such result. Here, we will use a Line Tracking Sensor and a Piranha LED Module to help you better understand how it works.
2.Hardware required
EASY plug controller Board x1
USB cable x1
EASY plug cable x2
EASY plug Piranha LED Module x1
EASY plug Line Tracking Sensor x1
First, we will learn something about this Line Tracking Sensor.

This Line Tracking Sensor can detect white line in black and black line in white. The single line-tracking signal provides a stable output signal TTL for a more accurate and more stable line. Multi-channel option can be easily achieved by installing required number of line-tracking sensors.
The working principle is simple, using infrared light’s different reflectivity of different color, and converting the strength of the reflected signal into current signal.
Below are its specifications:
Power supply: +5V
Operating current: <10mA
Operating temperature range: 0°C ~ + 50°C
Output interface: 3-wire interface (1 - signal, 2 - power, 3 - power supply negative)
Output Level: TTL level
Size: 56.8*16mm
Weight: 3g
3.Connection Diagram
Now, connect the LED module to the D10 port of the controller board, and line tracking sensor module to D3 port using the EASY plug cables.

4.Sample Code
Connect the board to your PC using the USB cable; copy below code into Arduino IDE, and click upload to upload it to your board.
#define Sensor 3
#define ledpin 10
void setup()
{
pinMode(Sensor,INPUT);
pinMode(ledpin,OUTPUT);
Serial.begin(9600);
}
void loop()
{
int val =digitalRead(Sensor);
digitalWrite(ledpin,val);
Serial.println(val); // print the data from the sensor
delay(200);
}
5.Result
After power is on, open serial monitor, you can see the current value is 1, the LED on the module remains off and the Piranha LED is on. When you place a white card in front of the sensor, you can see the LED on the module turns on, the value changes to 0 and the Piranha LED turns off. Now, place a black card in front of the sensor, you can see the result is the same with when there is nothing in front of the sensor. This principle is applied to line tracking smart car by programming the result.