I have an Arduino Nano with two attached Motion sensors "PIXNOR HC-SR501". This sensor puts 5V on its middle Pin, when it detects motion. I have connected this Pin to my Arduino and read the value with digitalRead

Here is the simplified code of my loop:

void loop() {
    motion1 = digitalRead(motion_pin1);
    motion2 = digitalRead(motion_pin2);

    if(motion1== HIGH) {
        Serial.println("Motion 1");
    if(motion2== HIGH) {
        Serial.println("Motion 2");

    // Wait 1,0 Second

Problem is... This used to work fine, but I had to extend the cable to the motion sensors from ~10 cm to 500 cm. Now I have the problem, that the Arduino sometimes (quite often) detects voltage on the motion pins, although there is no motion. I guess the Input-pins are is too sensitive? What can I do to prevent this flickering?

1 Answer 1


That device (datasheet) puts out 3.3V on the OUT pin, not 5V:

◦ TTL output: 3.3V, 0V

The excess cable is most likely picking up EMI and creating spurious pulses on the input. There are two basic ways of combating this:

  1. Increase the drive strength (especially the sink capacity) of the output
  2. Implement a balanced line communication system

You can combine both those quite easily, whilst at the same time boosting the output voltage to 5V using a 74HCT04 hex inverter chip (make sure it's the HCT variant). Powered from 5V it will boost the logic level from 3.3V to 5V, and it will have a greater drive strength than the PIR chip alone.

Then the trick is to use multiple gates in the right way to make a crude balanced line system:

enter image description here

Basically you're double-inverting the signal so it remains the same logic level (high = high, low = low) but has higher drive strength, and you're also single-inverting the signal so it has inverted logic (high = low, low = high). You then connect those to two different IO pins on the Arduino. Read both pins (instead of just one) and as long as the signal are opposite (Q = HIGH and !Q == LOW) then you have a valid signal. If both signals are HIGH then you have noise and you can ignore it.

You also need to ensure you select the right kind of cable. Ideally you need a cable with at least one twisted pair in it so that the Q and !Q signals are twined around each other. This ensures that if EMI is induced into the wire it's induced into both signals equally. CAT5 Ethernet cable is often quite a good choice.

  • Thank you for this very detailled information and for pointing out my mistake with the 5V output of the sensor!
    – Michael B
    Mar 7, 2016 at 10:25
  • For implementing a balanced line, the MAX487 transceivers are quite cheap (less than 3 € apiece). You can feed a 3.3 V logic signal to the sending one (VIH(min) = 2.0 V) and you get 5 V on the receiving side. Mar 7, 2016 at 11:51
  • Ouch, that's expensive. 74HCT04 can be purchased for just a few pence each in SMD, or a few tens of pence in DIP.
    – Majenko
    Mar 7, 2016 at 11:53

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.