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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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 } } |
Coding a Line Finder with Arduino Module Sensors for Robotics