NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

/*
Easy Line Follower Robot -DIYhacking.com Arvind Sanjeev

Quick and easy line following robot using an IR reflectance
array.Connect Vcc and Gnd to the Pololu QTR-8A sensor from
the arduino. Connect the pins 1,2,3,... to arduino's analog
pins 0,1,2,3,4,5.
If the average of the 3 values of the sensors on the left is
greater than the average of those on the right, then the robot
moves left and vice versa.
NOTE : The values in the code for analog voltages would have
to be modified if you are not using the Pololu QTR-8A reflectance
array sensor. Use trial and error to find out max and min
values for your own IR array sensor.

*/
#include <Servo.h>

Servo left;
Servo right;

int mid = 0;
int mn = 0;
int mx = 0;

void setup()
{

left.attach(9, 800, 2200); //left servo motor
right.attach(10, 800, 2200); //right servo motor

Serial.begin(115200);

digitalWrite(13, LOW);

right.write(90);//stop signal
left.write(90);//stop signal

for(int i=0; i<5000; i++)
{
digitalWrite(13, HIGH);

int val = 0;
for(int j=0; j<=5; j++)//Calibrating the sensor, finding max and
{ //min reflectance values.
val = analogRead(j);
if(val >= mx)
mx = val;
if(val <= mn)
mn = val;
}
delay(1);
}

mid = ((mx + mn)/2);
digitalWrite(13, LOW);

right.write(90);
left.write(90);
}

void loop()
{

int s0 = 0;
int s1 = 0;
int s2 = 0;
int s3 = 0;
int s4 = 0;
int s5 = 0;

s0 = analogRead(0);//Signal pin 1 on the board
s1 = analogRead(1);//Signal pin 2 on the board
s2 = analogRead(2);//Signal pin 3 on the board
s3 = analogRead(3);//Signal pin 4 on the board
s4 = analogRead(4);//Signal pin 5 on the board
s5 = analogRead(5);//Signal pin 6 on the board

Serial.print("Mid: ");
Serial.print(mid);
Serial.print(" ");
Serial.print(s0);
Serial.print(" ");
Serial.print(s1);
Serial.print(" ");
Serial.print(s2);
Serial.print(" ");
Serial.print(s3);
Serial.print(" ");
Serial.print(s4);
Serial.print(" ");
Serial.print(s5);
Serial.print(" ");
Serial.println();

right.write(180);//Move forward
left.write(0);//Move forward

delay(1);

if((((s0+s1+s2)/3)>(((s3+s4+s5)/3)+240)))//Move right
{
right.write(130);//180
left.write(90);//90
Serial.print(" RIGHT");
delay(abs((((s5+s4+s3)/3)-((s0+s1+s2)/3))/2));
}

if((((s0+s1+s2)/3)<(((s3+s4+s5)/3)-240)))//Move left
{
right.write(40);//90
left.write(0);//0
Serial.print(" LEFT");
delay(abs((((s5+s4+s3)/3)-((s0+s1+s2)/3))/2));
}

if((s0 > mid)&&(s5 > mid))//Stop if all the sensors give low
{ //reflectance values
right.write(90);
left.write(90);
Serial.print(" STOP");

for(int k=0; k<50; k++)
{
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(100);
}
delay(5000);
}


}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.