Bike Alarm project: Using TDA2030 to amplify buzzer alarm

Hi there!

It's my second post on this forum, I hope to post it in the right section.

I'm trying to use a TDA2030A chip to use a 24V buzzer with Adruino. The set up is working when connected directly to the Adruino, but when using the TDA2030A chip, the buzzer is unexpectedly always sounding, not only when it's supposed to do it.

Can someone help me to understand this unexpected behavior? Is there any easier way to use a 24V buzzer with Adruino?

I attach some diagrams and the code of the full project, which is a bike alarm that triggers when someone disconnect or cut the wire.

Thank you a lot for your help!

Note: What in the attached full diagram is a MOSFET, in reality is a TDA2030A like you can see in the following handwritten diagram.

const int button1 = 2; //pushbutton1 on pin 3
const int button2 = 3; //pushbutton2 on pin 2
const int connector = 4; //pushbutton3 on pin 4 (this is going to be a connector in the future)

const int Red = 11; //red LED is on pin 11
const int greenLed = 10; //green LED is pin 10
const int buzzer = 13; //buzzer pin is 13
void checkEntered1(int button);
void activateAlarm();

int code[] = {1, 2, 2, 1, 1, 1}; //the desired code is entered in this array,
//separated by commas

int entered[7]; //create a new empty array for the code entered by
//the user (has 4 elements)

int alarmActive = 0; //variable to check if the alarm is activated


//*** Variables for the alarm **//

unsigned long currentMillis = 0;
unsigned long interval=300; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.
unsigned int tone1 = 0000; 
unsigned int tone2 = 6; 
unsigned int previousTone;
bool connected = true; 

void setup() { //run once at sketch startup
  Serial.begin(9600); //begin Serial

  pinMode(button1, INPUT_PULLUP); //button 1 is an input
  pinMode(button2, INPUT_PULLUP); //button 2 is an input
  pinMode(connector, INPUT_PULLUP); //button 3 is an input
  pinMode(Red, OUTPUT); //the red LED is an output
  pinMode(greenLed, OUTPUT); // the green LED is an output
  pinMode(buzzer, OUTPUT); //initialize the buzzer pin as an output
  previousTone = tone1; 

}

void loop() { //run repeatedly
    
  currentMillis = millis(); // grab current time
  //en cas que l'alarma estigui
  if (alarmActive == 1) {

    if (digitalRead(connector) == HIGH) {
      connected = false; 
    }
    if (!connected) {
      
      activateAlarm(); 
    }

  }
  if (digitalRead(button1) == LOW) { //if button1 is pressed
    checkEntered1(1); //call checkEntered and pass it a 1

    delay(250);//wait, needed for correct functioning, otherwise
    //buttons are deemed to be pressed more than once

  }
  else if (digitalRead(button2) == LOW) { //if button2 is pressed
    checkEntered1(2); //call checkEntered1 and pass it a 2

    delay(250); //wait

  }


}

void checkEntered1(int button) { //check the first element of the entered[] array
  if (entered[0] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered2(button); //move on to checkEntered2, passing it "button"
  }

  else if (entered[0] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[0] = button; //set the first element as the button that has been pressed
    Serial.print("1: "); Serial.println(entered[0]); //for debugging
  }

}

void checkEntered2(int button) { //check the second element of the entered[] array
  if (entered[1] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered3(button); //move on to checkEntered3, passing it "button"
  }

  else if (entered[1] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[1] = button; //set the second element as the button that has been pressed
    Serial.print("2: "); Serial.println(entered[1]); //for debugging
  }

}

void checkEntered3(int button) { //check the third element of the entered[] array
  if (entered[2] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered4(button); //move on to checkEntered4, passing it "button"
  }

  else if (entered[2] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[2] = button; //set the third element as the button that has been pressed
    Serial.print("3: "); Serial.println(entered[2]); //for debugging
  }

}

