Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino Nano Battery-Powered Audio Player with SD Card and LM386 Amplifier

View and Edit Project In Cirkit DesignerImage of Arduino Nano Battery-Powered Audio Player with SD Card and LM386 Amplifier

Circuit Documentation

Summary

This circuit is designed to read .wav audio files from an SD card and output the audio through a loudspeaker. The core of the circuit is an Arduino Nano, which interfaces with an SD card module to read the audio files. The audio signal is then sent to an LM386 audio amplifier module, which amplifies the signal and drives a loudspeaker. Power is supplied by a 4 x AAA battery mount.

Component List

  1. Arduino Nano

    • Description: A small, complete, and breadboard-friendly board based on the ATmega328P.
    • Pins: D1/TX, D0/RX, RESET, GND, D2, D3, D4, D5, D6, D7, D8, D9, D10, D11/MOSI, D12/MISO, VIN, 5V, A7, A6, A5, A4, A3, A2, A1, A0, AREF, 3V3, D13/SCK
  2. SD Module

    • Description: A module used to interface with an SD card for reading and writing data.
    • Pins: CS, SCK, MOSI, MISO, VCC, GND
  3. Loudspeaker

    • Description: A device that converts electrical signals into sound.
    • Pins: pin1, pin2
  4. LM386 Audio Amplifier Module

    • Description: A low voltage audio power amplifier.
    • Pins: VCC, IN, GND, OUT
  5. 4 x AAA Battery Mount

    • Description: A battery holder for four AAA batteries.
    • Pins: -, +

Wiring Details

Arduino Nano

SD Module

Loudspeaker

LM386 Audio Amplifier Module

4 x AAA Battery Mount

Code Documentation

/*
 * This Arduino sketch reads .wav audio files from an SD card and outputs
 * the audio through pin D8, which is connected to an LM386 audio amplifier
 * module. The audio is then played through a loudspeaker connected to the
 * amplifier module.
 */

#include <SD.h>
#include <SPI.h>

#define SD_CS_PIN 10
#define AUDIO_PIN 8

File audioFile;

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  // Initialize the SD card
  if (!SD.begin(SD_CS_PIN)) {
    Serial.println("SD card initialization failed!");
    return;
  }
  Serial.println("SD card initialized.");
  // Open the audio file
  audioFile = SD.open("audio.wav");
  if (!audioFile) {
    Serial.println("Failed to open audio file!");
    return;
  }
  Serial.println("Audio file opened.");
  // Set the audio pin as output
  pinMode(AUDIO_PIN, OUTPUT);
}

void loop() {
  if (audioFile) {
    while (audioFile.available()) {
      int audioData = audioFile.read();
      analogWrite(AUDIO_PIN, audioData);
      delayMicroseconds(125); // Adjust for sample rate
    }
    audioFile.seek(0); // Loop the audio file
  }
}

This code initializes the SD card and reads an audio file named audio.wav. The audio data is then output through pin D8, which is connected to the LM386 audio amplifier module. The amplifier drives the loudspeaker to play the audio. The audio file is looped continuously.