Auduino Fix + Delay

Hi,
Its not the speaker thats at risk, its the Arduino. The 40ma limit is the most that a pin will safely output, it will output more if you let it, but it will die in the process. It will look like your getting away with it, but you are not, your damaging your chip and at some point the output pin will stop working.

I am not sure that the 318 op amp is a solution, its more of a voltage amplifier than an current amplifier.

If you don't have an LM386, you can try a simple resistor and capacitor network to send the output to an mp3 player or anything else with an Aux input - the circuit is shown in the Illutron B link above.

Duane B

DuaneB:
Hi,
Its not the speaker thats at risk, its the Arduino. The 40ma limit is the most that a pin will safely output, it will output more if you let it, but it will die in the process. It will look like your getting away with it, but you are not, your damaging your chip and at some point the output pin will stop working.Are you sure about that? Thats not how I understand it . The USB port sets the current to the arduino at a set amount. (200mA? not sure atm). I thought each pin could not supply or sink any more than 40mAs ?

I am not sure that the 318 op amp is a solution, its more of a voltage amplifier than an current amplifier. Yes, but it was all I had and it did not work. Just something to try as I won't get the right one for a week.

If you don't have an LM386, you can try a simple resistor and capacitor network to send the output to an mp3 player or anything else with an Aux input - the circuit is shown in the Illutron B link above.I tried this to a 100 ohm resistor but it just reduced it more . With a 16 ohm impedence speaker it would take 300mA at most at this voltage (3.3V), the 100 ohm resistance droped this again

Duane B

Just a quick squiz at the datasheet for my ATMega328 and I have the (p) model which is low power I think

  1. Electrical characteristics
    29.1
    Absolute maximum ratings*
    Operating temperature................................... -55°C to +125°C
    *NOTICE:
    Storage temperature...................................... -65°C to +150°C
    Voltage on any pin except RESET
    with respect to ground .................................-0.5V to VCC+0.5V
    Voltage on RESET with respect to ground ......-0.5V to +13.0V
    Stresses beyond those listed under “Absolute
    Maximum Ratings” may cause permanent dam-
    age to the device. This is a stress rating only and
    functional operation of the device at these or
    other conditions beyond those indicated in the
    operational sections of this specification is not
    implied. Exposure to absolute maximum rating
    conditions for extended periods may affect
    device reliability.
    Maximum operating voltage.............................................. 6.0V
    DC current per I/O pin.................................................. 40.0mA
    DC current VCC and GND pins ..................................

So if anybody knows for sure please jump in . It stands to reason that perhaps certain chips can push more than 40mA's but I would like to know for sure.

A resistor is the only way to be sure that the current will not exceed the pins current rating. The USB power supply might allow higher currents for a short period of time such as bursts. There is no way to know what is possible without careful testing. It is easier to and cheaper to provide your own protection like the resistor.

Hi,

@ Duane B

You use this amp circuit just because you connect the arduino to an mp3 system like... ?

You think is safe just using a 10k ohm resistor if I want to use studio monitor, or sound interface.....

Hi,

I use the amp circuit so that I can power a PC Speaker directly from the Arduino without needing an MP3 dock or anything else.

I have used the simple Resistor/Capacitor circuit in the link below (from digital pin 6 to the Audio out jack) to output sound without amplification - for example to send sound output from the Arduino into the aux input of an MP3 dock or similar equipment.

I am far from expert though so others might have better suggestions -

Duane B

Ok now i've understand thx

I've tried your code hooking a button to digital pin 4, I dont have any delay in the sound processing, I've also tried to implement your code into that http://www.instructables.com/files/orig/F6S/7C5D/H2MYIX2S/F6S7C5DH2MYIX2S.ino but with no result...

here's the modified code....

any suggestions???

audino_LDR_delay_NOTWORK.ino (14.2 KB)

Hi,
The way the delay switch on/off is implemented is ugly - everyone has buttons, not everyone has a switch so I wrote the code as a very simple button/toggle switch.

To force delay, replace this section of code

