user1499: I am running into a problem on a very basic functionality.
I want to read the state of an LED.
I have confirmed that under the specified circumstances, the LED receives 1.9V.
I try to read its state with this code:
#define LED_1  5

void setup()
{
pinMode(LED_1, INPUT);
}

void loop()
{
 int led_state = 0;
 if ( digitalRead(LED_1) ) led_state = 1;
 Serial.println("LED State is: ");
 Serial.println(led_state);
}

However, most of the time, the led_state is 0. Sometimes, it goes to 1, but then quickly goes back to 0.
Is it because the voltage is low?
EDIT: I am hooking power directly to one pin of the LED, and the other pin goes to GND (from the same DC power supply).
Also, the power pin from the LED enters inside Arduino Digital Pin 5.

user23841: For the CMOS logic the treshold is usually 1/2 Vcc, therefore you might get lucky with arduino 3.3V Arduinos, but it's still in undefined area. That usual threshold can also change with operating temperature (like 5V WS2812 stopped working in the winter if you were using 3V3 mcu as a driver)
So what are the possible solutions?

route it to the Ax pin and use analogRead + condition (basically software comparator)

if the previous is too slow, you can use AC module on the mega328p (Analog Comparator), but you'll most likely have to dig into the datasheet and use specific pin or pins (compare it against internal 1V1 reference or external one set by potentiometer)

external OpAmp/Comparator (this one can be used with the original pin, note comparator needs pullup, opamp doesn't)

NPN transistor (1k or bigger between base and Anode of the LED, internal pullup or external one between Vcc and Collector, Emmiter to the ground)



user7508: A digital input on the Arduino Uno is guaranteed to read LOW if the
input voltage is less than 1.5 V. It is guaranteed to read HIGH
if that voltage is above 3.0 V. For any voltage in between, you
have no guarantees.
That being said, the datasheet of the microcontroller shows some
“typical” characteristics. According to those, the input should switch
to HIGH when the input voltage goes above 2.6 V, and switch to
LOW when it goes below 2.1 V. There is an hysteretic range in
between.
Note, however, that there is no guarantee that your input will behave
like in the typical characteristics. The only guarantees are for
voltages below 1.5 V and above 3.0 V.

1499: <p>I am running into a problem on a very basic functionality.</p>
<p>I want to read the state of an LED.
I have confirmed that under the specified circumstances, the LED receives 1.9V.</p>
<p>I try to read its state with this code:</p>
<pre><code>#define LED_1  5

void setup()
{
pinMode(LED_1, INPUT);
}

void loop()
{
 int led_state = 0;
 if ( digitalRead(LED_1) ) led_state = 1;
 Serial.println(&quot;LED State is: &quot;);
 Serial.println(led_state);
}
</code></pre>
<p>However, most of the time, the <code>led_state</code> is <code>0</code>. Sometimes, it goes to <code>1</code>, but then quickly goes back to <code>0</code>.</p>
<p>Is it because the voltage is low?</p>
<p>EDIT: I am hooking power directly to one pin of the LED, and the other pin goes to GND (from the same DC power supply).
Also, the power pin from the LED enters inside Arduino Digital Pin 5.</p>
 23841: <p>For the CMOS logic the treshold is usually 1/2 Vcc, therefore you might get lucky with arduino 3.3V Arduinos, but it's still in undefined area. That usual threshold can also change with operating temperature (like 5V WS2812 stopped working in the winter if you were using 3V3 mcu as a driver)</p>
<p>So what are the possible solutions?</p>
<ol>
<li><p>route it to the Ax pin and use analogRead + condition (basically software comparator)</p>
</li>
<li><p>if the previous is too slow, you can use AC module on the mega328p (Analog Comparator), but you'll most likely have to dig into the datasheet and use specific pin or pins (compare it against internal 1V1 reference or external one set by potentiometer)</p>
</li>
<li><p>external OpAmp/Comparator (this one can be used with the original pin, note comparator needs pullup, opamp doesn't)</p>
</li>
<li><p>NPN transistor (1k or bigger between base and Anode of the LED, internal pullup or external one between Vcc and Collector, Emmiter to the ground)</p>
</li>
</ol>
 7508: <p>A digital input on the Arduino Uno is guaranteed to read <code>LOW</code> if the
input voltage is less than 1.5 V. It is guaranteed to read <code>HIGH</code>
if that voltage is above 3.0 V. For any voltage in between, you
have no guarantees.</p>
<p>That being said, the datasheet of the microcontroller shows some
“typical” characteristics. According to those, the input should switch
to <code>HIGH</code> when the input voltage goes above 2.6 V, and switch to
<code>LOW</code> when it goes below 2.1 V. There is an hysteretic range in
between.</p>
<p>Note, however, that there is no guarantee that your input will behave
like in the typical characteristics. The only guarantees are for
voltages below 1.5 V and above 3.0 V.</p>
