Arduino Line follower/ Ping sensor maze runner

Hello everyone,

I am trying to build a robot that follows a line to a maze using QTI sensors, and then navigates the maze using ping sensors.

I am having difficulty getting my motors to run when they are supposed to. In the code I have provided, the motors should run when QTI #2 is less than 100, yet they will not turn. I have checked my motors with a basic code, and they do function as intended. (code is attached).

I am new to programming the arduino, but have experience using basicstamp bs2 for parallax boards. Please excuse my lack of technical wording, I am a student.

Maze_Runner_Code_V3.ino (2.49 KB)

Please post your code.

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1 5
#define QTI2 6
#define QTI3 7

void setup() {

pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
servo1.attach(motor1Pin, 1000, 2000);
servo2.attach(motor2Pin, 1000, 2000);
Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
unsigned long echo;

pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
delayMicroseconds(2); // Wait for 2 microseconds
digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
delayMicroseconds(5); // Wait for 5 microseconds
digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
return (echo / 58.138) * .39; //convert to CM then to inches

}
void loop()

{

Serial.println();
Serial.print("QTI1 = ");
Serial.print(RCTime(QTI1));
Serial.println();
Serial.print("QTI2 = ");
Serial.print(RCTime(QTI2));
Serial.println();
Serial.print("QTI3 = ");
Serial.print(RCTime(QTI3));
delay(100);

unsigned long ultrasoundValue;
for (int i = 0; i < 2; i++) {
ultrasoundValue = ping(i);
Serial.println();
Serial.print(pingString*);*

  • Serial.print(ultrasoundValue);*
  • Serial.print("in, ");*
  • delay(25);*
    }
    }
  • long RCTime(int sensorIn) {*
  • long duration = 0;*
  • pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT*
  • digitalWrite(sensorIn, HIGH); // Pin HIGH*
  • delay(1); // Waits for 1 millisecond*
  • pinMode(sensorIn, INPUT); // Sets pin as INPUT*
  • digitalWrite(sensorIn, LOW); // Pin LOW*
  • while (digitalRead(sensorIn)) { // Waits for the pin to go LOW*
  • duration++;*
  • }*
  • return duration; // Returns the duration of the pulse*

if (RCTime(QTI2) < 100) {
servo1.write(120);
servo2.write(120); // fast
delay(1000); //for 1/10 second
}

  • }*

You forgot these [code][/code]

Please edit your last post.

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right  Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1 5
#define QTI2 6
#define QTI3 7


void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  servo1.attach(motor1Pin, 1000, 2000);
  servo2.attach(motor2Pin, 1000, 2000);
  Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
  unsigned long echo;

  pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
  pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
  echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
  return (echo / 58.138) * .39; //convert to CM then to inches



}
void loop()

{

      Serial.println();
       Serial.print("QTI1 = ");
      Serial.print(RCTime(QTI1));
      Serial.println();
      Serial.print("QTI2 = ");
      Serial.print(RCTime(QTI2));
      Serial.println();
      Serial.print("QTI3 = ");
      Serial.print(RCTime(QTI3));
      delay(100);

         unsigned long ultrasoundValue;
    for (int i = 0; i < 2; i++) {
      ultrasoundValue = ping(i);
      Serial.println();
      Serial.print(pingString[i]);
      Serial.print(ultrasoundValue);
      Serial.print("in, ");
      delay(25);

}
}

  long RCTime(int sensorIn) {
   long duration = 0;
    pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
    digitalWrite(sensorIn, HIGH); // Pin HIGH
    delay(1); // Waits for 1 millisecond
    pinMode(sensorIn, INPUT); // Sets pin as INPUT
    digitalWrite(sensorIn, LOW); // Pin LOW

    while (digitalRead(sensorIn)) { // Waits for the pin to go LOW
      duration++;
    }
    return duration; // Returns the duration of the pulse
    

if (RCTime(QTI2) < 100) {

servo1.write(120);
servo2.write(120); // fast
delay(1000); //for 1/10 second

 }
  }

What do you expect to happen after "return duration;" ?

I am hoping that after "return duration" the arduino will evaluate the value of QTI2 and act accordingly (Make the motors run).

Don't hope, it's hopeless.

The function returns at that point. That's what "return" means.

I do not understand where to properly incorporate my logic "if" statements to make my robot function with the data it is reading. Here is my code with no motor control logic functions.

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right  Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1 5
#define QTI2 6
#define QTI3 7


void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  servo1.attach(motor1Pin, 1000, 2000);
  servo2.attach(motor2Pin, 1000, 2000);
  Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
  unsigned long echo;

  pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
  pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
  echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
  return (echo / 58.138) * .39; //convert to CM then to inches



}
void loop()

{

      Serial.println();
       Serial.print("QTI1 = ");
      Serial.print(RCTime(QTI1));
      Serial.println();
      Serial.print("QTI2 = ");
      Serial.print(RCTime(QTI2));
      Serial.println();
      Serial.print("QTI3 = ");
      Serial.print(RCTime(QTI3));
      delay(100);

         unsigned long ultrasoundValue;
    for (int i = 0; i < 2; i++) {
      ultrasoundValue = ping(i);
      Serial.println();
      Serial.print(pingString[i]);
      Serial.print(ultrasoundValue);
      Serial.print("in, ");
      delay(25);

}
}

  long RCTime(int sensorIn) {
   long duration = 0;
    pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
    digitalWrite(sensorIn, HIGH); // Pin HIGH
    delay(1); // Waits for 1 millisecond
    pinMode(sensorIn, INPUT); // Sets pin as INPUT
    digitalWrite(sensorIn, LOW); // Pin LOW

    while (digitalRead(sensorIn)) { // Waits for the pin to go LOW
      duration++;
    }
      
return duration; // Returns the duration of the pulse
 }

How can I incorporate "if" statements to make my motors turn without interrupting the data flow to my robot? With this current code my serial monitor prints:

QTI1 = 154
QTI2 = 123
QTI3 = 213
Front Left 2in,
Front Right 10in,
QTI1 = 152
QTI2 = 123
QTI3 = 213
Front Left 2in,
Front Right 10in,
(repeats)

The Front left/front right displays my ping sensor distances.

Serial.print(RCTime(QTI1)) Don't do that; assign the return value to a variable, and test the variable.

I am unaware of how to do that. My attempts have resulted in nothing but errors. My attempted code change is posted below:

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right  Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1
#define QTI2
#define QTI3

int QTI1 = 5;
int QTI2 = 6;
int QTI = 7;

void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  servo1.attach(motor1Pin, 1000, 2000);
  servo2.attach(motor2Pin, 1000, 2000);
  Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
  unsigned long echo;

  pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
  pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
  echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
  return (echo / 58.138) * .39; //convert to CM then to inches



}
void loop()

{

      Serial.println();
       Serial.print("QTI1 = ");
      Serial.print(QTI1);
      Serial.println();
      Serial.print("QTI2 = ");
      Serial.print(QTI2);
      Serial.println();
      Serial.print("QTI3 = ");
      Serial.print(QTI3);
      delay(100);

         unsigned long ultrasoundValue;
    for (int i = 0; i < 2; i++) {
      ultrasoundValue = ping(i);
      Serial.println();
      Serial.print(pingString[i]);
      Serial.print(ultrasoundValue);
      Serial.print("in, ");
      delay(25);

}
}

  long RCTime(int sensorIn) {
   long duration = 0;
    pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
    digitalWrite(sensorIn, HIGH); // Pin HIGH
    delay(1); // Waits for 1 millisecond
    pinMode(sensorIn, INPUT); // Sets pin as INPUT
    digitalWrite(sensorIn, LOW); // Pin LOW

    while (digitalRead(sensorIn)) { // Waits for the pin to go LOW
      duration++;
    }
      
return duration; // Returns the duration of the pulse
 }

My attempts have resulted in nothing but errors.

And we have to guess what they were?

No thanks.

#define QTI1
#define QTI2
#define QTI3

Why did you change that?

C:\Users\Jack\Documents\Arduino\Maze_Runner_Code_V4\Maze_Runner_Code_V4.ino:11:52: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction

^

C:\Users\Jack\Documents\Arduino\Maze_Runner_Code_V4\Maze_Runner_Code_V4.ino:11:52: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]

Maze_Runner_Code_V4:16:10: error: expected unqualified-id before '=' token

int QTI1 = 5;

^

Maze_Runner_Code_V4:17:10: error: expected unqualified-id before '=' token

int QTI2 = 6;

^

C:\Users\Jack\Documents\Arduino\Maze_Runner_Code_V4\Maze_Runner_Code_V4.ino: In function 'void loop()':

Maze_Runner_Code_V4:54:24: error: no matching function for call to 'HardwareSerial::print()'

Serial.print(QTI1);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232,

from sketch\Maze_Runner_Code_V4.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: candidate: size_t Print::print(const __FlashStringHelper*)

size_t print(const __FlashStringHelper *);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: candidate: size_t Print::print(const String&)

size_t print(const String &);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:67:12: note: candidate: size_t Print::print(const char*)

size_t print(const char[]);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:67:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:68:12: note: candidate: size_t Print::print(char)

size_t print(char);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:68:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:69:12: note: candidate: size_t Print::print(unsigned char, int)

size_t print(unsigned char, int = DEC);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:69:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:70:12: note: candidate: size_t Print::print(int, int)

size_t print(int, int = DEC);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:70:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:71:12: note: candidate: size_t Print::print(unsigned int, int)

size_t print(unsigned int, int = DEC);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:71:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:72:12: note: candidate: size_t Print::print(long int, int)

size_t print(long, int = DEC);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:72:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:73:12: note: candidate: size_t Print::print(long unsigned int, int)

size_t print(unsigned long, int = DEC);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:73:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:74:12: note: candidate: size_t Print::print(double, int)

size_t print(double, int = 2);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:74:12: note: candidate expects 2 arguments, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:75:12: note: candidate: size_t Print::print(const Printable&)

size_t print(const Printable&);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:75:12: note: candidate expects 1 argument, 0 provided

Maze_Runner_Code_V4:57:24: error: no matching function for call to 'HardwareSerial::print()'

Serial.print(QTI2);

^

In file included from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Stream.h:26:0,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial.h:29,

from C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Arduino.h:232,

from sketch\Maze_Runner_Code_V4.ino.cpp:1:

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: candidate: size_t Print::print(const __FlashStringHelper*)

size_t print(const __FlashStringHelper *);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:65:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: candidate: size_t Print::print(const String&)

size_t print(const String &);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:66:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:67:12: note: candidate: size_t Print::print(const char*)

size_t print(const char[]);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:67:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:68:12: note: candidate: size_t Print::print(char)

size_t print(char);

^~~~~

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:68:12: note: candidate expects 1 argument, 0 provided

C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino/Print.h:69:12: note: candidate: size_t Print::print(unsigned char, int)

size_t print(unsigned char, int = DEC);

^~~~~

Here, from your original code, you assign the return value of a function to a variable.ultrasoundValue = ping(i);

like this?

unsigned long QTI1;
for (int a = 0;)
QTI1 = QTI1(a);

unsigned long QTI2;
for (int b = 0;)
QTI2 = QTI2(b);

unsigned long QTI3;
for (int c = 0;)
QTI3 = QTI3(c);

Also, I greatly appreciate your patience with me, this is probably more frustrating for you than for I.

I don't know what that last post was meant to do. You can't invent syntax.

Go back to your original code.

Take out the code after the "return duration"

Figure it out from there.

okay, so this is my code, but you're saying I need to assign my return values to variables.

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right  Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1 5
#define QTI2 6
#define QTI3 7


void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  servo1.attach(motor1Pin, 1000, 2000);
  servo2.attach(motor2Pin, 1000, 2000);
  Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
  unsigned long echo;

  pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
  pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
  echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
  return (echo / 58.138) * .39; //convert to CM then to inches



}
void loop()

{
      Serial.println();
      Serial.print("QTI1 = ");
      Serial.print(RCTime(QTI1));
      Serial.println();
      Serial.print("QTI2 = ");
      Serial.print(RCTime(QTI2));
      Serial.println();
      Serial.print("QTI3 = ");
      Serial.print(RCTime(QTI3));
      delay(100);

      
  if (QTI1 < 10){
servo1.write(130);
servo2.write(130); // fast
delay(1000); //wait 1 second
    


}

         unsigned long ultrasoundValue;
    for (int i = 0; i < 2; i++) {
      ultrasoundValue = ping(i);
      Serial.println();
      Serial.print(pingString[i]);
      Serial.print(ultrasoundValue);
      Serial.print("in, ");
      delay(25);
}
}

  long RCTime(int sensorIn) {
   long duration = 0;
    pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
    digitalWrite(sensorIn, HIGH); // Pin HIGH
    delay(1); // Waits for 1 millisecond
    pinMode(sensorIn, INPUT); // Sets pin as INPUT
    digitalWrite(sensorIn, LOW); // Pin LOW

    while (digitalRead(sensorIn)) { // Waits for the pin to go LOW
      duration++;
    }

    return duration; // Returns the duration of the pulse
    
    

}

