As a general rule, you will want the input levels either near 0 volts or the supply voltage to avoid incorrect readings. You will notice that when the supply voltage is low, the range for a 0 or 1 gets very small. With a low Vcc a little noise on an input can cause an improper read. For applications with noisy electrical environments, it is usually best to run the microcontroller near the high end of the allowable Vcc range. On the other hand, running at higher supply voltages will mean more power consumption. Those are the kind of tradeoffs that you will need to make as a circuit designer.
The actual levels and slope of the thresholds indicated by the blue and green lines of Figure 6-1 will depend on the microcontroller in question. They will also change a bit depending on the device temperature. Some special pins such as the reset pin might have different thresholds than regular I/O pins.
Referring again to Figure 5-1, the red line shows the input voltage equal to the supply voltage. You don’t want to subject inputs to voltages above Vcc or you can damage the IC. For that matter, you do not want the input to go below ground (0V). That can cause the internal circuitry in the IC to latch up, and possibly draw excessive current and damage or destroy the IC.
Pull ups and pull downs
Sometimes you want an input to read as a 1 or 0 as a default. Suppose you have a sensor on a cable that plugs into your device. It is possible that the user will disconnect the cable. If the input pin is left floating, it might sometimes read as a 1, sometimes as a 0. Your code might interpret this as changes from a sensor and not act the way you want.
Putting a pull up resistor will set the input voltage near Vcc and it will read as a 1. A pull down resistor will bring the voltage near 0V, and it will read as a zero. Figure 5-2 shows pull up and pull down resistors. The switch, sensor, or other component that generates the normal 1 and 0 voltages must be able to over drive the resistor.
What value resistor should you use for these resistors? There are no hard and fast rules, but there are some guidelines. A resistor with a relatively low resistance is called a strong pull up. That is because it takes a lot of current to pull it down. Alternatively, a high resistance pull up is a weak pull up because it will not take much to pull it down.
If your circuit is in an electrically noisy environment, some of that will get coupled into your circuit. If a weak pull up is used, the noise could be powerful enough to cause a false reading. If you use a strong pull up, the noise risk is reduced, but the circuit driving the input must be able to handle the load, and the system’s over all power consumption will be higher. You have to understand the conditions your circuit will operate in, and make the proper compromises.