Voltage changes but digitalRead always HIGH I developed simple push button project
I used wemos D1 mini
I connected D3 pin to pull down 1K resistor.

I used multimeter to measure D3 pin voltage.

When i push the button, D3 pin voltage changes from 0.x volt to 4.x volt

But digital read on D3 always return HIGH.

Please help me find the problem. Thanks in advance

This in my sketch :

int ledPin = D2; // choose the pin for the LED
int inPin = D3;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {

  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop(){

  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {    
    digitalWrite(ledPin, LOW);  
  } else {
    digitalWrite(ledPin, HIGH);  
  }
}
The problem is that when the button isn't pressed, the voltage at pin D3 is just floating. Since there is nothing attached, the voltage at the pin can be anything. To prevent this, you use a pull-down resistor, so that when the button isn't pressed, the voltage at D3 is pulled to ground, and you will get a LOW using digitalRead.







simulate this circuit &ndash; Schematic created using CircuitLab