├── .gitattributes ├── Line_Following_robot.ino └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /Line_Following_robot.ino: -------------------------------------------------------------------------------- 1 | const int lMotFwd=9; // connection on pin 9 left motor forward 2 | const int rMotFwd=10; //connection on pin 10 right motor forward 3 | const int lMotRev=11; //connection on pin 11 left motor reverse 4 | const int rMotRev=12; //connection on pin 12 right motor reverse 5 | const int onblack= 300; // reading for black line from sensor is less than this 6 | const int onWhite= 700; // reading for white line is greater than this 7 | 8 | void setup() { 9 | 10 | Serial.begin(9600); 11 | 12 | // pinMode(A0,INPUT); 13 | pinMode(A1,INPUT); //extreme left sensor 14 | pinMode(A2,INPUT); //left 15 | pinMode(A3,INPUT); // middle sensor 16 | pinMode(A4,INPUT); // right 17 | pinMode(A5,INPUT); // extreme right sensor 18 | 19 | pinMode(lMotFwd,OUTPUT); 20 | pinMode(rMotFwd,OUTPUT); 21 | pinMode(lMotRev,OUTPUT); 22 | pinMode(rMotRev,OUTPUT); 23 | 24 | 25 | 26 | } 27 | 28 | 29 | bool isOnBlack(int sensor){ 30 | 31 | if( sensor<=onblack) 32 | return true; 33 | else 34 | return false; 35 | } 36 | 37 | 38 | bool isOnWhite(int sensor){ 39 | if(sensor>=onWhite) 40 | return true; 41 | else 42 | return false; 43 | } 44 | 45 | 46 | 47 | 48 | void moveForward() 49 | { 50 | digitalWrite(lMotFwd,HIGH); 51 | digitalWrite(rMotFwd,HIGH); 52 | 53 | digitalWrite(rMotRev,LOW); 54 | digitalWrite(lMotRev,LOW); 55 | 56 | } 57 | 58 | void turnLeft() 59 | { 60 | digitalWrite(lMotFwd,LOW); 61 | digitalWrite(rMotFwd,HIGH); 62 | 63 | 64 | digitalWrite(rMotRev,LOW); 65 | digitalWrite(lMotRev,LOW); 66 | } 67 | 68 | 69 | void turnRight() 70 | { 71 | digitalWrite(lMotFwd,HIGH); 72 | digitalWrite(rMotFwd,LOW); 73 | 74 | digitalWrite(rMotRev,LOW); 75 | digitalWrite(lMotRev,LOW); 76 | } 77 | 78 | void turnCircle() 79 | { 80 | digitalWrite(lMotFwd,LOW); 81 | digitalWrite(rMotRev,LOW); 82 | digitalWrite(lMotRev,HIGH); 83 | digitalWrite(rMotFwd,HIGH); 84 | } 85 | 86 | void Stop() 87 | { 88 | 89 | digitalWrite(lMotFwd,LOW); 90 | digitalWrite(rMotFwd,LOW); 91 | digitalWrite(lMotRev,LOW); 92 | digitalWrite(rMotRev,LOW); 93 | 94 | } 95 | 96 | void loop() { 97 | // put your main code here, to run repeatedly: 98 | int sensor1=analogRead(A1);//sensor1 Extreme Left 99 | int sensor2=analogRead(A2);//sensor2 100 | int sensor3=analogRead(A3);//sensor3 middle 101 | int sensor4=analogRead(A4);//sensor4 102 | int sensor5=analogRead(A5);//sensor5 Extreme right 103 | Serial.print("extreme Left: "); 104 | Serial.print(sensor1); 105 | Serial.print("\t lower left: "); 106 | Serial.print(sensor2); 107 | Serial.print("\t middle: "); 108 | Serial.print(sensor3); 109 | Serial.print("\t lowerRight: "); 110 | Serial.print(sensor4); 111 | Serial.print("\t Extreme Right: "); 112 | Serial.println(sensor5); 113 | 114 | 115 | if( isOnBlack(sensor1)){ 116 | turnLeft(); 117 | }else{ 118 | 119 | if(isOnBlack(sensor3)&&isOnWhite(sensor1)){ 120 | moveForward(); 121 | }else 122 | 123 | if( isOnWhite(sensor1)&& isOnWhite(sensor3)&& isOnBlack(sensor5) ){ 124 | turnRight(); 125 | }else 126 | 127 | if(isOnBlack(sensor2)){ 128 | turnLeft(); 129 | }else 130 | if(isOnBlack(sensor4)){ 131 | turnRight(); 132 | }else 133 | if( isOnWhite(sensor1) && isOnWhite(sensor2) && isOnWhite(sensor3) && isOnWhite(sensor4) && isOnWhite(sensor5) ){ 134 | turnCircle(); // replace with left if gap is present 135 | } 136 | 137 | 138 | } 139 | 140 | 141 | } 142 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Line Following Robot 2 | ![GitHub forks](https://img.shields.io/github/forks/rawkush/line_following_robot?style=social) 3 | ![GitHub Repo stars](https://img.shields.io/github/stars/rawkush/line_Following_robot?style=social)
4 | ![ViewCount](https://views.whatilearened.today/views/github/rawkush/line_following_robot.svg) 5 | Line follower is an autonomous robot which follows either black line in white are or white line in black area. Robot must be able to detect particular line and keep following it. 6 | 7 | # LFR 8 |

9 | Video 1 10 | 11 |

12 | 13 | 14 | # Material Required 15 | 16 |

17 | 18 | ![Arduino](https://user-images.githubusercontent.com/25636146/48066148-d19f1880-e1f2-11e8-8c10-caba60d88e3d.png) 19 | 20 |

21 | 22 | #### Array of IR Sensors 23 |

24 | 25 | 26 | 27 |

28 |

29 | 30 | ![battery](https://user-images.githubusercontent.com/25636146/48066149-d237af00-e1f2-11e8-9d9c-ced5b219d001.png) 31 | ![casterwheel](https://user-images.githubusercontent.com/25636146/48066150-d237af00-e1f2-11e8-9971-300b789ebb71.png) 32 | ![female](https://user-images.githubusercontent.com/25636146/48066153-d2d04580-e1f2-11e8-8a5b-2bb422376ce9.png) 33 | ![frame](https://user-images.githubusercontent.com/25636146/48066154-d2d04580-e1f2-11e8-8373-e2692a99d61f.png) 34 | ![male](https://user-images.githubusercontent.com/25636146/48066155-d2d04580-e1f2-11e8-91c2-f484ad9f4819.png) 35 | ![motors](https://user-images.githubusercontent.com/25636146/48066156-d368dc00-e1f2-11e8-9e4a-ef4819fc5bf4.png) 36 | ![tyres](https://user-images.githubusercontent.com/25636146/48066157-d368dc00-e1f2-11e8-8342-7bd4e097c31a.png) 37 | ![9volt](https://user-images.githubusercontent.com/25636146/48066158-d368dc00-e1f2-11e8-8a5a-7ece0de08faf.png) 38 |

39 | 40 | # How to use 41 | 42 | Burn the code into arduino and make connection according to the code or just make your connection and change the pin number in the code 43 | --------------------------------------------------------------------------------