Go Down

Topic: Line tracker robot problem (Read 701 times) previous topic - next topic

Uidualc

Hey guys. Before i say what my problem is I just want to tell you that this is my first project and i don't know that much about arduino.

I got a line tracker robot with a CTRT5000 sensor. I tried to find a code on the internet that i could adapt for my robot but when i checked the serial monitor all of my sensors are working but all 3 of them are having exactly the same value and my robot isn't working. Here is the Code I used.

Delta_G

OPs code:

Code: [Select]
/*created by Mostafa Zaghloul with a helper library called RedBot.h you can find
   it on this link https://github.com/sparkfun/RedBot
  --------------------------- thanks a million ---------------------------------
  you can find me on
  FaceBook::https://www.facebook.com/mostafa.zaghlol3
  Twitter::https://twitter.com/Mostafazaghlul
  to Contact for hardware or software questions
*/
#include <RedBot.h>

RedBotSensor left_sen = RedBotSensor(A3);
RedBotSensor center_sen = RedBotSensor(A4);
RedBotSensor right_sen = RedBotSensor(A5);
//data_sheet
// constants that are used in the code. lineStandard is the level to detect
// if the sensor is on the line or not. If the sensor value is greater than this
// the sensor is above a DARK line.
//
// SPEED sets the nominal speed
//motor A
#define en1 9
#define in1 4
#define in2 5
//motor b
#define en2 3
#define in3 6
#define in4 7
int lineStandard = 800;

// LOW white
// HIGH black

void setup()
{ pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(in3, OUTPUT);
  pinMode(in4, OUTPUT);
  pinMode(en1, OUTPUT);
  pinMode(en2, OUTPUT);

  pinMode(A3, INPUT);
  pinMode(A4, INPUT);
  pinMode(A5, INPUT);

  Serial.begin(9600);
  Serial.println("IR Sensor Readings:: ");
  delay(1000);
}

void loop()
{
  Serial.print(left_sen.read());
  Serial.print("\t");
  Serial.print(center_sen.read());
  Serial.print("\t");
  Serial.print(right_sen.read());
  Serial.println();


  if (right_sen.read() > lineStandard) left();
  if (left_sen.read() > lineStandard) right();
  if (center_sen.read() > lineStandard) forward();
  if ((right_sen.read() > lineStandard) && (center_sen.read() > lineStandard)) left();
  if ((left_sen.read() > lineStandard) && (center_sen.read() > lineStandard)) right();
  if ((left_sen.read() > lineStandard) && (center_sen.read() > lineStandard) && (right_sen.read() > lineStandard))
  { //stop
    Stop ();
  }
  if ((left_sen.read() < lineStandard) && (center_sen.read() < lineStandard) && (right_sen.read() < lineStandard))
  { //stop
    Stop ();
  }

  ////data_sheet
  //  // if on the line drive left and right at the same speed (left is CCW / right is CW)
  //  if(center_sen.read() > lineStandard)
  //  {//right
  //   right();
  //  }
  //  //data_sheet
  //  // if the line is under the right sensor, adjust relative speeds to turn to the right
  //  else if(right_sen.read() > lineStandard)
  //  {//left
  //  left();
  //  }
  //  //data_sheet
  //  // if the line is under the left sensor, adjust relative speeds to turn to the left
  //  else if(left_sen.read() > lineStandard)
  //  {//right
  //  right();
  //  }
  //  //data_sheet
  //  // if all sensors are on black or up in the air, stop the motors.
  //  // otherwise, run motors given the control speeds above.
  //  if((left_sen.read() > lineStandard) && (center_sen.read() > lineStandard) && (right_sen.read() > lineStandard) )
  //  {
  //    //stop
  //    Stop ();
  //  }
  //  else
  //  {
  //  //any dir
  //    forward();
  //  }
  delay(0);  // add a delay to decrease sensitivity.
}

void right() {
  analogWrite(en1, 0);
  analogWrite(en2, 155);
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}
void Stop () {
  analogWrite(en1, 0);
  analogWrite(en2, 0);
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}
void left() {
  analogWrite(en1, 155);
  analogWrite(en2, 0);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, LOW);
  digitalWrite(in4, LOW);
}
void forward() {
  analogWrite(en1, 155);
  analogWrite(en2, 155);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  digitalWrite(in3, HIGH);
  digitalWrite(in4, LOW);
}
void back() {

  analogWrite(en1, 155);
  analogWrite(en2, 155);
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  digitalWrite(in3, LOW);
  digitalWrite(in4, HIGH);
}
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Delta_G

You should probably link us out to that library you used.  I've never heard of that one before 
|| | ||| | || | ||  ~Woodstock

Please do not PM with technical questions or comments.  Keep Arduino stuff out on the boards where it belongs.

Uidualc

i searched from the arduino IDe software at the libraries but i found a link. Hope it can help
 https://github.com/sparkfun/SparkFun_RedBot_Arduino_Library/blob/master/src/RedBot.h

Uidualc

And if you don't mind can you please explain to me what OPs code means?

vinceherman

OP is the Original Poster, in this case, you.
Your code because you posted it as an attachment, not the preferred way.
Read through the 'How to use this forum please read' post at the top of this forum.

Uidualc

I corrected the post later. I read before i posted some debates about line tracker robots and somebody was pissed that the one that posted just copy+pasted the code without using the code function so not to piss somebody off i putted the original code from the pc. Sorry if I was wrong

Johan_Ha

Quote
all of my sensors are working but all 3 of them are having exactly the same value
So are they working or not? Get one working. Then get two, then three.

BTW, does an infrared sensor distinguish between black and other colours? Could it be that your line and its background simply reflect infrared equally much due to glossiness?
____________________

If you ask for help and write 'u' instead of 'you' because you think it's convenient, I will write 'no' instead of 'yes'. For same reasons.

Go Up