// i want the led light up when the PIR sensor is HIGH ( people pass)
// then when PIR sensor is LOW the LED is LOW
int calibrationtime = 30;
int pir=3;
int pirState=LOW ;
int led =4;
void setup()
{
pinMode (pir ,INPUT);// pir sensor
pinMode ( led , OUTPUT);//led
}
void loop (){
if ( ;{
(pir == HIGH );
{digitalWrite (led , HIGH)};
else digitalWrite(led, LOW);
}}
What is all that junk? Have you seen an if statement before?
Edit: you're not even reading the input pin, let's fix that...
if (digitalRead(pir) == HIGH) {
digitalWrite(led, HIGH);
} else {
digitalWrite(led, LOW);
}
haha im sorta new.
i think i fixed it ;but there's an error that states that i cannot have else if there is no previous if
int pir=3;
int pirState=LOW ;
int led =4;
void setup()
{
pinMode (pir ,INPUT);// pir sensor
pinMode ( led , OUTPUT);//led
}
void loop (){
if (digitalRead(pir) == HIGH );
{digitalWrite (led , HIGH);}
else
{digitalWrite(led, LOW);}
}
You're a little too eager with those semicolons. The compiler errors only give you hints, throwing random stuff in there to make the errors go away will not produce working code.
so are you going to help or just state my errors, because the software does that pretty good.
I already pasted the exact code that you needed, which you then edited into a non-working state.
okay thanks got it i didnt notice any changes
the main thing with those else without previous if stuff is that you need to indent the else so i comes after in the heriarchy, and not along side. try it next time , and u wont have to copy code.
thebfs:
the main thing with those else without previous if stuff is that you need to indent the else so i comes after in the heriarchy, and not along side. try it next time , and u wont have to copy code.
Indenting has nothing to do with it. The problem was an extra semicolon where none was needed.