Go Down

Topic: Perhaps a really silly question (Read 721 times) previous topic - next topic


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... :)

Code: [Select]
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


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.


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.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131