LED timer?

okay so my code looks a little messy (it is) and i've mixed a lot of things together (im very new to this whole thing) but ive written some notes an i would REALLY aprichiate somebody helping me:) So i have a ifraRed (motion detecter) conected to an led and i was able to make it all run smoothly, but something was wrong with the timing and i've tried a lot of different things and now i have kind of messes up my code:/ suggestions?

infrar_d_2_.ino (3.45 KB)

My suggestion would be to do what I do. Walk away. Come back tomorrow with fresh eyes. And then start over. Not sure what you're attempting to accomplish. But the following is what I believe is a cleaned up version of what you wrote for the void called "bool". I didn't change your flow. just made it compile as it was. And no. This won't do what you want it to do.

void someOtherName(){ //can't name it bool
  if(digitalRead(pirPin) == HIGH) { //I think you meant something like this
    digitalWrite(ledPin, HIGH); //missing semi-colon and extra ( at the beginning
    while(ledPin == HIGH){ //I think you meant something like this
       if(digitalRead(pirPin) == HIGH) {
        digitalWrite(ledPin, HIGH); //missing semi-colon and extra ( at the beginning
        while(ledPin == LOW){ //I think you meant something like this
          if(digitalRead(pirPin) == HIGH) {
            digitalWrite(ledPin, HIGH); //missing semi-colon and extra ( at the beginning
            delay(2);
            if(digitalRead(pirPin) == LOW){      
              digitalWrite(ledPin, LOW);  //the led visualizes the sensors output pin state
              while(ledPin == HIGH){ //I think you meant something like this
                if(digitalRead(pirPin) == LOW) {
                   digitalWrite(ledPin, LOW); //missing semi-colon and extra ( at the beginning
                   while(ledPin == LOW){ //I think you meant something like this
                      if(digitalRead(pirPin) == LOW) {
                        digitalWrite(ledPin, LOW); //missing semi-colon and extra ( at the beginning
                        }
                   }
                }
              } //added a bunch of these to close all the ones above before the next void
            } // now there are a bunch of extras at the bottom of the script
          }
        }
       }
    }
  }
}

Have you tried connecting the motion detector to the Arduino instead of the LED?

yes both of them are connected?

  while (digitalWrite(ledPin, HIGH)

There are several instances of such code, all of them wrong, in the original code

Check the syntax of the while command then check the logic

For instance, what is this supposed to do ?

(digitalWrite(ledPin, HIGH)
                           while (digitalWrite(ledPin, LOW)
                        {

Even if the syntax used was correct. Can you make a decision based on writing to a pin ?

To be honest i cant remember writing something like that(i was probably desperate) but the function i am trying to optain with

while(digitalWrite(ledPin == HIGH)){
if(digitalRead(pirPin) == HIGH);{
digitalWrite(ledPin, HIGH);

is. Even when the current output is high if the sensor is low it switches to low. I know this is supposed to happen without the code i am trying to write and it almost did (very unprecisly) in the beginning, but then i wanted to control the time the led was on and i kept changing thing so it got a little better and a little better at then a lot worse and now it looks like this (attachment bellow)

i am unbeliveably greatful that you are helping me!!!!!(even if you cant)

My questions are: what function is missing fro code i this text?

And how do you control the time for an led?

sketch_mar18b.ino (2.81 KB)

I actually don't know what you are trying to do.

Please describe it as simply as you can

Cross-post.