// Define stepper motor connections and steps per revolution: #define dirPin 1 #define stepPin 2 #define threshold 500 // Adjust this value based on your microphone and clap sound const int numberOfSteps = 200; const int numberOfStepsIncrease = 32; const int stepsPerRevolution = numberOfSteps * numberOfStepsIncrease; int rotationTimePerSecond = 4; // 1 rotate in 4 second (1 ) int micPin = 26; // Analog pin connected to microphone int clapDetected = 0; // Flag to indicate clap detection void setup() { // Declare pins as output: pinMode(micPin, INPUT); pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); Serial.begin(9600); } void loop() { // Set the spinning direction clockwise: int sensorValue = analogRead(micPin); // Simple clap detection based on exceeding a threshold if (sensorValue > threshold && !clapDetected) { clapDetected = 1; Serial.println("Clap detected!"); // Print to serial monitor for debugging (optional) digitalWrite(stepPin, HIGH); delayMicroseconds(rotationTimePerSecond * 500000/stepsPerRevolution); digitalWrite(stepPin, LOW); delayMicroseconds(rotationTimePerSecond * 500000/stepsPerRevolution); } else if (sensorValue <= threshold && clapDetected) { clapDetected = 0; } }