Simple Arduino Sketch to verify PIR:
/
/ Infrared HC-SR501 Proximity Sensor
/
int ledPin = 13; // LED pin for the LED
int inputPin = 2; // input pin
int pirState = LOW; //
int val = 0; // pin status
void setup() {
pinMode(ledPin, OUTPUT); // declare output
pinMode(inputPin, INPUT); // declare input
Serial.begin(9600);
}
void loop(){
val = digitalRead(inputPin); // read input
if (val == HIGH) { // input HIGH
digitalWrite(ledPin, HIGH); // LED ON
if (pirState == LOW) {
// we have just turned on
Serial.println("Motion Detected!!");
// We only want to print on the output change, not state
pirState = HIGH;
}
} else {
digitalWrite(ledPin, LOW); // turn LED OFF
if (pirState == HIGH){
// we have just turned of
Serial.println("Motion ended!");
// We only want to print on the output change, not state
pirState = LOW;
}
}
}
and after say like 10 minutes or so the led strip dims low in brightness say like 30% then then say 2 or 3 minutes after that it shuts off the led strip can someone please help me I'm putting this in my hallway soon..
yeah well i didn't make the sketch up there is a output pin to goes to the arduino digital pin and a vcc and a ground pin. all I'm trying to do is get it to come up slowly in PWM and when it's fully up stay on for 10 minutes and go back down in brightly slowly into it gets to 30% in brightness and then shut off or if someone keeps moving or doing something within that 10 minutes it still remains fully o into they leave. i just don't know how to do that. This is what i need help on.
there is a output pin to goes to the arduino digital pin and a vcc and a ground pin.
So, connect the Vcc pin to 5V (or 3.3.V), connect Gnd to Gnd, and connect the output pin to a digital pin. Then, digitalRead() that pin to determine if the PIR sensor is seeing motion.
Only when you can reliably detect motion would you add code to ramp up, stay up, and ramp down. Put all that code in a function called motionDetected() that you call when there is motion detected.
i don't know have code to make it fade up and stay on for a long time like about 10 minutes. and then fade it back down to low light level. never made one of them before.
The value in someTime will be 1/255 of the total time you want to take to fade up to full brightness.
and stay on for a long time like about 10 minutes.
delay(600000UL);
and then fade it back down to low light level.
for(int i=155; i>100; i--) // Fade to dim
{
analogWrite(somePin, i);
delay(someTime);
}
delay(180000UL); // Hold for 3 minutes
digitalWrite(somePin, LOW); // Then turn off