How to make a -very- small button/speaker circuit?

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
Sounds like a simple alternating tone between two high pitched frequencies. I think it would be fairly simple to generate on an ATTiny85.

I use the Arduino IDE and a programmer from Sparkfun to program the ATTiny85. There is a command, tone(), which plays a tone through a pin to a piezo speaker.

The following code example would work.

Code:
unsigned int hitone = somevalue;
unsigned int lotine = anothervalue;
unsigned int timetone = xxx;
unsigned int outpin = pp;
while (-1) {
   tone(outpin, hitone );
   delay(timetone);
   tone(outpin, lotone);
   delay(timetone);
   }
UPDATE: I missed the pushbutton switch. It is easy to modify the sketch to use a pushbutton. Let me know if you need help in modifying the code.
Hello! Thank you for providing this code. There are a couple modifications I'd need, but I'm not super familiar with this coding language.

Primarily, I would need the code to be modified for the push button. But if it's possible to run two things at once on the microcontroller, I'd also want a light that turns on and off alongside the speaker.

Edit: would this programmer work, bt the way? It's much cheaper, but it seems to be the same thing but smaller.
 
Last edited:

djsfantasi

Joined Apr 11, 2010
9,237
Hello! Thank you for providing this code. There are a couple modifications I'd need, but I'm not super familiar with this coding language.

Primarily, I would need the code to be modified for the push button. But if it's possible to run two things at once on the microcontroller, I'd also want a light that turns on and off alongside the speaker.
I can easily modify the sketch to do both of those things. BUT, you’d need to supply the frequency of the high and low tones and how fast you’d want them to change.

I could assign pin numbers for the pushbutton, the light and the speaker assuming an ATTiny85. But I am leaving for vacation so further support would have to wait until I return in a week or so.

In the meantime, if I were you I’d follow up on the ISD1610. It might be a better fit for your application.
 

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
I can easily modify the sketch to do both of those things. BUT, you’d need to supply the frequency of the high and low tones and how fast you’d want them to change.

I could assign pin numbers for the pushbutton, the light and the speaker assuming an ATTiny85. But I am leaving for vacation so further support would have to wait until I return in a week or so.

In the meantime, if I were you I’d follow up on the ISD1610. It might be a better fit for your application.
It seems like the ISD1610 is made for recording and playback? Unless it can generate sounds as well, I feel like that would require a bit more work to get it to loop a short sound and stop immediately.

I'll most likely order an ATTiny85, since I found one that comes with a programmer as well. As for the wait, it will take at least a week to get here anyways, so I should be good on that regard.
 

djsfantasi

Joined Apr 11, 2010
9,237
It seems like the ISD1610 is made for recording and playback? Unless it can generate sounds as well, I feel like that would require a bit more work to get it to loop a short sound and stop immediately.

I'll most likely order an ATTiny85, since I found one that comes with a programmer as well. As for the wait, it will take at least a week to get here anyways, so I should be good on that regard.
I had a few minutes and I wrote the code for what you asked. There’s probably room for improvement, but this should work.

ATTiny85 Sonic Screwdriver:
// Sonic Screwdriver

#define Forever TRUE
int hitone = somevalue; // must be replaced with a freq.
int lotone = anothervalue; // must be replaced with a freq.
int timetone = 300; // modify to make desired buzz

int trigger = 0;
int sound = 1;
int light = 2;

void setup() {
pinMode(trigger, INPUT_PULLUP);
pinMode(sound, OUTPUT);
pinMode(light, OUTPUT);
}

void main() {

while (Forever) {

 noTone(sound);
 digitalWrite(light, HIGH);
 
 while (digitalRead(trigger) == LOW){
   digitalWrite(light, LOW)
   tone(sound, hitone );
   delay(timetone);
   tone(sound, lotone);
   delay(timetone);
  }
 }
}
The beginning defines the parameters used in the sketch, making it easy to make simple changes to create the desired effect.

