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

Arduino Mega 2560-Based Audio-Responsive LED and Stepper Motor System

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560-Based Audio-Responsive LED and Stepper Motor System

Circuit Documentation

Summary

This circuit is designed to create an interactive audio-visual experience using an Arduino Mega 2560 microcontroller. The circuit includes a stepper motor, a loudspeaker, a microphone, NeoPixel LED sticks, a pushbutton, a resistor, and a micro SD card module. The system visualizes audio frequencies and beats using LEDs, controls a stepper motor to create mechanical movements, and plays audio from an SD card.

Component List

  1. Arduino Mega 2560

    • Description: Microcontroller board based on the ATmega2560.
    • Pins: IOREF, RESET, 3V3, 5V, GND, VIN, A0-A15, D0-D53, AREF, SDA, SCL
  2. 28BYJ-48 Stepper Motor

    • Description: 5V stepper motor used for precise control of mechanical movements.
    • Pins: BLUE, PINK, YELLOW, ORANGE, RED
  3. ULN 2003

    • Description: Darlington transistor array used to drive the stepper motor.
    • Pins: IN1-IN7, GND, +, COIL1-COIL5
  4. Micro SD Card Module

    • Description: Module for reading and writing to micro SD cards.
    • Pins: cs, sck, mosi, miso, vcc, gnd
  5. Loudspeaker

    • Description: Audio output device.
    • Pins: pin1, pin2
  6. Adafruit NeoPixel Stick

    • Description: LED stick with individually addressable RGB LEDs.
    • Pins: GND, DATAOUT, +5V, DATAIN
  7. MAX4466

    • Description: Microphone amplifier module.
    • Pins: OUT, GND, VCC
  8. Pushbutton

    • Description: Simple pushbutton switch.
    • Pins: Pin 3 (out), Pin 4 (out), Pin 1 (in), Pin 2 (in)
  9. Resistor

    • Description: 10k Ohm resistor.
    • Pins: pin1, pin2
    • Properties: Resistance: 10k Ohms

Wiring Details

Arduino Mega 2560

28BYJ-48 Stepper Motor

ULN 2003

Micro SD Card Module

Loudspeaker

Adafruit NeoPixel Stick

Adafruit NeoPixel Stick

MAX4466

Pushbutton

Resistor

Documented Code

//ChatGPT was used to help debugging and fix errors with the FFT Data Arrays and LEDs functions 
//The LEDs for beat visulisation was inspired by this video - https://www.youtube.com/watch?v=5WP2Tjt9o2U&t=96s
//The LEDs for frequency visualisation was used the format from - https://github.com/BrainSmash/Arduino-Acoustic-Control-for-RGB-LED-Strip/blob/master/BrainSmash_AcousticControlForRGBLEDStrips_6_2019.ino
//ChatGPT was also used to merge codes together and to help create some of the comments 

#include <FastLED.h>
#include <Stepper.h>
#include <TMRpcm.h>
#include <SD.h>
#include <arduinoFFT.h>

/** LED Configuration **/
#define BEAT_LED_PIN 6           // Pin for the beat LED strip
#define NOTE_LED_PIN 7           // Pin for the note LED strip
#define NUM_BEAT_LEDS 15         // Number of LEDs for beat visualization
#define NUM_NOTE_LEDS 15         // Number of LEDs for frequency visualization
#define MIC_PIN A0               // Pin for microphone input
#define SAMPLES 128              // Number of samples for FFT
#define SAMPLING_FREQ 4000       // Sampling frequency for FFT
#define PEAK_THRESHOLD 150       // Threshold for peak detection
#define PEAK_HOLD_TIME 300       // Time to hold peak visualization
#define MIC_LOW 0                // Minimum microphone value
#define MIC_HIGH 737             // Maximum microphone value
#define PLAY_BUTTON_PIN 9        // Pin for play button

// FFT Data Arrays
double vReal[SAMPLES];           // Real part of FFT input
double vImag[SAMPLES];           // Imaginary part of FFT input
ArduinoFFT<double> FFT(vReal, vImag, SAMPLES, SAMPLING_FREQ);

// LEDs
CRGB beatLeds[NUM_BEAT_LEDS