problem with pause on pir sensor.

anyone can help?
How to give pause on sensor p.i.r?

my problem :
indicator led(led_pir) on pir sensor always blinking.

my script.

//--------------- ldr-------------------
const int pin_ldr = A0; //
const int pin_led = 12; //
int valueLDR;
//--------------- pir-------------------
int led_pir = 13;
const int read_pir = 2;
unsigned long turnoff;

void setup() {
//------------------------------------
//------------------PIR
pinMode(pin_led,OUTPUT);
pinMode(A0,INPUT);
//------------------PIR
//------ [pir]
pinMode(led_pir, OUTPUT);
pinMode(read_pir, INPUT);
//------------------------------------

}
void loop()
{
//------------------------------------------------------------------------

{
valueLDR = analogRead(A0);
if (valueLDR < 150)
digitalWrite(pin_led, HIGH);
else
digitalWrite(pin_led, LOW);
}
//------------------------------------------------------------------------

{

if (digitalRead(read_pir) == HIGH)
{
digitalWrite(led_pir, HIGH);
turnoff = millis() + (15*60000);
}
if (millis() > turnoff) digitalWrite(led_pir, LOW);
}
//------------------------------------------------------------------------
}

ldr_pir.ino (1.63 KB)

How are you powering your Arduino? The Arduino must be resetting and reloading the program, so your power supply is too small.

Paul

I use a 5 volt or 12 volt adapter just the same.
output led always blinking

Without knowing which sensor it's hard to give any sensible comments on this.

Maybe it's normal for your sensor to blink its LED when active?

Avoid pin13 if you can, because the LED could flash during bootup.
Have re-written your sketch (untested), removed several brackets, and moved led_pir from pin13 to pin11.
See if it works as expected.
Leo…

const byte read_pir = 2;
const byte led_pir = 11; // moved to 11
const byte pin_led = 12;
const byte pin_ldr = A0;
unsigned long turnoff;
int valueLDR;


void setup() {
  pinMode(pin_led, OUTPUT);
  pinMode(led_pir, OUTPUT);
}


void loop() {
  valueLDR = analogRead(pin_ldr);
  if (valueLDR < 140) digitalWrite(pin_led, HIGH); // bit of hyteresis
  if (valueLDR > 160) digitalWrite(pin_led, LOW);
  if (digitalRead(read_pir))
  {
    digitalWrite(led_pir, HIGH);
    turnoff = millis() + (15 * 60000);
  }
  if (millis() > turnoff) digitalWrite(led_pir, LOW);
}