Alright y'all, help me out please

Okay first of all i'm new at arduino but familiar with C++, I made this code for a clap on/off light with a sound sensor and an arduino. I wired it correctly the first time but forgot to write it down before i took everything apart. Please help me out, I just need help with the wiring.
Here's the code:

#include <Servo.h>

Servo s;
int pos = 0;
int soundpin = A2;
int threshold = 200;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(soundpin, INPUT);
  s.attach(2);
  s.write(100);
}

void loop() {
  // put your main code here, to run repeatedly:
  int sens = analogRead(soundpin);
  
  if(sens >= threshold && s.read() == 180){
    s.write(0);
    delay(15);
  } else if (sens >= threshold && pos == 0){
    s.write(180);
    delay(15);
  }
}

I have a 4 pin sound sensor and because im running analog i have the AO pin in A2, I cant figure out why everytime i turn it on, the servo starts moving really fast regardless of if the sensor picks up any sound or not. I could use any recommendations or tips for the wiring or code.

Is the data pin of your servo attached to DIGITAL pin 2?

That can be just anything. Datasheet, please....

Please post schematics for the current wiring.

yes it is, thats what makes it go all weird and fast. i shouldve taken a picture of it before.

im sorry i dont have the software for that, do you know where i could do that?

This is a valid statement (following is from Servo.h):

read()      - Gets the last written servo pulse width as an angle between 0 and 180.

... but why do use this and not pos == 180?

The "if" conditions say "if sound > 200, sweep to the opposite side"... so sound must be over 200. Serial.println() the value of threshold and I think it will be over 200.

Four-pin sound sensor... DO/AO/VCC/GND

So I am now guessing you have connected DO to the AIN 2... and DO of the sound card is sending HIGH/5v/1023 bits telling the servo(s) to constantly sweep.

Software for what? Schematics? You surely have pen and paper.
Software for datasheet? Come on...

most schematics ive seen on here are used by a software, figured you used that as well.

You are thinking of TinkerCAD which works for simulations on TinkerCAD.com, but not for "schematic drawings" which should clearly show device identification, pins and connecting wires. A picture of a hand drawing works.

i know this sounds like a dumb question, but in terms of my code a wiring i'd fix the read() to a pos == 180 correct? in terms of wiring, is it my servo or sound sensor that's messed up or both. im sorry im not that seasoned like you guys are

Technology is so accessible, i figured everyone used it and i was the only one still using paper LOL, working on a schematic now

Your code is "correct" in using read() rather than "if x then write(180)" or "if x then write (0)" but it is strange to see read().

Check your sound sensor. Is the wire to Arduino A2 from the sound sensor "AO" (analog out)?

I suspect you are using the Digital Out pin of the audio sensor (registers a 1 = 5v = 1023 bits or 0 = 0v = 0bits) rather than Analog Out pin of the audio sensor (registers a range from 0v/0 bits to 5v/1023 bits). When your code sees DIO = 1/5v/1023 that is over the threshold value of 200. If the Analog Out of the audio sensor was connected, the value could be 0 to 199 before the servos sweep.

I still use paper to make my drawings at work to get ideas across without a wordy explanation. Available, never needs power, erasable, re-writable, correctable, and ready for side-notes. When I have everything correct, with time and patience, I draw it on a computer.

I tried my best LOL, i didnt realize how small my handwriting would look, so if you need me to translate it i can

ive tried connect both the servo and the sensor to digital and the only one that gets any kind of movement within the project is D2 however its not the movement thats in the code. im just kinda stuck on this project that seemed so simple at first but became a real headache after my servo started twitching

Seems you don't have any code line to change the value of pos. It is set to 0 when it is defined and will always stay 0 becuse there is nothing in the logic to change it.
So, when we get to th eif test, if sens > threshold, regardless of where the servo is, teh else if statement will rotate the serv to 180, then in the next pass of the loop the if statement will rotae it back to 0. So, as long as sens is above or equal to threshold the loop will just keep sending the servo to 0 then back to 180.
If you add "pos = 180" after s.write(0); delay(15) in the if test then the servo will go to 0 and stop there until pos changes to 0.
Perhaps what you are missing is an if test to check if sens > threshold, s.write(0)?

i could definitely try that, i really appreciate any help i can get. i just get worried its a wiring issue rather than coding issue. nothing will work the way you want it to if its not hooked up in a way that makes sense to you and the computer.

False. It sweeps, twice.

so i would essentially remove one line of the code to make it sweep only once in one direction continuously? i understand the double sweep, but would changing it cause it to move in one direction when triggered then wait then move back?

No.... sorry... I should have written:
"It sweeps twice... Once if the "read()" is 0, and once if the "read()" is 180" (and threshold is over 200)

Did you get a look at the sound sensor? Can you see VCC, GND, AO, DO? You have three wires that are not (to me) clearly labeled, and the Arduino pin looks like "20" and not "A2"