// if the delay button is pressed, toggle delay
  if(0 == digitalRead(DELAY_BUTTON))
  {
    bDelay = !bDelay;
    // keeping it simple,
    delay(500);
  }

with

bDelay = true;

I will change the delay toggling code for something less ugly some day soon.

Duane B

rcarduino.blogspot.com

I'll got the same Error here

  pinMode(BUTTON_PIN,INPUT);

i've attached a screenshot of the log

Cattura.JPG

It looks as if you are trying to combine two sketches.

Can you compile each of the sketches on their own first ?

Do they do what you expect on their own ?

If your answer is yes and yes, I can tell you how to add the delay to the LDR sketch.

Duane B

I've compiled both scketches, the one with LDR sensor is working, the other not. I've attached a button to digital pin 4, but i can't hear the delay....

now I want to retry your scketch with an arduino duemilanove, instead of an arduino mega...

What are you expecting delay to sound like ?

EDIT: The delay is added to the output, so if you can hear the output, and bDelay = true; the delay is there.

As the Auduino outputs at a constant volume the delay can be heard as a reverb effect.

In projects with an attack/decay or even just on/off notes, the delay is more obvious as a repeat or echo of the initial note -

The same delay code running on the five dollar keyboard -

Duane B

Hi,
The way the delay switch on/off is implemented is ugly - everyone has buttons, not everyone has a switch so I wrote the code as a very simple button/toggle switch.

To force delay, replace this section of code

Code:
// if the delay button is pressed, toggle delay
if(0 == digitalRead(DELAY_BUTTON))
{
bDelay = !bDelay;
// keeping it simple,
delay(500);
}

with

Code:
bDelay = true;

I have a doubt....

I must change all the section that you indicate with

 bDelay = true;

or just this part

bDelay = !bDelay;

thx for helping me Duane sorry for my dumb questions... :slight_smile:

The section of code is a bit of a hack to use a push button as a toggle switch - its ugly and does not work that well, I will change it soon.

In the meantime to force delay on, replace the whole section with bDelay = true;

Duane B

Ok now I can feel the delay!!!!

want to show me how I can merge this two scketches now???? :grin:

I'm tryng to build even the LM386-N4 circuit amp, but I can't figure out how to power the IC... in the schematics you say its better to separate the power...

but how could do this? For my Auduino I use an arduino mega powered via usb.... I prefer not to use a battery... have you some advice for this?

Its a stupid idea try to power the circuit with the arduino mega??

G

Ok the amp circuit works!

Thanks Duane for your tutorial :wink:

I don't know why but the volume pot doesnt seems to work in the right way... is like a switch, you have to turn it until he reach a sort of treshold.... after that limit the volume start to pump...

Hi,

The pot is on the input side, its there to adjust the level of the input signal, not the output volume.

You do not hear much difference with square waves but with a sine wave you can hear the amp get overdriven as you adjust the input level, it can add an extra bit of colour to the sound.

Do you want volume ? I usually find the default volume is about right.

Duane B

oh shit I understand now!!! $)

I've notice a sort of colored sound.... yes the volume works good but iI would like to have less noise signal.... before solder all together I liked the filter "cut off"...

have you find a solution for the delay??? I would like to help you but I'm very bad in coding :disappointed_relieved:

Hi,
Two options for a nice hardware solution are -

  1. A toggle switch to turn delay on/off

  2. A potentiometer to adjust the delay buffer size anywhere from 0 for no delay to fractions of a second for a deep delay.

For now I will recommend 1) toggle switch, I will update the code to use this and the post to recommend this.

Duane B

Hi,
Very simple update to the code is now in place here -

It assumes a toggle switch is connected between the DELAY_BUTTON pin and ground and that a 10K pull up resistor is connected from 5V to the DELAY_BUTTON pin - your typical button with a pull up circuit except we are using a toggle switch inplace of a button.

I am making slow progress with a ribbon synth that uses and adaptation of the Auduino synth engine, hope to be able to post something soon.

Duane B

rcarduino.blogspot.com