Notifications
Clear all

Confusion about noisemakers: speakers, buzzers, transducers - what to buy?

9 Posts
5 Users
2 Likes
1,057 Views
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
Topic starter  

Hi all,

I have an experiment going, and used a small speaker to add some feedback, for when the ESP32 is not connected to the Serial Monitor. I just have the one speaker, from my beginning electronics kit, and I figure it is magnetic, since it has a little coil of wire. I don't know much else, since I don't want to tear it apart, other than it works at 3.3 and 5 volts, to make little chirps and beeps.

So I just need something inexpensive, 3-5V, to make beeps, chirps, etc., no music or voice at all. If I have to also order transistors and other components, I will, but I would prefer just something I apply some voltage to, and go. I don't care about the sound quality, or whether it is magnetic, piezoelectric, active or passive. Ideally, I could just order a 5-pack of something, solder it into a perfboard, and that's it.

So my question is: what would you buy? Thanks! John

In theory, theory and practice are the same.
In practice, they're different.


   
Quote
THRandell
(@thrandell)
Brain Donor
Joined: 3 years ago
Posts: 217
 

Hi @jBo

   The one thing that didn't come up in your requirements is volume.  I've been playing around with Piezo Buzzers but to get any volume out of them I have to driver them with a PWM signal.  Adafruit has one that has a built in driver circuit that outputs a fixed 2 kHz beep.  Just apply 3-5V and off you go.  My guess is that it's not very loud.  I noticed that Piezo buzzers start to sing at about 4-5 kHz.

Tom

 

To err is human.
To really foul up, use a computer.


   
ReplyQuote
Will
 Will
(@will)
Member
Joined: 3 years ago
Posts: 2502

   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
Topic starter  

@thrandell  Thanks for your reply. That's a good point about need for a PWM signal, and yes, I am willing to do that. My current sketch does it that way. I adapted another sketch so that I've got a quickly rising series of frequencies, then falling. So it's not music, of course, but I suppose one could call it a primitive kind of "sound design." 🤔 

Sorry, I should have clarified about the PWM. On the ESP32, I attach pin GPIO 12 to the positive wire of the little speaker. 

In theory, theory and practice are the same.
In practice, they're different.


   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
Topic starter  

@will Thanks, Will. I looked over that Instructable, and it made a lot of sense. As I know understand it, passive needs a PWM signal provide to it, which I'm doing, so passive is good for me. The active speaker already has some circuitry to provide a waveform of some kind, so it may cost a little more. What I also gather is that the active buzzers/speakers just have one frequency, although the Instructable seems to contradict this as he says he can produce different tones with his Arduino loop. This is intriguing, partly because his is the only example I've found to produce different frequencies without using the Arduino tone() and notone() functions. 

While on the topic, ESP32 does NOT have the tone() function, so none of those examples work. However, ESP32 does handle PWM extensively as you know, and in my case the ledcWrite() and ledcWriteTone() work fine. Adapted from some other examples, here's my main sound code. I return elapsed seconds from my function, because I don't want to get carried away and take too long.

loop() {
.
.
.

      //      Serial.println("let us have sound");
      float elapse_sec = tonesUpDown(50, 2500, 125, 5);
.
.
.
}  //end loop()

float tonesUpDown(int freqMin, int freqMax, int freqStep, int stepDelay) {
  /*
    On the previously initialized sound channel, give a series of tones. Each tone
    is higher than the last, in an arithmetic increase specified by freqStep.
    Give a tone at freqMin for stepDelay milliseconds, then increase by freqStep, until freqMax.
    Then, repeat, but start at max, tone, delay, decrease, until min.
    2021-09-20 John Bowen.
  */

  //  ledcWriteTone(soundChannel, 2000);
  //  for (int dutyCycle = 0; dutyCycle <= 255; dutyCycle = dutyCycle + 10) {
  //    Serial.println(dutyCycle);
  //    ledcWrite(soundChannel, dutyCycle);
  //    delay(10);
  //  }

  //ledcWrite(soundChannel, 125);

  int loopcount = 0;
  float elapsed = 0;
  long starttime_ms = millis();

  for (int frq = freqMin; frq < freqMax; frq += freqStep) {
    //    Serial.println(frq);
    ledcWriteTone(soundChannel, frq);
    delay(stepDelay);
    loopcount++;
  }

  for (int frq = freqMax; frq > freqMin; frq -= freqStep) {
    //    Serial.println(frq);
    ledcWriteTone(soundChannel, frq);
    delay(stepDelay);
    loopcount++;
  }

  ledcWriteTone(soundChannel, 0);
  elapsed = (millis() - starttime_ms) / 1000.0;

  Serial.print("freqMin: ");
  Serial.print(freqMin);
  Serial.print("; freqMax: ");
  Serial.print(freqMax);
  Serial.print("; freqStep: ");
  Serial.print(freqStep);
  Serial.print("; stepDelay: ");
  Serial.print(stepDelay);
  Serial.print("; elapsed seconds: ");
  Serial.print(elapsed);

  Serial.println("");

  return elapsed;

} //end tonesUpDown()

 

I will try out some of those buzzers you linked to, the Cylewet 5V ones. Thanks again!  -John

This post was modified 2 years ago 2 times by jBo

In theory, theory and practice are the same.
In practice, they're different.


   
Mark Bolton reacted
ReplyQuote
(@mark-bolton)
Member
Joined: 3 years ago
Posts: 108
 

Just dont...


   
ReplyQuote
(@mark-bolton)
Member
Joined: 3 years ago
Posts: 108
 

@jbo

"In theory, theory and practice are the same.
In practice, they're different."

When some "expletive deleted "says "a stopped clock is right twice a day" I go berserk ... any one who has ever studied the science of measuring things knows that a machine that is fucked never measures anything and can be trashed from the data set. . It is never right anytime...


   
ReplyQuote
Duce robot
(@duce-robot)
Member
Joined: 5 years ago
Posts: 670
 

Sound system?did someone say sound system?


   
ReplyQuote
jBo
 jBo
(@jbo)
Member
Joined: 3 years ago
Posts: 100
Topic starter  

@duce-robot  Thanks. Eh, no, not in the sense of high quality music or other audio. I'm just looking ahead to not having the Serial Monitor available, so I'm getting some little inexpensive speakers/buzzers for the purpose of audio feedback, kind of like I now use a small LED for some status, but I'm not lighting the room with it.  🙂

In theory, theory and practice are the same.
In practice, they're different.


   
Duce robot reacted
ReplyQuote