no 'operator>' in' 'firstping > 10'

int green = 4;
int red = 5;

#include <NewPing.h>

#define TRIGGER_PIN  12
#define ECHO_PIN     11
#define MAX_DISTANCE 200

NewPing firstping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos1ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos2ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos3ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos4ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);


const int pwmA = 3;
const int pwmB = 11;
const int brakeA = 9;
const int brakeB = 8;
const int dirA = 12;
const int dirB = 13;

void setup()
{
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);

  pinMode(dirA, OUTPUT); //Initiates Motor Channel A pin
  pinMode(brakeA, OUTPUT); //Initiates Brake Channel A pin

  //Setup Channel B
  pinMode(dirB, OUTPUT); //Initiates Motor Channel A pin
  pinMode(brakeB, OUTPUT); //Initiates Brake Channel A pin


}

void loop()
{
  digitalWrite(green,HIGH);

  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.

  unsigned int uS = firstping.ping(); // Send ping, get ping time in microseconds (uS).
  Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance in cm and print result (0 = outside set distance range)



  digitalWrite(dirA, HIGH); //Establishes forward direction of Channel A
  digitalWrite(dirB, HIGH); //Establishes forward direction of Channel B
  
  

  if (firstping > 10)
  {
    digitalWrite(green, LOW);
    digitalWrite(red, HIGH);


    digitalWrite(brakeA, HIGH); //Engage the Brake for Channel A and B.
    digitalWrite(brakeB, HIGH);

  }


}

I am making a robot that will explore a room. For some reason on the if statement, it gives me an error: no ‘operator>’ in’ ‘firstping > 10’

What am I doing wrong?

Should be:

if (firstping.ping > 10)

or

if (uS > 10)

Thank you so much!

It seems the first one didn't work but the second one did!

SamKirkiles:
It seems the first one didn’t work but the second one did!

The first one should have been a function call:

if (firstping.ping() > 10)
NewPing firstping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos1ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos2ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos3ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
NewPing pos4ping(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

Do you really have 5 ping sensors tied to the same 2 pins? How do you expect to get different values from the 5 of them?

I dont. I have 1 sensor hooked up to two pins and I am comparing the distances.

I don’t think you need one instance for each distance measurement.

I don't think you need one instance for each distance measurement.

Exactly. You need one instance of the class per sensor, not one per use of the sensor.