alebossi96:
Using analogRead I saw that Arduino read value from 300 to 800 .
I thought that Arduino is unable to count some measurement because it does not reach a threshold for a digital 1.
MarkT did a great job of covering the core of your issue [far better than I could have--my strengths are more in the Digital/Firmware arena), but he missed the question I quoted, above...so here goes:
First, I'm going to assume you mean Arduino Uno, when you say "Arduino".
So, it sounds like you're confusing the characteristics of Digital Inputs, with those of Analog Inputs.
An Analog Input, feeds a 10-bit ADC. As such the resulting values range from 0-1023, for an input voltage range of 0.00 to "+5V" ["+5V", in this case, is a substitute for whatever the actual "VCC" voltage is -- something between 4.95V and 5.10V]. Assuming the Uno's Regulator is holding the "+5V" rail at exactly 5.00V, a conversion value of 300, would be induced by the following input voltage:
[b](300/1023)*5.00 = [u]1.47 Volts[/u][/b]
and 800:
[b](800/1023)*5.00 = [u]3.91 Volts[/u][/b]
An input configured as Digital, has the following thresholds, where a "1" or a "0" is guaranteed:
"0" same as VIL: [b]0.3 * V[/b][sub][b]CC[/b][/sub] or [b]0.3 * 5.00 = [/b][u][b]1.5V[/b][/u]
"
</sub>[/u] [u]<sub>1</sub>[/u] [u]<sub>
" same as VIH: [b]0.7 * V[/b][sub][b]CC[/b][/sub] or [b]0.7 * 5.00 = [u]3[/u][/b][u][b].5V[/b][/u]
Plus there's, at minimum, 50mV of Hysteresis, so lets have a look at that [hopefully I get this right :o ]:
Any input voltage below 1.5V + hysteresis, is guaranteed to be interpreted as a "0" or "LOW". And, an input voltage above 3.5V + hysteresis is guaranteed to be interpreted as a "1" or "HIGH". Any voltage inbetween those two values, might be interpreted as a "0" or might be interpreted as a "1". It will be one, or the other, and, because this is a Schmitt Trigger input, that nebulous area between 1.45V and 3.55V will behave like this: if it was a "0" before, it won't become a "1" until the input voltage rises above the upper threshold + hysteresis [3.55V]. And, if it was a "1" before, it won't become a "0" until the input voltage falls below the lower threshold + hysteresis [1.45V] -- and, remember, we're assuming the regulator is holding "+5V" at 5.00V, so the 3.55V and 1.45V levels are only valid for 5.00V.
In terms of the lower of your two Analog "reads", 300 results in 1.47V, which is not below the 1.45V threshold, so it will stay a "0" if it was a "0", and will stay a "1" if it was a "1".
BUT, remember, we assumed perfect regulation at 5.00V. If it's regulating at more than 50mV above the nominal 5.00V, then 1.47V would be a solid "0" -- e.g: 5.10V * 0.3 - 0.05V = a lower threshold of 1.48V, thus 1.47V becomes a solid "0".
Then, in the case of your 800 read, that's a voltage of 3.91V, which is well above the upper threshold, even if we consider hysteresis AND even if the "+5V" voltage is 5.10V, so that's a solid "1".
So, I'm guessing the regulator, on your UNO, is running a little high -- which is fine, as long as it isn't above 5.10V. If it is, then it's out-of-spec!