user23548: The idea is to play the tone that is given by the center value read it by the center ultrasound sensor.
The code that is in Arduino is this one:
#include NewPing.h

#define PING_CENTER  2  // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor.
#define PING_RIGHT  3
#define PING_LEFT  4
#define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define buzzerPin = 10


long buzzerFreq1; // The frequency to buzz the buzzer
unsigned int BUZZ_FREQ_MAX = 2500; // Maximum frequency for the buzzer
unsigned int US_MAX = 2023; // Maximum value for ultrason sensor
int c1;

NewPing sonar2(PING_CENTER, PING_CENTER, PING_MAX_DISTANCE); // NewPing setup of pin and maximum distance.
NewPing sonar3(PING_RIGHT, PING_RIGHT, PING_MAX_DISTANCE);
NewPing sonar4(PING_LEFT, PING_LEFT, PING_MAX_DISTANCE);

void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT); // set pin for buzzer output 
}

void loop() { 
  buzzerFreq1 = (center * BUZZ_FREQ_MAX) / US_MAX;
  buzz(buzzerPin,buzzerFreq1,10);
  // tone(buzzerPin, center);
  delay(500);  // Wait 500ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int center = sonar2.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS) and convert it to centimeters (cm)
  unsigned int right = sonar3.ping() / US_ROUNDTRIP_CM;
  unsigned int left = sonar4.ping() / US_ROUNDTRIP_CM;
  // Serial.println("Distance: " + String(distanceInCms) + "cm");

  Serial.println(center);
  Serial.println(right);
  Serial.println(left);

}

 // buzz(buzzerPin, buzzerFreq1, 10);
 void buzz(int targetPin, long frequency, long length) {
 // int c1 = center;
  buzzerFreq1 = (center * BUZZ_FREQ_MAX) / US_MAX;
  long delayValue = 1000000/frequency/2;

  int numCycles = frequency * length/1000;

  for (int i=0; i < numCycles; i++){
    digitalWrite(targetPin,HIGH);
    delayMicroseconds(delayValue);
    digitalWrite(targetPin,LOW);
    delayMicroseconds(delayValue);
  }
} 

And I receive the following error that I have no idea how to solve it.
ultrason_onewire_sound.cpp: In function ‘void setup()’:
ultrason_onewire_sound.cpp:26:11: error: expected primary-expression before ‘=’ token
ultrason_onewire_sound.cpp: In function ‘void loop()’:
ultrason_onewire_sound.cpp:38:8: error: expected primary-expression before ‘=’ token
ultrason_onewire_sound.cpp: In function ‘void buzz(int, long int, long int)’:
ultrason_onewire_sound.cpp:48:18: error: ‘center’ was not declared in this scope


user2881: #define buzzerPin = 10 shouldn't have an = in it.
With the = pinMode(buzzerPin, OUTPUT); will turn into pinMode(= 10, OUTPUT); by the pre-processor. Which would give the error, complaining about an = token, you got.

23548: <p>The idea is to play the tone that is given by the center value read it by the center ultrasound sensor.</p>

<p>The code that is in Arduino is this one:</p>

<pre class="lang-cpp prettyprint-override"><code>#include NewPing.h

#define PING_CENTER  2  // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor.
#define PING_RIGHT  3
#define PING_LEFT  4
#define PING_MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.
#define buzzerPin = 10


long buzzerFreq1; // The frequency to buzz the buzzer
unsigned int BUZZ_FREQ_MAX = 2500; // Maximum frequency for the buzzer
unsigned int US_MAX = 2023; // Maximum value for ultrason sensor
int c1;

NewPing sonar2(PING_CENTER, PING_CENTER, PING_MAX_DISTANCE); // NewPing setup of pin and maximum distance.
NewPing sonar3(PING_RIGHT, PING_RIGHT, PING_MAX_DISTANCE);
NewPing sonar4(PING_LEFT, PING_LEFT, PING_MAX_DISTANCE);

void setup() {
  Serial.begin(9600);
  pinMode(buzzerPin, OUTPUT); // set pin for buzzer output 
}

void loop() { 
  buzzerFreq1 = (center * BUZZ_FREQ_MAX) / US_MAX;
  buzz(buzzerPin,buzzerFreq1,10);
  // tone(buzzerPin, center);
  delay(500);  // Wait 500ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  unsigned int center = sonar2.ping() / US_ROUNDTRIP_CM; // Send ping, get ping time in microseconds (uS) and convert it to centimeters (cm)
  unsigned int right = sonar3.ping() / US_ROUNDTRIP_CM;
  unsigned int left = sonar4.ping() / US_ROUNDTRIP_CM;
  // Serial.println("Distance: " + String(distanceInCms) + "cm");

  Serial.println(center);
  Serial.println(right);
  Serial.println(left);

}

 // buzz(buzzerPin, buzzerFreq1, 10);
 void buzz(int targetPin, long frequency, long length) {
 // int c1 = center;
  buzzerFreq1 = (center * BUZZ_FREQ_MAX) / US_MAX;
  long delayValue = 1000000/frequency/2;

  int numCycles = frequency * length/1000;

  for (int i=0; i &lt; numCycles; i++){
    digitalWrite(targetPin,HIGH);
    delayMicroseconds(delayValue);
    digitalWrite(targetPin,LOW);
    delayMicroseconds(delayValue);
  }
} 
</code></pre>

<p>And I receive the following error that I have no idea how to solve it.</p>

<pre><code>ultrason_onewire_sound.cpp: In function ‘void setup()’:
ultrason_onewire_sound.cpp:26:11: error: expected primary-expression before ‘=’ token
ultrason_onewire_sound.cpp: In function ‘void loop()’:
ultrason_onewire_sound.cpp:38:8: error: expected primary-expression before ‘=’ token
ultrason_onewire_sound.cpp: In function ‘void buzz(int, long int, long int)’:
ultrason_onewire_sound.cpp:48:18: error: ‘center’ was not declared in this scope
</code></pre>
 2881: <p><code>#define buzzerPin = 10</code> shouldn't have an <code>=</code> in it.</p>

<p>With the <code>=</code> <code>pinMode(buzzerPin, OUTPUT);</code> will turn into <code>pinMode(= 10, OUTPUT);</code> by the pre-processor. Which would give the error, complaining about an <code>=</code> token, you got.</p>
