PIR setup working w/ Uno but not Nano V3

Hello,

Beginner warning!
Just got a few Nano boards (not official) and I can’t get a simple PIR + LED setup to work.
It works just fine with my Uno board.
At first I thought I soldered something wrong on the Nano board but same thing with a second one. Tried changing pins, and 2 other PIR sensors.

Setup (pic below):

  • PIR power supplied with 5v breadboard supply hooked to 9V battery. Output pin on D2 on Nano
  • LED on D5 and GND on nano

The PIR and LED just go crazy switching on and off like alternating a detection/stop cycle.
You can see this on the pic of the serial monitor.

EDIT1: added pictures as images, no need to click on attached files.

EDIT2: tried with a third Nano board without pins just by sticking the wires in, same problem. I wondered if my soldering skills could be the problem but it seems they are not that bad :-X

  /*
     * PIR sensor tester
     */
     
    int ledPin = 5;                // choose the pin for the LED
    int inputPin = 2;               // choose the input pin (for PIR sensor)
    int pirState = LOW;             // we start, assuming no motion detected
    int val = 0;                    // variable for reading the pin status
     
    void setup() {
      pinMode(ledPin, OUTPUT);      // declare LED as output
      pinMode(inputPin, INPUT);     // declare sensor as input
     
      Serial.begin(9600);
    }
     
    void loop(){
      val = digitalRead(inputPin);  // read input value
      if (val == HIGH) {            // check if the input is HIGH
        digitalWrite(ledPin, HIGH);  // turn 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;
        }
      }
    }

Connecting the grounds might help.

The Arduino GND and the PIR GND must be connected for the Arduino to make sense of the PIR signal.

Spot on ! Thanks a lot.
As soon as I read this I was pretty sure that was it because I remembered reading something about it while preparing another project but I'd love an explanation on why this is.

The reason is because voltage is electric potential with respect to another electric potential. In other words, the Arduino uses GND as a reference electric potential to make sense of the signal coming from the PIR sensor. The PIR is giving the Arduino either 5 or 0 volts with respect to ground. If the two grounds are not connected, the reference voltage is different. This means there is an electric potential between the two grounds in question (the Arduino's and the PIR sensor'). This will cause the input to float sporadically, even if the PIR sensor is "sending" a constant 5V.

BLUF: Voltage is always measured with respect to a reference voltage (usually ground). Therefore, your Arduino and PIR sensor need the same reference voltage to make sense of each other's signals.

Got it, makes sens now. No wonder it didn't work right.

Thank you very much for your help !!