I want to say the following about Input pin voltage threshold and hysteris:
Quote:Am I going to get yelled at? Well of course, but is this substantially correct?
Looking at the ATmega328 data sheet we see that for the I/O pin to read 1 when the Vcc is 5 volts the input voltage level should be about 2.6 volts. For the pin to indicate 0 with a Vcc of 5 volts then the input voltage should be less than about 2.1 volts. So at 5 volts we have a hysteresis of about 0.5 volts. At 3.3 volts these values would be about 1.6 volts for a 1, about 1.25 for a 0, with about 0.35 volts hysteresis. Why do I keep saying "˜about'? That is so you won't memorize these figures and think you know how to generate a 1 or 0 on an input pin. Ask yourself: when have you ever gotten exactly 5 or 3.3 volts for Vcc? What if you are using batteries and you've got 3.2 volts one day and 2.7 a month later? What I'm saying is that you need to consider these thresholds and hysteresis values as ballpark for your application and make sure you've got some extra voltage if you want to be sure you've got a 1 and that you take it down lower than the indicated low to assure that you are getting a 0. So to be safe lets say that for a 5 volt system you should assure an input of greater than 3 volts to get a 1 and less than 2 volts to assure a 0. If you are on a battery then try to estimate the minimum voltage you are likely to have that will keep the system running, lets say 1.8 volts so for that you'd want greater than 1 volt for a 1 and less than 0.5 for a 0. When in doubt, refer to the pin threshold and hysteresis charts in the datasheet.