'SonarSensor' was not declared in this scope

Hey guys,

My program for multiple Sonar sensors, is giving the next fault:
'SonarSensor' was not declared in this scope
Does anyone know, what's wrong in the code..?

 // 
#define trigPin1 2
#define echoPin1 3
#define trigPin2 4
#define echoPin2 5
#define trigPin3 7
#define echoPin3 8
int ledPin = 13;
int WaardeVoor;
int WaardeLinks;
int WaardeRechts;
int SonarSensor;

long duration, distance, RightSensor, FrontSensor, LeftSensor;

void setup()
{

  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
  pinMode(trigPin2, OUTPUT);
  pinMode(echoPin2, INPUT);
  pinMode(trigPin3, OUTPUT);
  pinMode(echoPin3, INPUT);
}

void loop() {

  SonarSensor(trigPin1, echoPin1);
  RightSensor = distance;
  WaardeRechts = RightSensor;
  SonarSensor(trigPin2, echoPin2);
  LeftSensor = distance;
  WaardeLinks = LeftSensor;
  SonarSensor(trigPin3, echoPin3);
  FrontSensor = distance;
  WaardeVoor = FrontSensor;

  if (WaardeVoor > 4)
  {
    // getal 0 sturen
  }
  else
  {
    if (WaardeRechts > 4)// deze waarde nog bepalen
    {
      // getal 3 sturen
    }
    else
    {
      if (WaardeLinks > 4)// deze waarde nog bepalen
      {
        // getal 4 sturen
      }
      else
      {
        // getal 6 sturen
      }
      else
      {
        // volgende afweging maken
      }
      Serial.print(LeftSensor);
      Serial.print(" - ");
      Serial.print(FrontSensor);
      Serial.print(" - ");
      Serial.println(RightSensor);
    }

    void SonarSensor(int trigPin, int echoPin)
    {
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      duration = pulseIn(echoPin, HIGH);
      distance = (duration / 2) / 29.1;

      delay(5);

    }
  }

.

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)

→ when properly indented, you’ll see that there is a pb with closing brackets (the one for loop()) (and a if (WaardeLinks <= 4) else statement and will also likely help you get rid of possible stray chars

Hey,

Thanks for your reply..!
Do you mean, like it is right nouw, above..?
I still can't get rid of the error: 'SonarSensor cannot be used as a function."

Do you mean, like it is right nouw, above..?

As for the posting of the code, yes.

Except, that you need to be consistent in placing curly braces.

void setup()
{

void loop() {

That is not consistent. The first style is better, IMHO.

int SonarSensor;

  SonarSensor(trigPin1, echoPin1);

    void SonarSensor(int trigPin, int echoPin)
    {

You can not have a variable and a function with the same name.

You can NOT define a function (SonarSensor()) inside another function (loop()).

Except, that you need to be consistent in placing curly braces.

void setup()
{

void loop() {

That is not consistent. The first style is better, IMHO.

thanks, i'll try to be consistent next time
The program is working again, without the if statements, wich aren't fully defined
Thanks..!