Digital pin always reading HIGH?


I’m new to all this, so please be gentle :wink:

How is it that the following code always outputs 1 / HIGH to the serial connection? - This is with no pin connections at all on a Photon.

I get the ssame result regardless of which digital pin I use. I have also tried , in setup() setting the pin to OUTPUT and writing LOW, before switching pinmode to INPUT.

int in=D3;

void setup() {
    Serial.begin(115200); //baud ignored for USB

void loop() {
    int state=digitalRead(in);

With nothing connected, the input is ‘floating’ somewhere between low/high. If you check the docs on I/O, you’ll see the INPUT_PULLDOWN, which should pull it low. Give that a try :smile:

Ahh thankyou :slight_smile: