user70077: I am currently working on an alarm system using multiple sensors and one arduino board and I am getting readings from 2 of the sensors but one gives a constant zero and a constant buzzer sound even without sensing the distance...I have followed the schematics of the original project but nothing works. Here is the code

int ledred1 = 2;
int ledgreen1 = 3;
int ledorange1 = 4;
int ledred2 = 5;
int ledgreen2 = 6;
int ledorange2 = 7;
int ledred3 = 8;
int ledgreen3 = 9;
int ledorange3 = 10;

int sound = 250;

int trigPin1 = 11;
int echoPin1 = 12;

int trigPin2 = 13;
int echoPin2 = 30;

int trigPin3 = 31;
int echoPin3 = 32;

#define buzzer1 33
#define buzzer2 34
#define buzzer3 35


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

 
  pinMode(ledred1, OUTPUT);
  pinMode(ledred2, OUTPUT);
  pinMode(ledorange1, OUTPUT);
  pinMode(ledgreen1, OUTPUT);
  pinMode(ledgreen2, OUTPUT);
  pinMode(ledred3, OUTPUT);
  pinMode(ledgreen3, OUTPUT);
  pinMode(ledorange2, OUTPUT);
  pinMode(ledorange3, OUTPUT);

  
}
void firstsensor(){ // This function is for first sensor. 
  int duration1, distance1;
  digitalWrite (trigPin1, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin1, LOW);
  duration1 = pulseIn (echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

      Serial.print("1st Sensor: ");
      Serial.print(distance1); 
      Serial.print("cm    ");

  if (distance1 <=200 && distance1>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,HIGH);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance1 <100&& distance1>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,HIGH);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance1 <50&& distance1>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, HIGH);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance1>200 || distance1<0){
    Serial.println("Out of Range");
    noTone(buzzer1);
  }
  else{
    Serial.print(distance1);
    Serial.println("cm");
    tone(buzzer1,sound);

  }  
}
void secondsensor(){ // This function is for second sensor.
    int duration2, distance2;
    digitalWrite (trigPin2, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin2, LOW);
    duration2 = pulseIn (echoPin2, HIGH);
    distance2 = (duration2/2) / 29.1;
 
      Serial.print("2nd Sensor: ");
      Serial.print(distance2); 
      Serial.print("cm    ");
  
     if (distance2 <=200&& distance2>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, HIGH);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance2 <100&& distance2>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,HIGH);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance2 <50&& distance2>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, HIGH);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance2>200 || distance2<0){
    Serial.println("Out of Range");
    noTone(buzzer2);
  }
  else{
    Serial.print(distance2);
    Serial.println("cm");
    tone(buzzer2,sound);

  }  
}
void thirdsensor(){ // This function is for third sensor.
    int duration3, distance3;
    digitalWrite (trigPin3, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin3, LOW);
    duration3 = pulseIn (echoPin3, HIGH);
    distance3 = (duration3/2) / 29.1;

      Serial.print("3rd Sensor: ");  
      Serial.print(distance3); 
      Serial.print("cm");
  
     if (distance3 <=200&& distance3>=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, HIGH);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance3 <100&& distance3>=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,HIGH);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance3 <50&& distance3>=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance3>200 || distance3<0){
    Serial.println("Out of Range");
    noTone(buzzer3);
  }
  else{
    Serial.print(distance3);
    Serial.println("cm");
    tone(buzzer3,sound);

  }  
}

void loop() {
Serial.println("\n");
firstsensor();
delay(100);
secondsensor();
delay(100);
thirdsensor();
delay(100);
}

This is what I get in the serial monitor
This is the snapshot of the pin configuration

user31105: This is NOT an answer to the question, but I did some (major) refactoring which make it much more clear what is happening.
I think you made some mistake within the (refactored) method Sensor::UpdateState.
File <.ino>:
#include "Sensors.h"

Sensors _sensors;

void setup() {
  Serial.begin (9600);
  _sensors.Init();  
}


void loop()
{
  _sensors.Process();
}

File Sensors.h:
#ifndef SENSORS_H
#define SENSORS_H

#include "Arduino.h"
#include "Sensor.h"

class Sensors
{
  public:
    Sensors();

