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.
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.
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.
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.