Pins stay HIGH

Discussion in 'General Programming Discussion' started by ewuehler, Jan 24, 2014.

  1. ewuehler

    ewuehler New Member

    Joined:
    Jan 24, 2014
    Messages:
    2
    Likes Received:
    0
    I am trying to attach a PIR sensor to (pick a digital pin, any pin!) and the pins remain high no matter what I do. I'm sure I'm doing something wrong, but the equivalent sketch on an Arduino Uno works as I expect. Basically, here's what I've skinned it all down to for debugging purposes:

    Code:
    void setup() {
       Serial.begin(9600);
       pinMode(7, INPUT);
       digitalWrite(7, LOW);
    }
    
    void loop() {
       digitalWrite(7, LOW);
       Serial.print("pin 7: "); Serial.println(digitalRead(7));
       delay(1000);
       Serial.print("pin 7: "); Serial.println(digitalRead(7));
       delay(1000);
    }
    
    If I wire pin 7 to ground, it reports "pin 7: 0" as expected; but whether I have my PIR on pin 7 or not, it keeps printing "pin 7: 1". I expect it to be LOW as it is an INPUT pin and not INPUT_PULLUP (at least I think I'm understanding the docs right).

    Arduino Uno, works; Udoo no-workie.

    Differences:
    The Uno sits at my desk, plugs into either Ubuntu or a Mac for loading sketches. The Udoo is in a cabinet (I replaced my unused security system with the Udoo and I'm slowly wiring/replacing all the sensors) that I VNC to and I compile and load the sketch directly. I have 4 door sensors (switches) on it that all work fine (pin HIGH==open, pin LOW==closed).

    I've tried several PIRs, and attaching a multi-meter, the PIRs send high and low (< 1volt low and 3+volts high - they're 6-10m away; but even plugging the PIR directly in the Udoo in the cabinet doesn't work, so I don't think it is that either). I've tried different pins.

    So before I pull the Udoo out of the cabinet and take apart everything I've done so far, I'm hoping it is something simple I'm just overlooking as an Arduino/Udoo noob.
     
  2. mkopack

    mkopack Member

    Joined:
    Jun 14, 2013
    Messages:
    451
    Likes Received:
    21
    Ok, maybe I'm missing something, but you're telling it that you want Pin 7 as an INPUT, so why the heck are you WRITING to it (which means you're trying to use it as an OUTPUT).

    If you're trying to read the pin, and you're seeing it show up as a HIGH when you don't have anything connected to it, then it's floating. This can be resolved using a pull-down resistor to that pin.

    I assume you also are hooking up the PIR's power and ground pins properly?

    Also, you mentioned that you're using an Uno - remember, Uno works on 5V, Udoo on 3.3V... So be careful the sensor you're using isn't pushing 5V to the pin!
     
  3. ewuehler

    ewuehler New Member

    Joined:
    Jan 24, 2014
    Messages:
    2
    Likes Received:
    0
    Yeah - I was scouring the internet and found some code/post that suggested forcing a write to LOW after setting the pin as INPUT might help. What do I know. :) I will go triple check and make sure I'm using the 3.3v out and I've wired it correctly.

    Thanks!
     
  4. mkopack

    mkopack Member

    Joined:
    Jun 14, 2013
    Messages:
    451
    Likes Received:
    21
    And like I said, check the wiring, you might need a pull down resistor in there on the pin along with the PIR output. It's possible that when the PIR isn't pushing out a high, it's not nec pushing a LOW, but rather letting it float. If it's floating then it could be >1V which the Arduino pin might see as a high. The Pull-down resistor will force the value to be 0V if there's isn't an actual +3.3V coming out of the PIR.

    If you have an O-Scope, throw it onto that pin and see what you're really getting when the PIR should be sending out a low...
     

Share This Page