question regarding PIR sensor and Arduino nano

I have wired a PIR sensor to control a LED light. When plugging in the circuit, the LED lights automatically and the PIR sensor does not control it at all. The PIR sensor model is: hc-sr501. The code I was using goes as follows,

const int ledPin= 13;
const int inputPin= 2;

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);
}

void loop(){
int value= digitalRead(inputPin);

if (value == HIGH)
{
digitalWrite(ledPin, HIGH);
delay(60000);
digitalWrite(ledPin, LOW);
}
else
{
digitalWrite(ledPin, LOW);
}
}

Here is my sensor: 1pcs High Quality HC SR501 HCSR501 Adjust Infrared PIR Motion Sensor Detector Module for Arduino |motion sensor detector module|infrared pirpir motion sensor - AliExpress

Here is where I am basing the code and wiring off of: How to Build a Motion Sensor Light Circuit with an Arduino

Read the new comments on that site.
Leo..

Sorry, I am confused to what you mean, I looked at the comments and I still can't find anything helpful, any help would be appreciated :slight_smile:

""No external resistor is necessary to limit current to the LED, because pin 13 already has built-in resistance to limit current flow."
Not true. Pin13 of an Uno R3 is just like any other pin. You could damage the Arduino by not using a current limiting resistor."

This comment basically sais that you always have to use a current limiting resistor with a LED, even on pin13.
Otherwise you run the risk of blowing that Arduino pin.

"The article forgot to mention that the PIR sensor pictured already has a build-in timer, that could be factory-set to several minutes.
If you want the Arduino to be in control of timing, and not the PIR, then you must first set the timer of the PIR to minimum.
This can be done by turning the 'time' control pot on the PIR fully anticlockwise."

This comment explains that you have to turn the 'time' pot fully anticlockwise (and leave it there) if you want the Arduino to be in control.
The default setting (in the middle) is a ~3minute 'on' time of the PIR itself.

Note that the PIR (and your code) will re-trigger on the slightest movement in a radius of 7meters.
That includes moving air with a temp difference (hot radiator, open window).
Leo..

Thank you very much! We have added a resistor since we started but have noticed no difference. In regards to turning the factory default time to minimum, we have been playing around with that and still experiencing no difference. I appreciate the advise though, have a nice day :slight_smile:

rydog:
In regards to turning the factory default time to minimum, we have been playing around with that and still experiencing no difference.

You shouldn't be playing with that pot.
As said, turn it fully anticlockwise and leave it there.
That sets the PIR itself to the minimum 'on' time, so the Arduino can be in control if the timing.
Leave the 'sensitivity' pot in the middle. It does not adjust sensitivity/range.

Your code should work, although "delay(60000);" is "beginner's code".
The Arduino does nothing (freezes) for 60 minutes seconds.
Better to manage long delay times like this with millis().
Look at the "BlinkWithoutDelay" sketch in the examples of the IDE.

Try changing the Arduino delay from 60000 to 5000.
So you won't have to wait that so during testing.
Leo..

Wawa:
Your code should work, although "delay(60000);" is "beginner's code".
The Arduino does nothing (freezes) for 60 minutes.

That would be 1 minute.
Still, bad enough.

Also: you can learn a lot about what your sketch is doing by printing stuff to the Serial monitor, such as when you detect a trigger on the PIR.

Duhh, meant seconds.
Leo..