I am unaware of how to assign return values to variables, and though I tried, apparently I am "making up syntax" :frowning: what would you input to assign these QTIs to return variables?

Serial.print(RCTime(QTI1)); Here, you are printing the return value of the function "RCTime".
Don't print the return value, assign it to a variable.

I think I've both
a) mentioned this
b) shown you how.

Hello everyone.

I am attempting to make a robot that follows a line using QTIs and navigates a maze using Ping sensors. Here is my code:

#include <Servo.h>

//First, set up the servos
Servo servo1;
Servo servo2;

int motor1Pin = 11; // the first motor's port number
int motor2Pin = 10; // the second motor's port number

int ultraSoundSignalPins[] = {2, 3}; // Front Left,Front Right  Ultrasound signal pins
char *pingString[] = {"Front Left ", "Front Right "}; // just something to print to indicate direction
#define QTI1 5
#define QTI2 6
#define QTI3 7


void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  servo1.attach(motor1Pin, 1000, 2000);
  servo2.attach(motor2Pin, 1000, 2000);
  Serial.begin(9600);
}

//Ping function
unsigned long ping(int index)
{
  unsigned long echo;

  pinMode(ultraSoundSignalPins[index], OUTPUT); // Switch signalpin to output
  digitalWrite(ultraSoundSignalPins[index], LOW); // Send low pulse
  delayMicroseconds(2); // Wait for 2 microseconds
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Send high pulse
  delayMicroseconds(5); // Wait for 5 microseconds
  digitalWrite(ultraSoundSignalPins[index], LOW); // Holdoff
  pinMode(ultraSoundSignalPins[index], INPUT); // Switch signalpin to input
  digitalWrite(ultraSoundSignalPins[index], HIGH); // Turn on pullup resistor
  echo = pulseIn(ultraSoundSignalPins[index], HIGH); //Listen for echo
  return (echo / 58.138) * .39; //convert to CM then to inches



}
void loop()

{
      Serial.println();
      Serial.print("QTI1 = ");
      Serial.print(RCTime(QTI1));
      Serial.println();
      Serial.print("QTI2 = ");
      Serial.print(RCTime(QTI2));
      Serial.println();
      Serial.print("QTI3 = ");
      Serial.print(RCTime(QTI3));
      delay(100);

      
         unsigned long ultrasoundValue;
    for (int i = 0; i < 2; i++) {
      ultrasoundValue = ping(i);
      Serial.println();
      Serial.print(pingString[i]);
      Serial.print(ultrasoundValue);
      Serial.print("in, ");
      delay(25);
}
}

  long RCTime(int sensorIn) {
   long duration = 0;
    pinMode(sensorIn, OUTPUT); // Sets pin as OUTPUT
    digitalWrite(sensorIn, HIGH); // Pin HIGH
    delay(1); // Waits for 1 millisecond
    pinMode(sensorIn, INPUT); // Sets pin as INPUT
    digitalWrite(sensorIn, LOW); // Pin LOW

    while (digitalRead(sensorIn)) { // Waits for the pin to go LOW
      duration++;
    }

    return duration; // Returns the duration of the pulse
    
    

}

I was told by another user not to use this:

 Serial.print(RCTime(QTI1));

but to instead assign my return values to a variable.

can anyone help me do this?

when I try assigning it to a variable like this:

unsigned long RCTime;
for (int a = 0; a < 1; a++);
     RCTime = QTI1(a);

I get the error message:

Maze_Runner_Code_BackupV3:61:21: error: expression cannot be used as a function

RCTime = QTI1(a);

^

Multiple libraries were found for "Servo.h"
Used: C:\Program
exit status 1
'a' was not declared in this scope