element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Playing wave files using arduino, SD card and speaker
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Suggested Answer
  • Replies 9 replies
  • Answers 3 answers
  • Subscribers 390 subscribers
  • Views 1567 views
  • Users 0 members are here
  • audio
  • arduino
Related

Playing wave files using arduino, SD card and speaker

Former Member
Former Member over 10 years ago

Hi,

I've been trying to have an Arduino randomly choose a short mp3 file from an sd card and play it through a small 8ohm speaker and almost got it, but need help.

The SD is connected to the arduino using a logic level shifter (soldered to the SD pads, not using a shield or breakout board). Using the built in SD library I can read and write files consistently without problems.

Then I tried playing an 8bit,mono,8khz Microsoft wave file, by attaching the speaker to the ground rails and to the digital output pin through a 100ohm resistor.

It plays, but the volume is very low. I think that it's also slow and a bit choppy, but the volume is actually too low to tell.

I reckon I need to amplify the signal somehow.

Tried using an npn transistor with 5 volts. Didn't change anything.

Tried creating an audio amplifier using an LM386,but doesn't work either.

Before starting to provide schematics and discuss rc filters and capacitor sizes, I feel I know to little than to even choose the best or proper course of action.

My reasoning tells me the missing part here is an amplifier of sorts. Am I even right? Is the "nature" of the audio signal coming out of the digital pin even "amplifiable"

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 10 years ago in reply to Former Member +1
    Long story short got it working. And in time to give the birthday present, well, on the birthday. A. Used a SparkFun mono amp breakout board. Turns out I asked for LM386 at the store and got LM358N,which…
  • michaelkellett
    michaelkellett over 10 years ago in reply to Former Member +1
    Glad you got it going - there's nothing (well not much) worse than buying in some special part and getting the wrong thing. I think it happens about 1 part in 100. I have 50 TL082 chips here (dual op amp…
Parents
  • michaelkellett
    0 michaelkellett over 10 years ago

    What are you doing to make the Digital To Analogue Converter (DAC) - if you have an 8 bit .wav file you've got 8 digital connections to make but you only mention 1.

    (There are ways it can be done with only 1 pin but I don't think you are doing this from your description.)

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to michaelkellett

    That's a very good question. I don't know. The idea that it can be done was based on numerous examples on the Web and on YouTube showing it done exactly like that using not only the atmega328 but also using an attiny85.

     

    So,I'm missing a DAC? any way it can be done without it, or at least improvised? I'll get a DAC if that's the way to go, but have a deadline I can't really push (birthday :-)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to Former Member

    If you want decent sound quality you need a proper DAC. If you are good at software you can make PWM DAC using a digital output pin and  a low pass filter  - you will need some kind of amplifier to drive  speaker.

     

    If there are projects on the web and you are in a hurry why not just copy one.

     

    I don't think you'll be able to decode mp3 in real time using an Arduino (but you can buy chips that will and can be controlled by an Arduino).

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to michaelkellett

    A. not trying to decode mp3. Trying to play WAV files.

    B. The library I mentioned (and several others)  do exactly that - use pwm in software. It works, but the volume is low and choppy. So the low pass filter and amplifier that's missing was exactly my question.

    Problem is: values to use for resistor/capacitor of low pass filter and what type of amplifier exactly.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to Former Member

    I can't see any reference to the software in your earlier posts but never mind -  the important thing is the PWM frequency being used - if the code has any documentation a link would help.  Did the project you're modifying have come with a schematic - is so could you link to it or post yours.

    If you are trying to drive a speaker you need an audio power amplifier, something like an LM386 or LM380 should do.

    You do need a filter between the processor pin and the amplifier.

    I see that you tried an LM386 but it didn't work  - should have at least made more noise so the next question:

    Do you have any test gear ?

     

    MK

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to michaelkellett

    Wow, sorry about that. The library in use is the tmrpcm library . https://github.com/TMRh20/TMRpcm. My bad.

    Yes, I've tried using an LM386 but it didn't work. It made no sound at all. Tried without a filter.

    I wanted to know if it were the course to go before trying to arrange a test.

    My intention is to try and use the LM386 to amplify simple audio from a headphone jack to make sure I got it right.

    I'll give that a try, and get back to you.

    It was important to me to get a preliminary approval for the general course of action -  processor pin pwm - to low pass filter - to opamp - to speaker

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    Long story short got it working. And in time to give the birthday present, well, on the birthday.

     

    A. Used a SparkFun mono amp breakout board. Turns out I asked for LM386 at the store and got LM358N,which are no good for audio amplification, and I didn't have the necessary parts to try and build one anyways.

    B. First I thought using a 9v battery and one 5V regulator for the atmega328 plus one 3v regulator for the logic level shifter and the SD. BUT, the 7805 uses the battery even when the arduino is put to sleep (power down, reset connected to button for wake up), so I went with 2 1.5 AA batteries. The volume is lower, but I've built a small enclosure for the speaker from cardboard, and it's good enough for one listener in a quite room, which was the purpose.

     

    Thanks a lot for your help. Turns out it was quite simple.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • michaelkellett
    0 michaelkellett over 10 years ago in reply to Former Member

    Glad you got it going - there's nothing (well not much) worse than buying in some special part and getting the wrong thing. I think it happens about 1 part in 100. I have 50 TL082 chips here (dual op amp) in a packet with a label saying MC74BLX4052 - luckily I didn't have the board to solder them to and they were replaced quickly.

     

    MK

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • suicidebattery
    0 suicidebattery over 5 years ago in reply to Former Member

    Hi, I know this thread is from some time ago, but would you be willing to share the code, if you still have it.

    I would like to do something similar to your project.

    Thank you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • suicidebattery
    0 suicidebattery over 5 years ago in reply to Former Member

    Hi, I know this thread is from some time ago, but would you be willing to share the code, if you still have it.

    I would like to do something similar to your project.

    Thank you.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube