Would you like to react to this message? Create an account in a few clicks or log in to continue.

You are not connected. Please login or register

DigitalRead threshold high and low

2 posters

Go down  Message [Page 1 of 1]

1DigitalRead threshold high and low Empty DigitalRead threshold high and low Sat Oct 29, 2022 4:24 pm

FlameOnion



It prints 1 in serial if voltage is above 2.5V and 0 if voltage is under 2.5v.I tried with a pot and it the same(middle to pin, sides to gnd and 3.3v)
I expected, when going from high to low, to stay high until a lower voltage(1-1.5v)because I wanted to see what is that lower threshold and then switch to low.


Code:
/*
  DigitalReadSerial

  Reads a digital input on pin 2, prints the result to the Serial Monitor

  This example code is in the public domain.

  https://www.arduino.cc/en/Tutorial/BuiltInExamples/DigitalReadSerial
*/

// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
  // make the pushbutton's pin an input:
  pinMode(pushButton, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input pin:
  int buttonState = digitalRead(pushButton);
  // print out the state of the button:
  Serial.println(buttonState);
  delay(1);  // delay in between reads for stability
}
(serial console is hidden on the right side
DigitalRead threshold high and low 110
DigitalRead threshold high and low 210

2DigitalRead threshold high and low Empty Re: DigitalRead threshold high and low Sat Oct 29, 2022 5:21 pm

arcachofo

arcachofo

Hi.
I expected, when going from high to low, to stay high until a lower voltage(1-1.5v)
Yes, the input threshold voltages are "simplified" to 2.5 v for all MCUs.
It is planned to set more accurate voltages.

But in this case Low to High threshold is around 2.6 v and Hi to Low around 2.1 v (as per the datasheet).

Back to top  Message [Page 1 of 1]

Permissions in this forum:
You cannot reply to topics in this forum