Error: collect2: error: id return 1 exit status

I was working on something and when I added a buzzer and the code for it and I got this error:
"collect2: error: id return 1 exit status" . The code works if I remove the code for the buzzer(
tone(buzzer, 1000) and noTone(buzzer) ) but with it I get the error. This is the code:

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <NewPing.h>
#define RST_PIN         5
#define SS_PIN          53
MFRC522 mfrc522(SS_PIN, RST_PIN);
Servo Barrier1;
const int red = 48, green = 49, buzzer = 41;
int distance;
String uid1 = "53 AF F6 38";
NewPing sonar (31, 30, 20);
void setup() {
Barrier1.attach(32);
pinMode[red, OUTPUT];
pinMode[green, OUTPUT];
pinMode[buzzer,OUTPUT];
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
delay(50);
}

void loop() {


  distance = sonar.ping_cm();
  if (distance >= 1)
  {
    digitalWrite(red, HIGH);
    digitalWrite(green, LOW);
  }
  else
  {
    digitalWrite(red, LOW);
    digitalWrite(green, HIGH);
  }

  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }

  
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  
  String content = "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  content.toUpperCase();
  if (content.substring(1) == uid1) 
  {
    Serial.println("uid1");
      tone(buzzer, 1000);
      delay(500);
      noTone(buzzer);
  }
  else if (content.substring(1) != uid1)
  {
    Serial.println("Unknown uid");
  }
  delay(1000);
}

Thanks for any help!

You have a conflict where libraries and/or functions are trying to use the same timer.

Maybe the tone() function and the Servo library. Maybe try the ServoTimer2 library?

More information if you Google "collect2: error: id return 1 exit status".

In the future please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

1 Like

Tried removing it and it still gives me the error.

Then you will need to find out where the conflicts are and deal with them. For instance, the NewPing library may be the source of a conflict. You can use the rangefinder without a library.
See here.

1 Like

Thanks for help, I will try!