Generating AUDIO ECHO using Atmega32 microcontroller

(video demo of echo generation using atmega32)
While I was studying at 10th standard, I used to play with small electronic circuits mostly based on transistor bc547 - bc557 pair. At that time, I just asked myself, I can amplify audio signals using few transistor combinations, but how can I make an echo effect which I used to hear in almost all loudspeaker announcements? I can't imagine what I can do with few transistors and resistors to make such an effect! I have no answer at that time because it was beyond my limitation..
  But now I can do this very easily by a simple digital signal processing using a microcontroller. It's concept is very simple, ie we need to apply a proper delayed feedback in digital samples with in a circular buffer. I did this using an atmega32 microcontroller and it worked fine. This is simple but really an interesting project. Not only an echo, but we can do a lot of fun with this type of small DSP experiments if we have considerably large RAM in the mcu...

 I am using an Atmega32 microcontroller for the purpose. It is having RAM of 2KB and an ADC which is enough for demonstrating the concept of echo generation. An electert mic is used for capturing the voice. It is introduced to ADC with proper amplification and level shifting, which are more critical for the perfect operation. Now the ADC module inside the AVR will convert the analog signal to digital signal at a particular sampling rate(which we can decide).  Now a 1900byte circular buffer is introduced. Our first aim is to make a delay in input and output audio. So, we can do one thing, ie we can populate the buffer from one end and we can read the buffer from another point so that there will be a delay! So how to make this delay to it's maximum? I think it will be better to explain it via a diagram.
uint8_t buf[1900]; 

Now, the next process is to make echo effect. For this,we need to provide a feedback from reading point to writing point. In simple words, we need to add a scaled version of reading signal along with the writing sample. The feedback gain should always be <1. So, now the digital signal in the buffer is processed by adding an echo effect. We can provide the reading samples to PWM of AVR to get the pulse width modulated signal. This could be demodulated by using a simple RC filter and can be provided to a power amplifier and we can notice an echo effect in the audio...

In my demo code, I also provided a 5 level echo selection via external push button, ie echo 0 to echo 4. 

We can do a lot of adjustments here. 

  • If we increase the sampling rate, the echo time gap and echo duration will be reduced but the audio quality will be increased. 
  • If we are decreasing the sampling rate, the echo time gap and echo duration will be increased. 
  • If we increase the feedback gain (but always < 1), the echo volume and echo number will be increased..
  • If we increase the feedback gain above 1, a totally disturbed audio is obtained due to oscillation.
  • To obtain a very good audio quality with good echo effect, both the echo buffer (RAM) and the sampling rate should be high..... Atmega2560 may be best for the purpose because it have 8KB RAM.

Circuit diagram:

 Now, for an audio amplifier, just search in google, we will get a lot of circuits which suits for our speaker specifications. So, I am not putting the diagram here. Still couldn't find it, just mail me. I will suggest suitable amplifier for your speaker.

 Source code:
#include <avr/io.h>
#define F_CPU 16000000
#include <util/delay.h>

uint8_t buf[1900];

void pwm_init();
void adc_init();
uint16_t adc_read();
void switch_enable();

