Driving a loud buzzer...

I’ve created a simple trip alarm using a 12 volts, Piezo buzzer. It’s a monotonous buzzer so I’ve driven it using PWM to make a rising and falling sound effect. Just like a siren.

On the breadboard, it was working as I have expected. I am using Arduino Uno by the way. Then I transferred it to stand alone version, whenever the alarm comes off, the circuit would reset itself. Sometimes it just hang.

The connection was simple, the positive terminal of the buzzer is connected to 12 volts, the negative terminal buzzer is connected to the Collector pin of BC547, the Emitter of the transistor is connected to ground. I have a 1K resistor connected to the base which is then connected to a PWM pin of my ATMEGA328P.

I am all lost, what am I dong wrong. The circuit would work if I leave the buzzer out and replace it with a power LED instead.

Help, please?

Hi Rolly

How are you powering the Arduino and the buzzer? How are they connected? Did anything change between the breadboard and standalone versions?

Regards

Ray

A photo of the PCB might help. It could be a short somewhere on the board.

Hackscribble: Hi Rolly

How are you powering the Arduino and the buzzer? How are they connected? Did anything change between the breadboard and standalone versions?

Regards

Ray

I have a diagram ready to show but I seem to not find how to attach image here.

I hope I can explain it enough for your imagination to draw the picture in your head...

The main power supply is 12 volts. I have a 5 volts voltage regulator connected to it so I can power the the ATMEGA328P. The buzzer is 12 volts so I hook it up directly to the 12 volts rail. I have an NPN transistor connected between the buzzer and ground, it's wired as a switch as we all know how. The the base of this transistor is connected to the pin 5 of my ATMEGA328P chip via 1K resistor.

Looking further, I've noticed that the circuit would resets itself (if it doesn't hang) when the sound becomes louder. Could it be that the buzzer is drawing too much current? Is my connection wrong?

Try wiggling something.

KenF: Try wiggling something.

There's nothing to wiggle, everything is soldered to a protoboard. The connection has been checked many times. The problem begins when the alarm is sounded. And it's easy to check the alarm connection. The buzzer is connected to 12 volts, the negative pin of the buzzer is connected to the collector of NPN transistor, the emitter of the transistor is then connected to the ground.

I did a check just now, I disconnected the base of the transistor from the ATMEGA328P chip and use a wire to tap it to the 5 volts supply. The buzzer gave loud sound. I also tapped it to the 12 volts rail, and the same result. conclusion is that the NPN transistor is working. I replaced the ATMEGA328P and I still have the same issue.

What I will do now is to change the signal of the ATMEGA328P where the buzzer is connected to be either high or low (ON or OFF). I will not use PWM. I will let you know what happens...

From this code;

/*** Sound the alarm! ***/
for (int j=10; j<255; j = j * 1.5){
analogWrite(ALARM, j);
delay(50);
}

changed to this code;

/*** Sound the alarm! ***/
for (int j=10; j<255; j = j * 1.5){
//analogWrite(ALARM, j);
digitalWrite(ALARM, HIGH);
delay(100);
digitalWrite(ALARM, LOW);
delay(50);
digitalWrite(ALARM, HIGH);
}

It’s now working. And I have a more panic inducing alarm. hahaha

But I guess I will never know what’s wrong with the previous code.

It could be the layout of your board, but we'll never know.

Thanks. Have a good one guys...

Hi, well have you fixed your problem, what was it. It would be nice to know so if others find themselves in the same situation they may be able to use your solution.

Also re-edit your subject and put [SOLVED] on the end of it.

If you use Reply AND NOT Quick Reply, you will find at the bottom of the screen an ATTACHMENTS facility.

Tom.... :)

TomGeorge: Hi, well have you fixed your problem, what was it. It would be nice to know so if others find themselves in the same situation they may be able to use your solution.

Also re-edit your subject and put [SOLVED] on the end of it.

If you use Reply AND NOT Quick Reply, you will find at the bottom of the screen an ATTACHMENTS facility.

Tom.... :)

Gee, how do I re-edit the subject?

I've already posted the code that fixed my issue. However, I can explain why the circuit behaved as such.

Do not forget the 0.1 uF decoupling capacitor. Nick Gammon-Make your own board