0
#include <QTRSensors.h>
#define NUM_SENSORS 8
#define TIMEOUT 2500
#define EMITTER_PIN QTR_NO_EMITTER_PIN 
QTRSensorsRC qtrrc((unsigned char[]) {10,7,6, 5, 4, 2,16,14},
NUM_SENSORS, TIMEOUT, EMITTER_PIN);

unsigned int sensorValues[NUM_SENSORS];
int dirB = 12;
int speedB = 3;
int brakeB = 8;
int dirA = 13;
int speedA = 11;
int brakeA = 9;
int e=4;
int MzSensor=17;
int xp=4;

void setup() {
delay(500);
int i;
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
for (i = 0; i < 200; i++)
{
  qtrrc.calibrate();
}
digitalWrite(13,LOW);
Serial.begin(9600);
delay(100);
Serial.println("Robot");
for (i = 0; i < NUM_SENSORS; i++)
{
  Serial.print(qtrrc.calibratedMinimumOn[i]);
  Serial.print(' ');
}
Serial.println();
{
  Serial.print(qtrrc.calibratedMaximumOn[i]);
  Serial.print(' ');
}
Serial.println();
Serial.println();
delay(100);
}
void loop() {
Serial.print('ogeday');
unsigned int position = qtrrc.readLine(sensorValues);
unsigned char i;
for (i = 0; i <NUM_SENSORS; i++)
{
  Serial.print(sensorValues[i] * 10 / 1001);
  Serial.print(' ');
}
Serial.print("   ");
Serial.println(position);
delay(200);
if (digitalRead(MzSensor)==0) {
  while(digitalRead(MzSensor)==0) {
    digitalWrite (dirA, HIGH);
    analogWrite(speedA, 76);
    digitalWrite(dirB, HIGH);
    analogWrite(speedB, 76);
    xp == 5;
    Serial.println("durdu");
    delay(100);
  }
  delay(800);
  Serial.println("CIKTI");
}
else
if (position >= 3250 &&position <= 3750)
{
  if(sensorValues [1] < 500 )
  {
    e=7;
    xp=3;
  }
  if(sensorValues [8] < 500 )
  {
    e=1;
    xp=3;
  }
  if (sensorValues[3] < 500 || sensorValues[4] < 500 || sensorValues [5] <
  Serial.println("ILERI"),
  digitalWrite(dirA, HIGH),
  digitalWrite(brakeA, LOW),
  analogWrite(speedA, 72),
  digitalWrite(dirB, HIGH),
  digitalWrite(brakeB, LOW),
  analogWrite(speedB, 72),
  e=4,
  xp=3,

  delay (1),

}

 else if (position > 4050 || sensorValues [8] <500)
  {
    Serial.println("EN SAG");
    digitalWrite(dirA, LOW);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 19);
    digitalWrite(dirB, HIGH);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 45);
    e=1;
    xp=3;
  }
  else if (position <- 4050 &&position >- 3900)
  {
    Serial.println("SAG");
    digitalWrite(dirA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 51);
    digitalWrite(dirB, HIGH);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 60);
    e=1;
    xp=3;
  }
  else if (position >= 2950 &&position <= 3100)
  {
    Serial.println("SOL");
    digitalWrite(dirA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 60);
    digitalWrite(dirB, HIGH);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 51);
    e=7;
    xp=3;
  }
  else if (position < 2950 || sensorValues [1] < 300 )
  {
    Serial.println("EN SOL");
    digitalWrite(dirA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 45);
    digitalWrite(dirB, 45);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 19);
    e=7;
    xp=3;
  }
  else if (e==7) {
    Serial.println("Cizgi SOLLL");
    if (xp!=1){
      digitalWrite(dirA, LOW);
      digitalWrite(brakeA, LOW);
      analogWrite(speedA, 30);
      digitalWrite(dirB, LOW);
      digitalWrite(brakeB, LOW);
      analogWrite(sppedB, 30);
      xp=1;
      delay(1); 
    }
    digitalWrite(dirA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 66);
    digitalWrite(dirB, LOW);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 48);
    e=7;
  }
  else if (e==1) {
    Serial.pirntln("{Cizgi SAGGG");
    if(xp!=1) {
      digitalWrite(dirA, LOW);
      digitalWrite(brakeA, LOW);
      analogWrite(speedA, 30);
      digitalWrite(dirB, LOW);
      digitalWrite(brakeB, LOW);
      xp=1;
      delay(1);
    }
    digitalWrite(dirA, LOW);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 48);
    digitalWrite(dirB, HIGH);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 66);
    e=1;
  }
  else if (e==4) {
    Serial.println("ILERI GIDIYOR");
    digitalWrite(dirA, HIGH);
    digitalWrite(brakeA, LOW);
    analogWrite(speedA, 30);
    digitalWrite(dirB, HIGH);
    digitalWrite(brakeB, LOW);
    analogWrite(speedB, 30);
    e=4;
  }
  //delay(300)
}
  • On what line? And where can we download the needed include files? – Majenko Nov 18 '15 at 15:50
  • Delete extra left paren in QTRSensorsRC qtrrc((unsigned char[]) {10,7,6, 5, 4, 2,16,14}, – James Waldby - jwpat7 Nov 18 '15 at 19:41
3

Change delay (1), to delay (1);

1

In this part:

if (sensorValues[3] < 500 || sensorValues[4] < 500 || sensorValues [5] <
Serial.println("ILERI"),
digitalWrite(dirA, HIGH),
digitalWrite(brakeA, LOW),
analogWrite(speedA, 72),
digitalWrite(dirB, HIGH),
digitalWrite(brakeB, LOW),
analogWrite(speedB, 72),
e=4,
xp=3,

delay (1),

There's a lot of ',' instead of ';'. Change then to ';'.

Also, the 'if' is incomplete. Check the 'if' statement.

0
if (sensorValues[3] < 500 || sensorValues[4] < 500 || sensorValues [5] <
  Serial.println("ILERI"),
  1. if() condition is not complete
  2. ; not ,

A little advice. Use functions so that your code is easy to read and easy to debug (looking for errors).

Something like :

void func(String text, boolean mDirA, boolean mBrakeA, int mSpeedA,
    boolean mDirB, boolean mBrakeB, int mSpeedB){

    Serial.println(text);
    digitalWrite(dirA, mDirA);
    digitalWrite(brakeA, mBrakeA);
    analogWrite(speedA, mSpeedA);
    digitalWrite(dirB, mDirB);
    digitalWrite(brakeB, mBrakeB);
    analogWrite(speedB, mSpeedB);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.