Ultrasonic Robot, ISO C++ forbids comparison between pointer and integer

Hi Guys,
For this project I’m using an Arduino UNO, a SG-50 servo and a HC-SR04 ultrasonic sensor.
My programming skills are pretty average but …
I’m trying to make an ultrasonic robot and for the moment I’m just trying to make a base code to test each individual building block in the robot. In this case I’m testing whether I can get a reading from an ultrasonic sensor and if it’s below a certain point a servo turns checking both directions and whichever of those directions has a bigger distance the motors (or in this case led’s) turn in that direction and continue on.
Here is my code:

#include <Servo.h>

Servo myServo;

int duration, distance;

#define trigPin 13
#define echoPin 12
#define ledG1 5
#define ledR1 6

void distanceCm() {
  digitalWrite (trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);
  
  pinMode (echoPin, INPUT);
  duration = pulseIn (echoPin, HIGH);
  distance = duration/2/29;
}

void center() {
  myServo.write (90);
}

void scanCenter() {
  myServo.write (90);
  delay (100);
  distanceCm();
  delay (200);
}

void scanLeft() {
  myServo.write (0);
  delay (100);
  distanceCm();
  delay (200);
}

void scanRight() {
  myServo.write (180);
  delay (100);
  distanceCm();
  delay (200);
}

void setup() {
  pinMode (trigPin, OUTPUT);
  myServo.attach(2);
}

void loop() {
  if (scanCenter < 15) { // I'm getting the error on this line
    scanLeft();
    delay (1000);
    scanRight();
    delay (500);
    center();
  }
     if (scanLeft() > scanRight()) {
       digitalWrite (ledG1, HIGH);
       digitalWrite (ledR1, LOW);
     }
     if (scanRight() > scanLeft()) {
       digitalWrite (ledG1, LOW);
       digitalWrite (ledR1, HIGH);
     }
     else {
       digitalWrite (ledG1, HIGH);
       digitalWrite (ledR1, HIGH);
     }
}

I’m getting the error ISO C++ forbids comparison between pointer and integer and I’ve tried changing a few things but I can’t get what I want. Could someone please tell me what to change to make it work like this and why it doesn’t work how it is?

Thanks heaps,
nathman11

You need to call the function scanCentre, like you call scanLeft and scanRight

'scanCenter' is a function that takes no argument so to call it you should write 'scanCenter()'.

Of course scanCenter() returns 'void' (nothing) so you can't compare the return value against anything. It looks like you intended to return a distance (in cm) from your function. But you don't return a value from distanceCm() either. You could use the global variable 'distance' but that will make some of your other comparisons not work.

Start by returning a distance from 'distanceCm()':

int distanceCm() {
  unsigned long duration; // No need for this to be global
  digitalWrite (trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite (trigPin, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin, LOW);

  pinMode (echoPin, INPUT);
  duration = pulseIn (echoPin, HIGH);
  return duration/2/29;
}

Then each of your scan functions can return the distance:

int scanCenter() {
  myServo.write (90);
  delay (100);
  return distanceCm();
}

int scanLeft() {
  myServo.write (0);
  delay (100);
  return distanceCm();
}

int scanRight() {
  myServo.write (180);
  delay (100);
  return distanceCm();
}

Then your sketch will compile. Then you can see if it does what you want.