why dose this not work ?

void setup() {
// put your setup code here, to run once:int soundSensor = 2;
int LED = 3;

void setup()
{

pinMode (soundSensor, INPUT);
pinMode (LED, OUTPUT);
}

void loop()
{
int statusSensor = digitalRead (soundSensor);

if (statusSensor == 1)
{
digitalWrite(LED, HIGH);
}

else
{
digitalWrite(LED, LOW);
}

}

Hi, welcome to the forum. Please have a look at How to use the forum before making any more posts. Because your post is lacking code-tags and a ton of info.

How many setup() functions do you have in the code ?
How many are allowed in the code ?

You are also nesting functions - not allowed in C++
You also have mismatched curly braces.

You should have posted the entire compiler error messages verbatim, if you read the instructions
for posting.

When I compile that I get:

sketch_jul24a.ino: In function 'void setup()':
sketch_jul24a:6: error: a function-definition is not allowed here before '{' token
sketch_jul24a:13: error: a function-definition is not allowed here before '{' token
sketch_jul24a.ino:3:5: warning: unused variable 'LED' [-Wunused-variable]
sketch_jul24a:26: error: expected '}' at end of input
a function-definition is not allowed here before '{' token

Learn to understand these messages - but be aware that sometimes an error can lead to a cascade of messages and its sometimes tricky to figure out the genuine issue.

"Learn to understand these messages - but be aware that sometimes an error can lead to a cascade of messages and its sometimes tricky to figure out the genuine issue."

And that is why we compile/verify after writing 3-4 lines of code. When no errors, continue with coding.

Paul

Perhaps your sound sensor or LED is not wired correctly. Perhaps the threshold on the sound sensor is set too high or too low. Perhaps the sound is detected only briefly. Adding a delay to stretch the pulses may help:

const int soundSensor = 2;
const int LED = 3;

void setup() 
{
  pinMode (soundSensor, INPUT);
  pinMode (LED, OUTPUT);
}

void loop()
{
  int statusSensor = digitalRead(soundSensor);
  
  if (statusSensor == 1)
  {
    digitalWrite(LED, HIGH);
    delay(100);
  }
  else
  {
    digitalWrite(LED, LOW);
    delay(100);
  }
}

Note: The body of that loop() is equivalent to:

void loop()
{
  digitalWrite(LED, digitalRead(soundSensor));
  delay(100);
}