I'm creating a circuit using an Arduino Nano + ESP8266 to allow LED remote (via mobile app) activation and configuration (RGB colour, timeout, etc.). The circuit also has an optional PIR sensor to switch on the LED when someone enters the room.

I'd like the circuit to behave differently when the PIR is physically connected to the Arduino (i.e. to light the LED in a different colour) but I have no idea of how detect if the sensor is physically connected to the circuit.

I tried reading the value of the Arduino PIN but (obviously) the signal is LOW whether nothing is detected by the PIR or is not physically connected.

I have two different PIR detectors that I can use for the project:

  1. Arduino Compatible PIR Motion Detector (Description)
  2. DFRobot PIR Detector (Description, Schematic)

Thank you for your time. If there is missing information in my question, please tell me and I will add it.

  • Which PIR sensor are you planning to use please?
    – Mark Smith
    Dec 9, 2016 at 22:54
  • Hi @MarkSmith, I've edited the post to include the information about the sensors. Thank you!
    – Luis U.
    Dec 9, 2016 at 23:14
  • Will the PIR always be connected at power-up?
    – sa_leinad
    Dec 10, 2016 at 4:30
  • Yes @sa_leinad, you can assume that the PIR will be connected at power_up.
    – Luis U.
    Dec 10, 2016 at 5:13

1 Answer 1


The PIR sensor I have will overpower the internal pull-up resistor of the ATmega328P used on the Arduino Nano. This means if you turn on the pull-up and then get a read of LOW you know something is connected to that pin because the unconnected pin will always read HIGH with the pull-up on. With this approach you can get false negatives because the pin will also read HIGH if the PIR is triggered but you won't ever get false positives for PIR sensor detection. This means you can't rely on just doing a single test in setup() because the PIR might be triggered then so you will need to repeatedly run the test until the PIR sensor is detected. Example sketch:

int PIRpin = 2;    //the input pin for the PIR sensor
boolean PIRconnected = false;

void setup() {
  pinMode(PIRpin, INPUT);

void loop() {
  if (PIRconnected == false) {
    pinMode(PIRpin, INPUT_PULLUP);
    if (digitalRead(PIRpin) == LOW) {
      Serial.println(F("PIR sensor detected"));
      PIRconnected = true;
    pinMode(PIRpin, INPUT);  //turn off the internal pull-up to reduce power consumption

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.