The setup function defines and initialized the three pins used. One for the pushbutton to activate the effect. One for a light and one for the sound.

The main function simply loops forever, waiting for a press of the pushbutton. If not pressed, it stops any sound and turns off the light. It does so even if it’s not necessary because it simplifies the code and leaves things in a know state if something goes wrong.

If the button is pressed, the program enters another loop until the button is released. This loop turns on the light and creates the sound. Since it loops, the sound continues as long as the button is pressed. As before, it turns on the light regardless of if it was already on because it simplifies the code.

When the button is released, the outer loop stops the sound and turns off the light. And so on.

There are certain assumptions on the hardware.

A pushbutton is connected between ground and pin 1, so that when it’s pressed pin 1 is grounded.

An appropriate piezo speaker is connected between ground and pin 2.

An ultra bright LED of the desired color is connected via a resistor to pin 3. The resistor value depends on the voltage supplied, the LED characteristics (Vf and IMAX) and limiting current to 5-10mA. If you need assistance in calculating the resistor value, supply the above parameters.

Here is the schematic.
3E10F328-99E3-413E-BDE7-8C8E946DD750.jpeg

I leave Friday night, so probably will answer any questions until then.
 

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
I leave Friday night, so probably will answer any questions until then.
Hello! One more quick thing, since I'm struggling to find it.
Would you happen to know what battery would fit in a container the size of my provided dimensions (1.1mm wide)? Or at least what battery that size would have a holder I can buy for it?
 

djsfantasi

Joined Apr 11, 2010
9,237
Hello! One more quick thing, since I'm struggling to find it.
Would you happen to know what battery would fit in a container the size of my provided dimensions (1.1mm wide)? Or at least what battery that size would have a holder I can buy for it?
No, I don’t know. But 1.1mm is extremely small. Like a strand of spaghetti. Are you sure that’s the width?
 

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
An ultra bright LED of the desired color is connected via a resistor to pin 3. The resistor value depends on the voltage supplied, the LED characteristics (Vf and IMAX) and limiting current to 5-10mA. If you need assistance in calculating the resistor value, supply the above parameters.
Hello again! Quick question.

If my power supply is 3v, and my LED takes 3v, is there a need for a resistor still, or will the LED be fine? The LED has a rated forward current of 20mA, would I need to still reduce it?
 

Audioguru again

Joined Oct 21, 2019
6,826
Nobody makes a 3V LED because it is not simply a very hot piece of wire, instead it is a special diode.

1) All diodes have a range of voltages, an LED diode might be from 2.7V to 3.3V but typically be 3.0V.Then with a 3.0V supply, a 2.7V LED will instantly burn out and a 3.3V LED will not light.

2) The LED voltage changes with temperature changes even as it warms up. Then the heating might cause its voltage to drop increasing the current which increases the heating and it continues heating until it burns out.
 

MisterBill2

Joined Jan 23, 2018
27,658
Nobody makes a 3V LED because it is not simply a very hot piece of wire, instead it is a special diode.

1) All diodes have a range of voltages, an LED diode might be from 2.7V to 3.3V but typically be 3.0V.Then with a 3.0V supply, a 2.7V LED will instantly burn out and a 3.3V LED will not light.

2) The LED voltage changes with temperature changes even as it warms up. Then the heating might cause its voltage to drop increasing the current which increases the heating and it continues heating until it burns out.
I routinely check LEDs with no series resistor tp limit the current. OF COURSE, a bit of sense is required to avoid causing damage. The check always starts well below the normal forward voltage, and of course the LED is observed while checking. An LED will usually start to illuminate about a volt below the published forward voltage. Just like a diode, the transition from non-conduction to full conduction is not a single point occurrence.
For nominal 2.7 volt LEDs the start of illumination is below 2.0 volts. Very dim, but definite. The brightness continues to increase and at 3 volts it is quite a bit brighter than at 2.7 volts, but they did not fail instantly. I have not held them at 3 volts until failure, but it must be more than 3 seconds. AND, be aware that most power sources do exhibit some internal resistance that will limit current some. Of course, a well regulated power source will tend towards showing zero internal resistance up to some current limit.
 

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
Nobody makes a 3V LED because it is not simply a very hot piece of wire, instead it is a special diode.