void main()
    int i,j;
    int8_t echo_level = 4;
    uint16_t rd;
    i = 0;j=1;
    while(1) {
        rd = adc_read() +  buf[j]*echo_level;
        buf[i] = rd;
        OCR0 = rd;
        if(!(PINB & (1<<PB1))) {
            if(echo_level < 4) {
            } else if(!(PINB & (1<<PB2))) {
            if(echo_level > 0) {

void adc_init()
    ADMUX = 0b11000000;
    ADCSRA =0b10000010;

void switch_enable()
    DDRB &= ~((1<<PB1)|(1<<PB2));
    PORTB = (1<<PB1)|(1<<PB2);

uint16_t adc_read()
    uint16_t retl,reth;
    ADCSRA |= 1<<ADSC;
    ADCSRA |= 1<<ADIF;
    retl = ADCL;
    reth = ADCH;
    return reth;

void pwm_init()
To compile it in linux, check my previous post of the atmega32 based wav player. I have explained it in detail about the command line, the makefile etc...

Here is the hex for lazy guys...;-)

If you have any questions, you can ask me at [vinodstanur at gmail dot com]


  1. Very nice work! I saw your project on!

  2. Hi!

    Could you adapt your code for Arduino please?

    Lazy Guy

  3. Really cool!

    I see you use a 324 opamp, so you have three unused opamps, if you want to increase the audio quality (with this chip) you could split up the signal, so the Dry signal, the original one is not running trough the AVR, so it's quality is independent of the sampling rate/bit depth, and run the output from the avr and the original signal into a virtual earth mixer.

    Then you could even decrease the bit depth/sampling rate and give a longer lo-fi delay effect with the original quality dry signal.

    Or even use analog feedback of the delay signal, this could give a much better control over the amount of the delay and you can put additional filter in the feedback loop, so the "older" signal is less high freqs, like in an analog delay.

    And that would also give the ability to chain more smaller,cheaper AVR-s after each other for longer delays!

  4. Nice job ! Very inspiring. I did it on an atmega328 and I have some remarks.
    1. Why using two counters ? You don't need to start writing at 0 and start reading at 1. Both can be done from 0 by using only one counter (i in your case).
    The other remarks are a bit silly:
    2. By doing the test of the counters after incrementation at1899 you are loosing one sample. The test should be at 1900.
    3. On your figure, it should be 1899 not 1889. (actually, that's more than silly!).

  5. Great work. but how could be extend the delay? in audio buffer? which is buf[1900]? should i increase the array?

  6. Здравствуйте. Собрал я это устройство. Но у меня все гудит и звенит. Что я мог сделать не так? Подскажите какие фьюз биты нужно установить? Я использовал стандартные. И на входе у меня не микрофон, а гитара. Когда я бью по струнам гитару если если слышно в очень искаженно виде. Помогите. Я начинающий.

  7. Hi! I'm Rolando from Peru, I saw your video and it really impressed me!...My question is wheter I can generate a 8 bit song with an atmega88. I'm planing to implement a guitar hero simulator. Help me please! Any idea you can give me will be helpful, well I'll wait for your answer; thanks!

  8. Hi ,can you implemen on a tiva c launchpad? (tm4c123)
    thanks in advance

  9. oh THANKYOU. :) i've been banging my head on the wall trying t work out circular buffers and delays for a project adding reverb (echos) to a wav file playing from an SD card. Your example has solved my problem!! Thanks again.

  10. What are the fuse bit settings for 16mhz

  11. Whether for employment as an Electronics Engineering Technician or for further pursuance of a Bachelors Degree, it is always better to go for an accredited course. Cleveland Institute of Electronics (CIE), Penn Foster Career School, and Grantham University are three institutions that offer accredited Associate Degrees in the subject.generatore capacitivo alta frequenza

  12. This comment has been removed by the author.

  13. Hello, your project, it's really cool.
    Could you use a serial memory to improve the sampling?

  14. A landfill is a terrible place for electronic devices, since they contain components that can pollute when they're damaged. So, you might throw away a water-damaged cell phone, but if its screen is cracked in the process, it'll end up releasing mercury. rc judge

  15. Its Atmega32 or Atmel 32-tqfp

  16. An audio mixer is an important electronic item also popular under the name of a mixing console, mixing desk, audio production console or a mixer. Best Audio Mixers

  17. Other than this, nowadays numerous items are effortlessly accessible and can be gotten to in the online could check here

  18. can use an external ram spi for supply more ram?

  19. Purchasing out an electronic item in a rush may in some cases turn out to be a wrong choice for which you need to atone later. Top questions to ask an entrepreneur

  20. You may not know, but rather this individual is subject to it ordinary to make life simple. robot vacuum cleaner

  21. Thus in the event that we remember the above things, at that point regardless of whether we are assuming the job of a purchaser or seller,we can undoubtedly prevail in the realm of discount.Bobsweep review

  22. This gadget brags of a 3.2 super pixel camera and 2.2 inches wide TFT show board that indicates pictures to it clients in a goals of 240 x 320 pixels.Bobsweep pethair plus review

  23. Science and technology extend society's learning. Science enables people to increase expanded comprehension of how the world functions, while technology enables researchers to make these hearing amplifier reviews

  24. Discussions with different instructors are critical to resolving the subtleties and making ready toward genuine application in your class.source

  25. specialists and representatives don't need to invest valuable energy and exertion looking reports and looking after records; robots Washington

  26. really cool project Vinod! what IDE are you using to program the ATMEGA32?

  27. You will put in a couple of more bucks for this errand. When you are simply leasing, you won't have issues like this one. conference av hire

  28. Numerous sites effectively offer text to speech software to their online visitor, which has turned out to be an extraordinary help with regards to changing over composed archives into a sound arrangement. online text to audio converter

  29. This comment has been removed by the author.

  30. Contracting of this kind of gear requires proficient direction which you will discover at all online rental sites Orlando video production from American Audio Visual

  31. (if without a doubt they ever do), implies that creators and creator side distributing legal counselors and diversion lawyers can exploit this crossroads ever. electrician Perth

  32. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. OMC repair parts

  33. Excellent post. I was reviewing this blog continuously, and I am impressed! Extremely helpful information especially this page. Thank you and good luck. bestsoundbarlab

  34. Changed over electric cars can beIf you are thinking about doing the change to an electric vehicle, at that point there are a few things you ought to consider before beginning.used car dealerships near me

  35. Elegant simplicity combined with state-of-the-art performance makes the Genuine 110 a fine choice for an AM/FM radio. In table top radio

  36. Try not to let your utilized and broken electronics go to squander by giving them a chance to lounge around your home and get considerably increasingly pummeled, or more awful discarding them.Eye Massagers with Heat