Digital Pin Threshold and Hysteresis


Well, as long as you are using TTL signals to drive the inputs of your Arduino you always can rely on "1"s and "0"s. But what will happen if you connect an NTC or a photodiode to a digital input? And: will all digital inputs act in the same manner?

To check for this we connected all the six inputs of PORT-B plus the analog input A0 to the wiper of a pot (the ends connected to Vcc and GND) and twisted the pot while reading A0 and PINB.

The result was: nearly each time all the pins of PORT-B showed the same value; only in very rare cases one of the pins showed a value different from the others. As the datasheet says the threshold is somewhat above half of the supply voltage.

/*
Connect the Arduino-pins 8 to 13 plus A0 to the wiper 
of a potentiometer and rotate the knob.
Check if all the bits change at the same 
position of the knob.
*/

void setup() {
  Serial.begin(9600);
}

void loop() {
  int a = analogRead(A0);
  byte b = PINB; // read Pin-8 to Pin-13 on one go
  Serial.print(a);
  Serial.print("\t");
  Serial.println(b,BIN);
  delay(100);
}

See also:

ATMEL doc8161.pdf, chapter 29.4.9 or
ATMEL doc8271.pdf, chapter 30.8.9


contact: nji(at)gmx.de