Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 3 of 3

Thread: Piezo speaker doesn't beep on battery power

  1. #1

    Piezo speaker doesn't beep on battery power


    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
    pinMode(speakerPin, OUTPUT);
    and the routine is
    void Beep(int pitch, int duration)
      for (int j=1; j < duration; j++)
          digitalWrite(speakerPin, HIGH);  // send 3.3 volts to the speaker pin
          digitalWrite(speakerPin, LOW);  // remove voltage from the speaker pin
    I'd be grateful for hints!

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    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.

  3. #3
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts