77Views2Replies

Author Options:

arduino coding problem Answered

im working on a project of mine which needs an arduino to easily manipulate the PIR sensor and easily use its outputs via LED light.
this is my current program.

int ledPin = 13;
int pinPir = 2;
int val = 0;
int led2Pin = 12;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(pinPir, INPUT);
  pinMode(led2Pin, OUTPUT);

  Serial.begin(9600);
}

void calcLed(){
  val = digitalRead(pinPir);
  if (val == HIGH){
    digitalWrite(ledPin, HIGH);
    delay(5000);
  }
  else
  {
    digitalWrite(ledPin, LOW);
  }
}

void loop(){
  digitalWrite(led2Pin, HIGH);
  calcLed();
  delay(5000);
  digitalWrite(led2Pin, LOW);
  delay(2000);
}

im having a problem with how the sequence of the program works.
when i test the project . its works fine. but while the program is running . it seems that it wont 
recognize the input of the Pir sensor until the program is done?

how can i intervene ? i want the program to go back to 1st step when the PIR sensor . detects motion.
please help? thankyou :)

Discussions

0
caitlinsdad
caitlinsdad

5 years ago

Did you look into the code samples for the PIR sensor? Tutorials on arduino.cc

I don't know where the gndPin comes into play in your program. The PIR sensor has to be initialized to "warm up" and then monitored for any changes in reading. Good luck.

0
charmaineanne.bahia
charmaineanne.bahia

Reply 5 years ago

i didnt know that the pir needed to "warm up" thankyou . i'll start looking into it.

and the gndpin. is actually the led2pin. i forgot to edit that one. and now i have. thankyou again.