Buzzer won't stop beeping

I am trying to trigger a buzzer with tx and get xbee radio module data with rx on same serial port 1. I am using a Nano BLE Sense Rev2 board which has hardware serial ports. But the buzzer won't stop beeping even after pulling the pin LOW after beginning serial1. I am able to receive data from radio.

Code:

void setup() {
  pinMode(0, OUTPUT);
  Serial.begin(9600);
  Serial1.begin(9600);
  Serial2.begin(9600);
  digitalWrite(0, LOW);
}
void loop() {
  /*
digitalWrite(0, HIGH);
delay(1);
digitalWrite(0, LOW);
delay(1);
*/
  /* Serial1.println("1");
  delay(1);
  Serial1.println("0");
  delay(1);*/
  if (Serial1.read() == '2') {
    Serial1.println("Begin Transmission");
    Serial.println("Begin Transmission");
  }
}

what board?
pin 0 is usually Rx for Serial and it's used as an INPUT when you call Serial.begin()

what type of buzzer? some need a resistor to limit the current draw when activated

1 Like

I mentioned the board, it is a Nano 33 BLE Sense Rev2
It is a passive buzzer and I am triggering it with n channel mosfet (CJ8810). When I don't begin serial1, the buzzer works as expected and starts only when I print something like Serial1.print("11111111111111111"); in Serial1 port.
So, the circuit is correct.

The board has pinout as below:

image

As @J-M-L wrote, pin D0 and pin D1 are ALSO used for serial Rx and Tx. When you use D0 and D1 without Serial.begin, your circuit works. When you Serial.begin(), the Rx/Tx of D0 and D1 interfere with your circuit. Do not use buzzer on D0 or D1.

sorry missed that

here is a larger pinout diagram

Serial is only connected to the USB on the Nano 33 but Serial1 is connected to pins 0 and 1.

Is there any way to make this happen? I have made a pcb using the D0 pin for trigger so its not possible to change the pin

@J-M-L shows that if you do not use the buzzer on Serial1, Serial1.print() will not interfere with your buzzer circuit.

Without breadboard testing it first?

1 Like

I am not printing anything in Serial1, it is used only for receiving data, the same is done in the code I uploaded above.

without risk, victory is weak...

Yeah, I missed it

Basically, I only want to use rx pin of Serial1 port and use tx pin as a normal digital pin

Serial is a two wire protocol. that makes sense to you?

Why?

You said that you did. Show your code, please.

I have tested two different devices on same serial port one in rx and one tx and they worked fine, so I was sure that a can make use of Tx pin for buzzer too but it didn't work as the buzzer stays on.

Yes, but why not just use another pin?

When I want to trigger the buzzer in that case I would use that, but in my above code, I am not printing anything

Hardware serial ports use hardware internal to the MCU, it is designed to allocate both pins for use if serial is enabled.

The buzzer I used is passive and was louder when I ran it using tx than making a pulse with any other digital pin