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.