Pages: [1]   Go Down
Author Topic: Perhaps a really silly question  (Read 283 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi I have found this code in another thread, 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?

thanks... smiley

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);

      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   
  PIRstate = val;                 // save the new state to the variable


Offline Offline
Edison Member
Karma: 58
Posts: 2078
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Some PIR sensor have a open collector output. You would need a pull-up resistor.
Some PIR sensor are for 12V.
Some PIR sensor have an output signal of only 2V.

Manchester (England England)
Offline Offline
Brattain Member
Karma: 631
Posts: 34473
Solder is electric glue
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

but I get nothing at all?
There is no such thing in electronics there is always something. Here you will have a logic zero or one. Which is it? Write a sketch to find out, a simple one that say just transfers what it reads on pin 2 to the output pin 13 to light up the LED.
What voltage do you measure on pin 2? You can't do electronics without any measuring equipment.

Pages: [1]   Go Up
Jump to: