Question Regarding Four Microphone Sound Detection System

I am using an Arduino Mega 2560 to make a system (with four microphones, eight RGB LEDs, and 4 servo motors) that if one specific microphone picks up a loud enough sound, it will trigger a certain color combination of LEDs and turn only just two of the servo motors 90 degrees.

There will be four different combinations of possible LED and servo outcomes for the four different microphones inputting a loud enough sound.

I have attached the code I have so far (One problem with the code is that once a specific microphone is triggered, the serial monitor output stops. I would like to have a continuously running output of the read microphone inputs).

I have been having difficulty with the code and are looking for general guidance on how I should approach and improve this project.

Please let me know if you need anything else to help me.

Thank You.

Code 2020.pdf (71.6 KB)

More members will see our code if you post it in accordance with the forum guidelines (see #7).

 for (pos = 0; pos <= 90; pos += 1)   // goes from 0 degrees to 90 degrees
         // in steps of 1 degree
         myservo1Pin34.write(pos); // tell servo to go to position
         in variable 'pos'
         Serial.println("Orange Sound Intensity Value:");
         Serial.println("Yellow Sound Intensity Value:");
         Serial.println("Green Sound Intensity Value:");
         Serial.println("Blue Sound Intensity Value:");

It will take (5000+15) * 90 milliseconds for that for loop to execute. Serial does not stop, your program has, for all intents and purposes, stopped. For (and while) loops block execution and should not take very much time if used. If you want a responsive program, avoid for and while loops and use millis() to do non-blocking code.

Non-blocking timing tutorials:
Several things at a time.
Beginner’s guide to millis().
Blink without delay().