1) All diodes have a range of voltages, an LED diode might be from 2.7V to 3.3V but typically be 3.0V.Then with a 3.0V supply, a 2.7V LED will instantly burn out and a 3.3V LED will not light.


2) The LED voltage changes with temperature changes even as it warms up. Then the heating might cause its voltage to drop increasing the current which increases the heating and it continues heating until it burns out.
I somewhat understand? Not completely, but enough to rephrase my question.

My power supply gives 3.0V, which goes through a microcontroller, which will power on an LED that is rated for 3.0-3.4V and 20mA forward current. Would I need a resistor for that circuit, and if so, what resistor would I need?

Here is a link to the LED if that would help: https://www.sparkfun.com/products/10635
 

Audioguru again

Joined Oct 21, 2019
6,826
A microcontroller powered with 3.0V will not produce an output of 3.0V at 20mA, Its unloaded output will be 3.0V but loaded with 20mA it might produce only 2.5V.
The specs for your blue LED says 3.0V to 3.4V. If it is actually 3.4V then will it light up when fed only 2.5V? I doubt it.

I have a modern but cheap flashlight that has 60 white surface-mount LEDs in parallel and all matched for voltage and brightness and powered by three AAA "Sooper Heavy Dooty" battery cells with no current-limiting resistor. When the cheap battery failed I replace it with Name-brand alkaline cells and now the brightness is blinding.
 

Attachments

Thread Starter

CocoaHere

Joined Jan 18, 2023
13
A microcontroller powered with 3.0V will not produce an output of 3.0V at 20mA, Its unloaded output will be 3.0V but loaded with 20mA it might produce only 2.5V.

The specs for your blue LED says 3.0V to 3.4V. If it is actually 3.4V then will it light up when fed only 2.5V? I doubt it.

I have a modern but cheap flashlight that has 60 white surface-mount LEDs in parallel and all matched for voltage and brightness and powered by three AAA "Sooper Heavy Dooty" battery cells with no current-limiting resistor. When the cheap battery failed I replace it with Name-brand alkaline cells and now the brightness is blinding.
That's odd, then. With my current setup the light is very adequately bright with only 2 AAs powering a microcontroller.


20230207_113822.jpg
 

BobTPH

Joined Jun 5, 2013
11,555
If an LED has range of 3.0 to 3.4V at 20 mA, you have no idea what current it might draw when powered by a 3V source. It might be as high as 20 mA and it might be only 2 mA.

Now let’s look at lighting it with a 5V supply and resistor. We calculate based on 3.0V.

R = (5-3) / 0.02 = 100Ω

And let’s see what you get if the actual LED is 3.4V. The voltage across the resistor bow has to be 1.6V. So,

I = V/R = 16mA.

Actually it will be a little higher than that because the voltage drop at 16mA will be less than 3.0V

But, you have essentially guaranteed a current range between 16 and 20mA for any LED of that type. This is why you use a voltage higher than the forward voltage of the LED and a resistor. It acts as a current regulator. The higher the voltage, the better the regulation.
 

sghioto

Joined Dec 31, 2017
8,634
Use a resistor in series with the LED. Start with 100 ohm and see if that is bright enough. If not reduce the value of the resistor.
I have some super bright white LEDs that are easily visible at only 1 ma
 

BobTPH

Joined Jun 5, 2013
11,555
That's odd, then. With my current setup the light is very adequately bright with only 2 AAs powering a microcontroller.
And what will it be when the battery voltage drops to 2.5V? Batteries are at their rated voltage for only a small part of their useful lifetime. And what would it be if you manufactured 1000 boards and some of the LEDs were at the high end if 3.4V?

The reason it is adequately bright is that blue LEDs are insanely bright at 20mA.
 
Top