    void Init();
    void Process();

  private:
    static const int NR_OF_SENSORS = 3;

    Sensor _sensors[NR_OF_SENSORS];
};

#endif // SENSORS_H

File Sensors.cpp:
#include "Sensors.h"

Sensors::Sensors()
:
  //              index trigPin echoPin redLed orangeLed greenLed buzzer)
  _sensors( { Sensor(1 ,  11   ,  12   ,  2       3     ,   4    ,  33),
              Sensor(2 ,  13   ,  30   ,  5       6     ,   7    ,  34),
              Sensor(3 ,  31   ,  32   ,  8       9     ,   10   ,  35) })
{
}

void Sensors::Init()
{
  for (uint8_t index = 0; index < NR_OF_SENSORS; index++)
  {
    _sensors[index].Init();
  }
}


void Sensors::Process()
{
  for (uint8_t index = 0; index < NR_OF_SENSORS; index++)
  {
    _sensors[index].Process();
  }
}

File Sensor.h:
#ifndef SENSOR_H
#define SENSOR_H

#include "Arduino.h"

class Sensor
{
  public:
    enum EState 
    {
      LOW_OUT_OF_RANGE, 
      WAY_TOO_CLOSE,
      TOO_CLOSE, 
      OK, 
      HIGH_OUT_OF_RANGE
    };
    
    Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer);

    uint8_t Index    (void) { return _index;     };
    uint8_t TrigPin  (void) { return _trigPin;   };
    uint8_t EchoPin  (void) { return _echoPin;   };
    uint8_t RedLed   (void) { return _redLed;    };
    uint8_t OrangeLed(void) { return _orangeLed; };
    uint8_t GreenLed (void) { return _greenLed;  };
    uint8_t Buzzer   (void) { return _buzzer;    };
     
    void Init();
    void Process();

  private:
    uint8_t _index;
    uint8_t _trigPin;
    uint8_t _echoPin;
    uint8_t _redLed;
    uint8_t _orangeLed;
    uint8_t _greenLed;
    uint8_t _buzzer;
    EState _state;
    uint8_t _distance;
    
    void Measure();
    void UpdateState();
    void ProcessState();
    void Show(uint16_t sound, uint8_t led);
    void PrintDistance(void);
};

#endif // SENSOR_H

File Sensor.cpp:
#include "Sensor.h"

Sensor::Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer)
:
  _index(index),
  _trigPin(trigPin),
  _echoPin(echoPin),
  _redLed(redLed),
  _orangeLed(orangeLed),
  _greenLed(greenLed),
  _buzzer(buzzer),
  _state(OK),
  _distance(0)
{
}


void Sensor::Init()
{
  pinMode(TrigPin()  , OUTPUT);
  pinMode(EchoPin()  , INPUT);
  pinMode(RedLed()   , OUTPUT);
  pinMode(OrangeLed(), OUTPUT);
  pinMode(GreenLed() , OUTPUT);
}


void Sensor::Process()
{
  Measure();
  UpdateState();
  ProcessState();
  PrintDistance();
  delay(100);
}


void Sensor::Measure()
{
  digitalWrite(TrigPin(), HIGH);
  delayMicroseconds (10);
  digitalWrite(TrigPin(), LOW);
  uint16_t duration = pulseIn (EchoPin(), HIGH);
  _distance = (duration / 2) / 29.1;
}


void Sensor::UpdateState()
{
  if (_distance < 0)
  {
    _state = LOW_OUT_OF_RANGE;
  }
  else if (_distance <= 50)
  {
    _state = WAY_TOO_CLOSE;
  }
  else if (_distance <= 100)
  {
    _state = TOO_CLOSE;
  }
  else if (_distance <= 200)
  {
    _state = OK;
  }
  else 
  {
    _state = HIGH_OUT_OF_RANGE;
  }
}


void Sensor::ProcessState()
{
  digitalWrite(RedLed(), LOW);
  digitalWrite(OrangeLed(), LOW);
  digitalWrite(GreenLed(), LOW);
  
  switch (_state)
  {
  case LOW_OUT_OF_RANGE:
    noTone(Buzzer());  
    break;
    
  case WAY_TOO_CLOSE:
    Show(300, RedLed());
    break;
    
  case TOO_CLOSE:
    Show(275, OrangeLed());
    break;
    
  case OK:
    Show(250, GreenLed());
    break;
  
  case HIGH_OUT_OF_RANGE:
    noTone(Buzzer());    break;
    break;
  
  default:
    // Error
    break;
  }
}


void Sensor::Show(uint16_t sound, uint8_t led)
{
  tone(Buzzer(), sound);
  digitalWrite(led, HIGH);
}


void Sensor::PrintDistance()
{
  Serial.print("Sensor ");
  Serial.print(Index());
  Serial.print(": ");
  Serial.print(_distance); 
  Serial.print("cm    ");
  
  if ((_state == LOW_OUT_OF_RANGE) || (_state == HIGH_OUT_OF_RANGE))
  {
    Serial.print(" (Out of range)");
  }
  
  Serial.println("");
}


70077: <p>I am currently working on an alarm system using multiple sensors and one arduino board and I am getting readings from 2 of the sensors but one gives a constant zero and a constant buzzer sound even without sensing the distance...I have followed the schematics of the original project but nothing works. Here is the code</p>
<pre><code>
int ledred1 = 2;
int ledgreen1 = 3;
int ledorange1 = 4;
int ledred2 = 5;
int ledgreen2 = 6;
int ledorange2 = 7;
int ledred3 = 8;
int ledgreen3 = 9;
int ledorange3 = 10;

int sound = 250;

int trigPin1 = 11;
int echoPin1 = 12;

int trigPin2 = 13;
int echoPin2 = 30;

int trigPin3 = 31;
int echoPin3 = 32;

#define buzzer1 33
#define buzzer2 34
#define buzzer3 35


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

 
  pinMode(ledred1, OUTPUT);
  pinMode(ledred2, OUTPUT);
  pinMode(ledorange1, OUTPUT);
  pinMode(ledgreen1, OUTPUT);
  pinMode(ledgreen2, OUTPUT);
  pinMode(ledred3, OUTPUT);
  pinMode(ledgreen3, OUTPUT);
  pinMode(ledorange2, OUTPUT);
  pinMode(ledorange3, OUTPUT);

  
}
void firstsensor(){ // This function is for first sensor. 
  int duration1, distance1;
  digitalWrite (trigPin1, HIGH);
  delayMicroseconds (10);
  digitalWrite (trigPin1, LOW);
  duration1 = pulseIn (echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

      Serial.print(&quot;1st Sensor: &quot;);
      Serial.print(distance1); 
      Serial.print(&quot;cm    &quot;);

  if (distance1 &lt;=200 &amp;&amp; distance1&gt;=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,HIGH);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance1 &lt;100&amp;&amp; distance1&gt;=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,HIGH);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance1 &lt;50&amp;&amp; distance1&gt;=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, HIGH);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance1&gt;200 || distance1&lt;0){
    Serial.println(&quot;Out of Range&quot;);
    noTone(buzzer1);
  }
  else{
    Serial.print(distance1);
    Serial.println(&quot;cm&quot;);
    tone(buzzer1,sound);

  }  
}
void secondsensor(){ // This function is for second sensor.
    int duration2, distance2;
    digitalWrite (trigPin2, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin2, LOW);
    duration2 = pulseIn (echoPin2, HIGH);
    distance2 = (duration2/2) / 29.1;
 
      Serial.print(&quot;2nd Sensor: &quot;);
      Serial.print(distance2); 
      Serial.print(&quot;cm    &quot;);
  
     if (distance2 &lt;=200&amp;&amp; distance2&gt;=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, HIGH);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance2 &lt;100&amp;&amp; distance2&gt;=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,HIGH);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance2 &lt;50&amp;&amp; distance2&gt;=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, HIGH);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance2&gt;200 || distance2&lt;0){
    Serial.println(&quot;Out of Range&quot;);
    noTone(buzzer2);
  }
  else{
    Serial.print(distance2);
    Serial.println(&quot;cm&quot;);
    tone(buzzer2,sound);

  }  
}
void thirdsensor(){ // This function is for third sensor.
    int duration3, distance3;
    digitalWrite (trigPin3, HIGH);
    delayMicroseconds (10);
    digitalWrite (trigPin3, LOW);
    duration3 = pulseIn (echoPin3, HIGH);
    distance3 = (duration3/2) / 29.1;

      Serial.print(&quot;3rd Sensor: &quot;);  
      Serial.print(distance3); 
      Serial.print(&quot;cm&quot;);
  
     if (distance3 &lt;=200&amp;&amp; distance3&gt;=100) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, HIGH);
    
    sound=250;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
     }   


  if (distance3 &lt;100&amp;&amp; distance3&gt;=50) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,HIGH);
    digitalWrite (ledgreen3, LOW);
    
    sound=275;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      }   
        if (distance3 &lt;50&amp;&amp; distance3&gt;=0) {  // Change the number for long or short distances.
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
    
    sound=300;

  } else {
    digitalWrite (ledred1, LOW);
    digitalWrite (ledgreen1,LOW);
    digitalWrite (ledorange1,LOW);
    digitalWrite (ledred2, LOW);
    digitalWrite (ledorange2,LOW);
    digitalWrite (ledgreen2, LOW);
    digitalWrite (ledred3, LOW);
    digitalWrite (ledorange3,LOW);
    digitalWrite (ledgreen3, LOW);
      } 
      if(distance3&gt;200 || distance3&lt;0){
    Serial.println(&quot;Out of Range&quot;);
    noTone(buzzer3);
  }
  else{
    Serial.print(distance3);
    Serial.println(&quot;cm&quot;);
    tone(buzzer3,sound);

  }  
}

void loop() {
Serial.println(&quot;\n&quot;);
firstsensor();
delay(100);
secondsensor();
delay(100);
thirdsensor();
delay(100);
}
</code></pre>
<p>This is what I get in the serial monitor<a href="https://i.stack.imgur.com/5HuaI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5HuaI.png" alt="enter image description here" /></a>
This is the snapshot of the pin configuration<a href="https://i.stack.imgur.com/FmVpz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FmVpz.png" alt="enter image description here" /></a></p>
 31105: <p>This is NOT an answer to the question, but I did some (major) refactoring which make it much more clear what is happening.</p>
<p>I think you made some mistake within the (refactored) method Sensor::UpdateState.</p>
<p>File &lt;.ino&gt;:</p>
<pre><code>#include &quot;Sensors.h&quot;

Sensors _sensors;

void setup() {
  Serial.begin (9600);
  _sensors.Init();  
}


void loop()
{
  _sensors.Process();
}
</code></pre>
<p>File Sensors.h:</p>
<pre><code>#ifndef SENSORS_H
#define SENSORS_H

#include &quot;Arduino.h&quot;
#include &quot;Sensor.h&quot;

class Sensors
{
  public:
    Sensors();

    void Init();
    void Process();

  private:
    static const int NR_OF_SENSORS = 3;

    Sensor _sensors[NR_OF_SENSORS];
};

#endif // SENSORS_H
</code></pre>
<p>File Sensors.cpp:</p>
<pre><code>#include &quot;Sensors.h&quot;

Sensors::Sensors()
:
  //              index trigPin echoPin redLed orangeLed greenLed buzzer)
  _sensors( { Sensor(1 ,  11   ,  12   ,  2       3     ,   4    ,  33),
              Sensor(2 ,  13   ,  30   ,  5       6     ,   7    ,  34),
              Sensor(3 ,  31   ,  32   ,  8       9     ,   10   ,  35) })
{
}

void Sensors::Init()
{
  for (uint8_t index = 0; index &lt; NR_OF_SENSORS; index++)
  {
    _sensors[index].Init();
  }
}


void Sensors::Process()
{
  for (uint8_t index = 0; index &lt; NR_OF_SENSORS; index++)
  {
    _sensors[index].Process();
  }
}
</code></pre>
<p>File Sensor.h:</p>
<pre><code>#ifndef SENSOR_H
#define SENSOR_H

#include &quot;Arduino.h&quot;

