Below are the program sketch how to code a line following robots using Arduino, to detect Black Line & White Line when digital signal is HIGH, sensor will read black line and when digital signal is LOW, sensor will read white line.
The Sketch Code
|
int signalPin = 3; // connect the pin to digital pin 3 void setup() { pinMode(signalPin, INPUT); // initializing the digital pin as an output: Serial.begin(9600); // reading the serial communication port at 9600 bps: } void loop() // The code below will keep looping { if(HIGH == digitalRead(signalPin)) Serial.println("READ BLACK"); else Serial.println("READ WHITE"); // it will display the color " //delay(1000); // delay for a seconds } } |