Piezo speaker doesn't beep on battery power

Status
Not open for further replies.

bugeye60

Active member
Hello,

I'm using a Teensy 3.5 with a piezo speaker that beeps as expected when connected to power through USB. However, when I remove the USB and power it via batteries, sometimes the speaker beeps but usually it doesn't.

The setup is simply
Code:
pinMode(speakerPin, OUTPUT);

and the routine is
Code:
void Beep(int pitch, int duration)
{
  for (int j=1; j < duration; j++)
    {
      digitalWrite(speakerPin, HIGH);  // send 3.3 volts to the speaker pin
      delayMicroseconds(pitch);
      digitalWrite(speakerPin, LOW);  // remove voltage from the speaker pin
      delayMicroseconds(pitch);
    }
}

I'd be grateful for hints!
 
Maybe try also turning on a LED, so you can watch if the Beep() code is running or now?

You could just connect the LED+resistor to the same pin. Rapid pulsing of the pin should appear as the LED on.
 
As Paul, mentioned are you sure the code is executing?

Or maybe does your code hang some place. Example if you have code like: while (!Serial) ;
Which waits for the USB Serial to become available.

I would probably if possible toggle the LED each time this function is called to see if it is called (digitalWrite(13, !digitalRead(13));
Which assumes you already did a pinMode to OUTPUT earlier....

Also does your battery setup provide enough voltage/current to run properly?
 
Status
Not open for further replies.
Back
Top