Pages: 1 [2]   Go Down
Author Topic: using PIR Sensor to fading LED  (Read 1703 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

when the PIR throws HIGH the LED strobes.  When the PIR throws LOW it fades while strobing repeatedly
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
when the PIR throws HIGH the LED strobes.  When the PIR throws LOW it fades while strobing repeatedly
Not sure what you mean by "strobes". If the fading is not smooth, there is a problem with your LED or how it is wired.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I messed with my hardware a bit and It was my LED going bad... Now the LED stays solid when the PIR throws HIGH and fades (as it should) but now it cycles through the fade when the PIR throws LOW
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 549
Posts: 46107
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Now the LED stays solid when the PIR throws HIGH and fades (as it should) but now it cycles through the fade when the PIR throws LOW
Have you changed the code so that firstLEDvalue has different values when the PIR throws HIGH and when it throws LOW? If not, then the behavior you are seeing is expected.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the help so far but I still haven't found a solution to this...
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 238
Posts: 24371
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sketch?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I finally figured it out!  smiley-lol

Code:
const int firstLED = 3;      // pin for the LED
const int inputPin = 2;      // input pin for the PIR sensor
int PIRstate;               // variable to hold the last PIR state
int val;                    // variable for reading the pin status

void setup() {

  pinMode(inputPin, INPUT);              //declare PIR as input
  PIRstate = digitalRead(inputPin);      //assign PIR state to PIRstate
}

void loop() {

  val = digitalRead(inputPin);      // read input value
  if (val != PIRstate)                      // check if the input has changed
  {
    if(val == HIGH){ 
      analogWrite(firstLED, 255);
    }
    else{

      for(int fadeValue = 255 ; fadeValue >= 0; fadeValue -=5) {
        // sets the value (range from 0 to 255):
        analogWrite(firstLED, fadeValue);         
        // wait for 30 milliseconds to see the dimming effect   
        delay(30);                           
      }
    }
  }
  PIRstate = val;                 // save the new state to the variable
}




Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

This post was super helpful.. however the only problem I am encountering (which im assuming is going to be a 'duh' moment when someone responds) but how do i set up my PIR? I am using an UNO... i had the 5v lead of PIR in 5v of arduino, ground in GND and the 'OUT' lead of PIR in digital pin 2... but I get nothing at all?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Don't forget the resistor. http://bildr.org/blog/wp-content/uploads/2011/06/PIR-Arduino_hookup.png
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

haha YES!!! thank you! life saver!!!!
Logged

Pages: 1 [2]   Go Up
Jump to: