This circuit is designed to integrate an Arduino Nano with various components including an Adafruit Audio FX Mini Sound Board, a SparkFun Electret Microphone Breakout, a TIP120 Hi-Current Darlington Transistor, a 12V power supply, a loudspeaker, a Power LED, and a 1 kilohm resistor. The Arduino Nano serves as the central processing unit, controlling the LED and sound playback based on input from the microphone. The Adafruit Audio FX Mini Sound Board is used for audio output, which is played through the loudspeaker. The TIP120 transistor is used to control the high-current LED. The circuit is powered by a 12V power supply, which also powers the LED.
3V3
connected to SparkFun Electret Microphone Breakout VCC
and Adafruit Audio FX Mini Sound Board VIN
A0
connected to SparkFun Electret Microphone Breakout AUD
D6
connected to TIP120 Transistor BASE
(via 1 kilohm resistor)GND
connected to common ground netD0/RX
connected to Adafruit Audio FX Mini Sound Board TX
VIN
connected to 12V power supply +
and Power LED +
D1/TX
connected to Adafruit Audio FX Mini Sound Board RX_5V
RST
, GPIO0_0
to GPIO0_7
, ACT
, L_AC
, CS
, UG
, VBUS
not connectedVIN
connected to Arduino Nano 3V3
GND
connected to common ground netTX
connected to Arduino Nano D0/RX
RX_5V
connected to Arduino Nano D1/TX
R_AC
connected to Loudspeaker pin2
+
connected to Arduino Nano VIN
and Power LED +
-
connected to common ground netpin1
connected to Adafruit Audio FX Mini Sound Board GND
pin2
connected to Adafruit Audio FX Mini Sound Board R_AC
BASE
connected to Arduino Nano D6
(via 1 kilohm resistor)COLLECTOR
connected to Power LED -
EMITTER
connected to common ground net+
connected to 12V power supply +
and Arduino Nano VIN
-
connected to TIP120 Transistor COLLECTOR
pin1
connected to TIP120 Transistor BASE
pin2
connected to Arduino Nano D6
VCC
connected to Arduino Nano 3V3
GND
connected to common ground netAUD
connected to Arduino Nano A0
// Pin definitions
const int soundSensorPin = A0; // analog output connected to A0
const int ledPin = 6; // LED bulb connected to D6
const int fxTriggerPin = 2; // FX board trigger pin connected to D2
// Variables
bool ledState = false; // To keep track of LED state
int clapCount = 0; // To count the number of claps
unsigned long lastClapTime = 0; // To store the time of the last clap
int trackIndex = 0; // To keep track of the current track for pin5
void setup() {
pinMode(soundSensorPin, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(fxTriggerPin, OUTPUT);
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
int sensorValue = analogRead(soundSensorPin);
// Detect clap (assuming a threshold value for clap detection)
if (sensorValue > 600) { // Adjust threshold as needed
delay(50); // Debounce delay
if (analogRead(soundSensorPin) > 600) {
unsigned long currentTime = millis();
unsigned long timeBetweenClaps = (currentTime - lastClapTime) / 1000; // Convert to seconds
lastClapTime = currentTime;
clapCount++;
Serial.println("Clap detected!");
// Toggle LED state
ledState = !ledState;
digitalWrite(ledPin, ledState ? HIGH : LOW);
// Determine which track to play based on time between claps and clap count
if (timeBetweenClaps >= 30 && timeBetweenClaps <= 45) {
if (clapCount % 2 == 1) {
playRandomTrack(1); // Odd clap, play from pin1
} else {
playRandomTrack(2); // Even clap, play from pin2
}
} else if (timeBetweenClaps >= 15 && timeBetweenClaps < 30) {
if (clapCount % 2 == 1) {
playRandomTrack(3); // Odd clap, play from pin3
} else {
playRandomTrack(4); // Even clap, play from pin4
}
} else if (timeBetweenClaps < 15) {
playSequentialTrack(5); // Play sequentially from pin5
} else {
// Default action if time between claps is outside specified ranges
playRandomTrack(0); // Play a random track from GPIO0_0 to GPIO0_4
}
// Wait for a short period to avoid multiple detections of the same clap
delay(500);
}
}
}
void playRandomTrack(int pin) {
// Generate a random number between 0 and 3 (for 4 tracks)
int trackNumber = random(0, 4);
// Send the track number to the FX board
// Assuming the FX board is set up to play tracks on GPIO0_0 to GPIO0_4
digitalWrite(fxTriggerPin, LOW); // Reset the trigger pin
delay(10);
digitalWrite(fxTriggerPin, HIGH); // Trigger the pin
delay(10);
digitalWrite(fxTriggerPin, LOW); // Reset the trigger pin
Serial.print("Playing track from pin");
Serial.print(pin);
Serial.print(": ");
Serial.println(trackNumber);
}
void playSequentialTrack(int pin) {
// Play the next track in order from pin5
int trackNumber = trackIndex % 8; // There are 8 tracks
trackIndex++;
// Send the track number to the FX board
digitalWrite(fxTriggerPin, LOW); // Reset the trigger pin
delay(10);
digitalWrite(fxTriggerPin, HIGH); // Trigger the pin
delay(10);
digitalWrite(fxTriggerPin, LOW); // Reset the trigger pin
Serial.print("Playing sequential track from pin");
Serial.print(pin);
Serial.print(": ");
Serial.println(trackNumber);
}
This code is designed to run on the Arduino Nano and controls the behavior of the circuit based on audio input from the microphone. It detects claps and toggles the state of the LED, as well as plays audio tracks from the Adafruit Audio FX Mini Sound Board. The code includes functions for playing random and sequential tracks based on the clap pattern detected.