How to specify a voltage in input pin.

#include <Servo.h>

Servo myservo;

void setup() {
  pinMode(A0, INPUT);
  pinMode(12, OUTPUT);
  myservo.attach(9);
}

void loop() {
  if (digitalRead(A0) == HIGH) {
    myservo.write(90);
    
  }
  if (digitalRead(A0) == LOW ) {
    myservo.write(0);
    
  }
}

So I was working on project (box with two wires coming out of it. one wire is 5V and other is ground. So when 4.5 or more voltage is detected I won’t to gape open with servo but it seems to caught up noise voltage from somewhere) s my servo opens and closes randomly) How could I specify voltage that is not HIGH. Thank you in forward.

See how you get on specifying A0’s pinMode as “INPUT_PULLUP”

Thank you very much that saved me.