void checkEntered4(int button) { //check the third element of the entered[] array
  if (entered[3] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered5(button); //move on to checkEntered4, passing it "button"
  }

  else if (entered[3] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[3] = button; //set the third element as the button that has been pressed
    Serial.print("4: "); Serial.println(entered[3]); //for debugging
  }

}


void checkEntered5(int button) { //check the third element of the entered[] array
  if (entered[4] != 0) { //if it is not a zero, i.e. it has already been inputted
    checkEntered6(button); //move on to checkEntered4, passing it "button"
  }

  else if (entered[4] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[4] = button; //set the third element as the button that has been pressed
    Serial.print("5: "); Serial.println(entered[4]); //for debugging
  }

}

void checkEntered6(int button) { //check the fourth element of the entered[] array
  if (entered[5] == 0) { //if it is zero, i.e. if it hasn't been defined with a button yet
    entered[5] = button; //set the final element as the button that has been pressed
    Serial.print("6: "); Serial.println(entered[5]); //for debugging
    delay(100); //allow time for processing
    compareCode(); //call the compareCode function
  }
}
void activateAlarm() {

     // check if "interval" time has passed (1000 milliseconds)
   if ((unsigned long)(currentMillis - previousMillis) >= interval) {
  
   if (previousTone == tone1) {
     tone(buzzer,tone2);
     previousTone = tone2;
   }
   else if (previousTone == tone2){
     noTone(buzzer);
     previousTone = tone1; 
   }
   previousMillis = millis();
 }
  }
void compareCode() { //checks if the code entered is correct by comparing the code[] array with the entered[] array

  if ((entered[0] == code[0]) && (entered[1] == code[1]) && (entered[2] == code[2]) && (entered[3] == code[3]) && (entered[4] == code[4]) && (entered[5] == code[5])) { //if all the elements of each array are equal

    if (alarmActive == 1) { //Check if alarm is activated
      digitalWrite(greenLed, LOW); // turn the gren LED off
      alarmActive = 0;
      noTone(buzzer);
      connected = true; 
      Serial.println("Alarm Deactivated");
      delay(250);
    }
    else {
      digitalWrite(greenLed, HIGH); //turn the green LED on
      Serial.println("Alarm Activated");
      alarmActive = 1;
      delay(250);
    }





    for (int i = 0; i < 7; i++) { //this next loop is for debugging
      entered[i] = 0;

    }

    loop(); //return to loop() (not really necessary)
  }

  else { //if you (or the intruder) get the code wrong

    digitalWrite(Red, HIGH);
    delay(1000);
    Serial.println("Wrong PassWord");
    digitalWrite(Red, LOW);

    for (int i = 0; i < 7; i++) { //this next loop is for debugging
      entered[i] = 0;

    }

  }
}

the TDA2030 is a 5-pin IC. The IC in the Fritzing is 3 pins.
Where's the TDA2030 in the Fritzing ?

Nice first attempt however I would forget about fritzing and draw a schematic A schematic it is a lot more understandable especially as the circuits get more complicated. Your code looks like this is not your first rodeo. You do not have the grounds connected, that could explain the noise in your speaker. Your 24V is only 9 volts, a big problem. Your prototype board has no power connections. Your Arduino has no power unless it is via the USB. I would spend a few hours at least studying the electronics involved in your project. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

Dont use the pin 13, the onboard led is connected to this pin. as a general rule, use rx, tx and pin 13 as last resort. As i seem to understand, the led is the actual culprit. works like a weak pullup. moreover, this pin is pulled high during boot, regardless of code.

Hi,
Does the buzzer make a sound when connected directly to the 12V?
Is the buzzer a buzzer or a speaker of some kind?

If it is a proper buzzer and works when connected to supply, then you only need a MOSFET to switch it on and off.
Buzzers can be notoriously noisy EMC wise.
The electrical noise causing your controller to reset.
Can you post a link to the specs/data of the buzzer please?

