How much voltage is needed to register as high on a digital pin?


#1

Hi,

I am working on a tutorial for BluzDK and I would like to know how much voltage is needed to register as high on a digital pin?

I have connected the output pin of my sensor to a digital pin of my BluzDK. My multimeter shows 3.20 to 3.25 V when the sensor goes high, but the digital pin pinMode(sensor, INPUT_PULLDOWN); does not recognize it. It only works when I use the 3v3 V of my Photon instead of the sensor output.

Do you experience the same?
I would be very grateful if you could help me :slight_smile:


#2

According to the nrf51 product spec, the minimum voltage on a pin to register as HIGH is 0.7VDD, so 70% of whatever you measure on the 3V3 pin.

What sensor are you using? Is it possible the sensor is varying output and the multimeter is averaging?


#3

Hi eric,

thanks for your fast reply! I am using this sensor: http://www.seeedstudio.com/depot/PIR-Motion-Sensor-Large-Lens-version-p-1976.html
My multimeter is a cheap one for about 65 $ so I am not sure if it tells me the truth :smiley:


#4

Those are normally pretty simple little sensors.

Can you post your code? Also, how are you powering this sensor?

I just set up a quick little experiment where I used resistors to drop the voltage from VDD by about 15% and then tried to trigger an input with a pulldown. It works just fine.


#5

The Photon is powered via USB
VIN Photon to VIN Bluz
GND Photon to GND Bluz
VCC PIR to 3v3 Bluz
GND PIR to GND Bluz
OUT PIR to D1
and an LED connected to D4 with a resistor

My code is:

int LEDpin = D4;
int pirSensor = D1;

void setup()
{
    pinMode(pirSensor, INPUT_PULLDOWN);
    pinMode(LEDpin, OUTPUT);
}

void loop() 
{
    //this, and only this...
    System.sleep(SLEEP_MODE_CPU);
    
    if (digitalRead(pirSensor) == HIGH) {
        digitalWrite(LEDpin, LOW);
    } else {
        digitalWrite(LEDpin, HIGH);
    }
}

The LED only goes off when I connect D1 to 3v3.


#6

Hmmm… that looks ok.

You said earlier you measures ~3.2V from the PIR. How long does it stay that way when motion is detected?

I don’t have this exact sensor, but the one I do have will stay HIGH for several seconds if motion is detected. If this one does not, and only flips the bit HIGH quickly, it could miss it. With this current code, the loop function would only run every 100mSeconds.

You can try using interrupts: http://docs.bluz.io/reference/interrupts/

So you would setup a function and attach an interrupt to the pin when it rises, falls, or changes. This will ensure you always catch the change and isn’t timing dependent.


#7

You might try using an interrupt, just in case the loop is missing the motion. Down the road it should in theory lower energy consumption as well.

int LEDpin = D4;
int pirSensor = D1;
volatile int state = HIGH;

void setup()
{
    pinMode(pirSensor, INPUT_PULLDOWN);
    pinMode(LEDpin, OUTPUT);
    attachInterrupt(pirSensor, pirCheck, CHANGE);
    digitalWrite(state);
}

void loop() 
{
    //this, and only this...
    System.sleep(SLEEP_MODE_CPU);
}


void pirCheck()
{
    state = !digitalRead(pirSensor);
    digitalWrite(state);
}


#8

Thank you both very much for your help! I have tried the interrupt code but without luck so far. The LED is always on.
My Multimeter measures a maximum of 3.25 V and it stays there for about 1 to 2 seconds when I move my hand in front of the sensor.


#9

Does it work on the Photon?


#10

Yes, I have just tried it with my Photon and it works without any problem.


#11

Maybe instead of INPUT_PULLDOWN, just use INPUT, and use a real pulldown resistor?


#12

One BluzDK is now powered through the battery shield, power LED is on, the Bluz LED is off. After a factory reset it blinks magenta and I can connect it to the app(blinking blue). After that it blinks again magenta so I assume it is in save mode again.
The web ide says it is connected. When I press flash I can see it in the dashboard and the update fails -> safe mode
And now after about 2 hours of try and error it is breathing cyan. I do not know what I am doing wrong? Yesterday I also had constant magenta and sometimes green light.
The Android app (0.9.2) has problems if my phone screen goes off. When I turn on the screen and the BluzDK got disconnected the app crashes.
Android 6.0.1 CM13 on Nexus 4
I was not able to get a logcat of a crash until now.

Both of my BluzDK do not seem to work with the PIR sensor. Would you please be so kind and tell me how to connect the external pull-down resistor (10kOhm?)?

Kind regards


#13

When you perform a factory reset, the device does indeed go to safe mode. Had you already upgraded the DKs from 1.0.47 to 1.1.47? After you did a factory reset, were you building with 1.1.47? When you did a factory reset it would have reverted your base firmware back to 1.0.47, so the subsequent update could have taken more time than expected.

Do you have the logcat when the app crashed? Can you email it to us? I wasn’t even aware that you could run Android 6 on a Nexus 4, I thought that wasn’t supported? Are you running a custom version?

Sounds like the connection issue was resolved at least, so for the sensor, can you try using analogRead and view the results somehow (using Serial1, Particle.publish, etc)? It would be good to see if the DK is picking up the sensor at all. So if you could write out the value read from the pin every half second or so, that should be sufficient. You would have to switch the pin to an A pin to do this, so A0 for example.


#14

Hi Eric,

I am building with 1.1.47.
I was not able to get a logcat from my phone but I will try it again. My Nexus 4 is running a custom rom (Cyanogenmod 13) and it works really reliable. Also my first smartphone, the Galaxy S2 runs Android 6.0.1 because of Cyanogenmod 13 :smiley:
I am now testing your app with a Motorola Moto G (Stock Android 6.0.1) and it works much more reliable. The crash happens always when the screen is of and BluzDK loses its connection and switches to blinking green. When I turn on the screen and press connect the app crashes. As soon as I am able to get a logcat I will email it to you :slight_smile:

As you suggested, I am now using analogRead for the PIR sensor and I get 913 for high and 6 for low. 913 of 1023 seems good so it is really strange why it does not work. Today I have also bought a new PIR sensor (http://www.seeedstudio.com/depot/Grove-PIR-Motion-Sensor-p-802.html ) and it is also not recognized on a digital pin.


#15

Could you perhaps try a different pin? You can do a digitalRead on the A0 pin, does that work?

Also, as previously suggested, what if you change the INPUT_PULLDOWN to simply INPUT and try that?


#16

The following code works on all pins with pinMode(pirSensor, INPUT); :slight_smile:
I have used INPUT_PULLDOWN because the reference said pinMode(button, INPUT_PULLDOWN); // sets pin as input I think I have misinterpreted that.

int LEDpin = D7;
int pirSensor = A0;
volatile int state = HIGH;

void setup()
{   
    pinMode(pirSensor, INPUT);
    pinMode(LEDpin, OUTPUT);
    attachInterrupt(pirSensor, pirCheck, CHANGE);
    digitalWrite(LEDpin, state);
}

void loop() 
{
    //this, and only this...
    System.sleep(SLEEP_MODE_CPU);
}

void pirCheck()
{
    state = !digitalRead(pirSensor);
    digitalWrite(LEDpin, state);
}