• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

audio output using arduino

Thread starter #1
What is the easiest way to output audio using arduino?

The audio output that I need will be a voice saying "turn left", "turn right", "The device is now turned on". "Error! Please press the reset switch." From these, I can estimate that each audio output will not exceed 5 seconds.

Additional info: My arduino uses ATMEGA 168 microcontroller.
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#2
Thread starter #3
Thank you for the link.

I have 512 bytes of EEPROM on arduino.
Can't I use that?
 
Thread starter #5
I already have a raw audio file. A very short one and it's already 5KB. :D :p :D

I saved it as mono, 8 bit unsigned, and with sample rate of 8000.

From the link on post 3:

"I recorded a second or so of audio using Audacity, dumped it as an 8 bit raw audio file, and then converted it to bytes."

How do I convert the .raw to byte?

Additional:
Code:
void setup()
{
  pinMode(11, OUTPUT);                                                     //pin 11 designated as output
  TCCR2A = _BV(COM2A1) | _BV(WGM21) | _BV(WGM20);        //i don't understand
  TCCR2B = _BV(CS20) ;                                                     //i don't understand
  OCR2A = 180;                                                                 //i don't understand 
}
 
void loop()
{
  int i ;
  char ch ;
   
  for (i=0; i<sizeof(bwdat); i++) {
    ch = pgm_read_byte_near(bwdat+i) ;                               //read back a char
    OCR2A = ch ;                                                               //i don't understand
    delayMicroseconds(125) ;
  }
}
This is the code on your link.
I could not understand some parts.
Kindly explain or add comment.
Thank you. :)
 
Last edited:

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#6
Code:
TCCR2A = _BV(COM2A1) | _BV(WGM21) | _BV(WGM20);
The timer counter control register... COM2A1 set ( non inverting mode )
WGMx0 and WGMx1 wave form generator = Fast PWM mode.

Code:
TCCR2B = 0x01;
... No prescaler.

Code:
OCR2A = 180;
Output compare loaded with initial data.
Code:
OCR2A  ch;
= Voice data

For more info section 14.11 of the ATmega324 manual.... http://www.electro-tech-online.com/custompdfs/2013/02/doc8011.pdf
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
#8
There is always that option.... I have a datalogger that uses Arduino and the SD setup...

The Colourmax has audio out but it uses the RAM drive for speed.... Not sure about SPI mode on an SD card... Trial and error..
 
#9
Try connecting your speaker output on your computer to an analog output on the arduino, record the wavelengths, and then use one of the pwm outputs to produce those pulses and connect it to a speaker
 
Thread starter #10
Here's the testing for the audio output of the project.
There's no filtering yet so there is still some noise coming from the PWM pin.

Enjoy. :)

Titanium
 

Latest threads

EE World Online Articles

Loading

 
Top