This bit of code looks a bit weird...

    for (int i = 0; i < 7; i++) { //this next loop is for debugging
      entered[i] = 0;

    }

    loop(); //return to loop() (not really necessary)
  }

If you want to go back to the loop(), use return.

Thanks.. Tom.... :slight_smile:

The TDA2030A is an AUDIO AMPLIFIER (14W) !

You CAN'T connect a DC steady state signal directly. You need a 2.2uF axial electrolytic cap in series with
the "-" terminal connected to the TDA2030A input pin and the other to the pin-13.

Also, you can't use a piezo on the output of the audio amp. You need a speaker.
You need to use the example schematic on page 4 of the datasheet.

Hi! Thank you all for your answers and help. ++Karma!

raschemmel:
the TDA2030 is a 5-pin IC. The IC in the Fritzing is 3 pins.
Where's the TDA2030 in the Fritzing ?

Where you see the MOSFET there is actually the TDA2030A. The connections are like in the handwritten diagram I attached.

gilshultz:
Nice first attempt however I would forget about fritzing and draw a schematic A schematic it is a lot more understandable especially as the circuits get more complicated. Your code looks like this is not your first rodeo. You do not have the grounds connected, that could explain the noise in your speaker. Your 24V is only 9 volts, a big problem. Your prototype board has no power connections. Your Arduino has no power unless it is via the USB. I would spend a few hours at least studying the electronics involved in your project. This response is to help you get started in solving your problem, not solve it for you.
Good Luck & Have Fun!
Gil

I didn't know about Fritzing. I'm going to download it and try to make a better schematic. Thanks!

kaseftamjid:
Dont use the pin 13, the onboard led is connected to this pin. as a general rule, use rx, tx and pin 13 as last resort. As i seem to understand, the led is the actual culprit. works like a weak pullup. moreover, this pin is pulled high during boot, regardless of code.

I'm going to try it. That's a plausible problem. Thanks!

TomGeorge:
Hi,
Does the buzzer make a sound when connected directly to the 12V?
Is the buzzer a buzzer or a speaker of some kind?

If it is a proper buzzer and works when connected to supply, then you only need a MOSFET to switch it on and off.
Buzzers can be notoriously noisy EMC wise.
The electrical noise causing your controller to reset.
Can you post a link to the specs/data of the buzzer please?

This bit of code looks a bit weird...

    for (int i = 0; i < 7; i++) { //this next loop is for debugging

entered[i] = 0;

}

loop(); //return to loop() (not really necessary)
  }



If you want to go back to the loop(), use return.

Thanks.. Tom.... :)

Yes! I've just tried to connect it directly to the power source and I see that it produces a constant "Bip-bip". That means that the TDA2030 is always providing current to the buzzer? Here is the ebay link where I bought the buzzer.

raschemmel:
The TDA2030A is an AUDIO AMPLIFIER (14W) !

You CAN'T connect a DC steady state signal directly. You need a 2.2uF axial electrolytic cap in series with
the "-" terminal connected to the TDA2030A input pin and the other to the pin-13.

Also, you can't use a piezo on the output of the audio amp. You need a speaker.
You need to use the example schematic on page 4 of the datasheet.

I know that this chip is an amplifier, I was trying to reuse some that I had from other projects. Do you know if there is any way to hack this chip to work as a MOSFET?

Thanks again to everyone! I appreciate A LOT your time and effort to help.

No.
This is like askingvif you can use a hammer
as a screwdriver. They have nothing in common
other than they can run on the same power.
If you need a mosfet , use a mosfet.
If, on the other hand you want to call your
application an 'audio ' application then you
can replace your circuit with the example
on page 4 of the TDA2030A datasheet.
If you don't want music and simply want an
alarm tone then get a mosfet or transistor.

If you wanted an audio amplifier you would need to use the example schematic
on page 4 of the datasheet