class Sensor
{
  public:
    enum EState 
    {
      LOW_OUT_OF_RANGE, 
      WAY_TOO_CLOSE,
      TOO_CLOSE, 
      OK, 
      HIGH_OUT_OF_RANGE
    };
    
    Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer);

    uint8_t Index    (void) { return _index;     };
    uint8_t TrigPin  (void) { return _trigPin;   };
    uint8_t EchoPin  (void) { return _echoPin;   };
    uint8_t RedLed   (void) { return _redLed;    };
    uint8_t OrangeLed(void) { return _orangeLed; };
    uint8_t GreenLed (void) { return _greenLed;  };
    uint8_t Buzzer   (void) { return _buzzer;    };
     
    void Init();
    void Process();

  private:
    uint8_t _index;
    uint8_t _trigPin;
    uint8_t _echoPin;
    uint8_t _redLed;
    uint8_t _orangeLed;
    uint8_t _greenLed;
    uint8_t _buzzer;
    EState _state;
    uint8_t _distance;
    
    void Measure();
    void UpdateState();
    void ProcessState();
    void Show(uint16_t sound, uint8_t led);
    void PrintDistance(void);
};

#endif // SENSOR_H
</code></pre>
<p>File Sensor.cpp:</p>
<pre><code>#include &quot;Sensor.h&quot;

Sensor::Sensor(uint8_t index, uint8_t trigPin, uint8_t echoPin, uint8_t redLed, uint8_t orangeLed, uint8_t greenLed, uint8_t buzzer)
:
  _index(index),
  _trigPin(trigPin),
  _echoPin(echoPin),
  _redLed(redLed),
  _orangeLed(orangeLed),
  _greenLed(greenLed),
  _buzzer(buzzer),
  _state(OK),
  _distance(0)
{
}


void Sensor::Init()
{
  pinMode(TrigPin()  , OUTPUT);
  pinMode(EchoPin()  , INPUT);
  pinMode(RedLed()   , OUTPUT);
  pinMode(OrangeLed(), OUTPUT);
  pinMode(GreenLed() , OUTPUT);
}


void Sensor::Process()
{
  Measure();
  UpdateState();
  ProcessState();
  PrintDistance();
  delay(100);
}


void Sensor::Measure()
{
  digitalWrite(TrigPin(), HIGH);
  delayMicroseconds (10);
  digitalWrite(TrigPin(), LOW);
  uint16_t duration = pulseIn (EchoPin(), HIGH);
  _distance = (duration / 2) / 29.1;
}


void Sensor::UpdateState()
{
  if (_distance &lt; 0)
  {
    _state = LOW_OUT_OF_RANGE;
  }
  else if (_distance &lt;= 50)
  {
    _state = WAY_TOO_CLOSE;
  }
  else if (_distance &lt;= 100)
  {
    _state = TOO_CLOSE;
  }
  else if (_distance &lt;= 200)
  {
    _state = OK;
  }
  else 
  {
    _state = HIGH_OUT_OF_RANGE;
  }
}


void Sensor::ProcessState()
{
  digitalWrite(RedLed(), LOW);
  digitalWrite(OrangeLed(), LOW);
  digitalWrite(GreenLed(), LOW);
  
  switch (_state)
  {
  case LOW_OUT_OF_RANGE:
    noTone(Buzzer());  
    break;
    
  case WAY_TOO_CLOSE:
    Show(300, RedLed());
    break;
    
  case TOO_CLOSE:
    Show(275, OrangeLed());
    break;
    
  case OK:
    Show(250, GreenLed());
    break;
  
  case HIGH_OUT_OF_RANGE:
    noTone(Buzzer());    break;
    break;
  
  default:
    // Error
    break;
  }
}


void Sensor::Show(uint16_t sound, uint8_t led)
{
  tone(Buzzer(), sound);
  digitalWrite(led, HIGH);
}


void Sensor::PrintDistance()
{
  Serial.print(&quot;Sensor &quot;);
  Serial.print(Index());
  Serial.print(&quot;: &quot;);
  Serial.print(_distance); 
  Serial.print(&quot;cm    &quot;);
  
  if ((_state == LOW_OUT_OF_RANGE) || (_state == HIGH_OUT_OF_RANGE))
  {
    Serial.print(&quot; (Out of range)&quot;);
  }
  
  Serial.println(&quot;&quot;);
}
</code></pre>
