Simplest way to detect, if LED i manually disconnected

Dear All,

I'm new to Arduino and hope you can help.

My setup is simple:

(Arduino GND) -- resistor -- LED -- manually connecting/disconnecting wire -- (Arduino PIN set to HIGH 5 V)

When I now cut the wire to the LED, will the command digitalRead read LOW? Will this work?

void loop() {
digitalWrite(9, HIGH); // turn LED on
if (digitalRead(9) == LOW) {
// do Thing A
}

Cheers,
Christoph

Post a schematic showing the arrangement of the components and connection to the Arduino.

What Arduino?

Thanks for your answer. I plan to use Arduino Uno. Here is a similar schematic cut_wire

Is there a way to detect, if the LEDs are one without using any other component? Probably not, because the pins to the LEDs can either set to input or output. Not both at the same time.

Think about what you just wrote. The LED was powered and had light. You cut the wire and there is no power to the LED. You can use your program to change the pin from output to input and read the status of that same pin. But what is there to be read? Nothing. Actually is will be undefined because it is now what is referred to as "floating". So the signal could be anything from 0 to 1 or rapidly fluctuating between the two states.
Paul

What’s your necessity of removing GND from the LED string ?

If you want the LEDs OFF, just turn them OFF.

In that scenario, if you remove an LED, the associated pin will be floating so its state is indeterminate.

This page may be of interest.

Thanks, I want the switch to replace by an iron ball. This ball is released manually and starts a stopwatch. Another sensor is detecting falling the ball on a plate and stops the time. It will take about 500 ms.

I don't want to use another pins, because I will need them for further sensors and a display.

If need be, you can use an Arduino i/o pin as both an output and an input pin.

@christoph1706, your topic has been moved to a more suitable location on the forum. Introductory Tutorials is for tutorials that e.g. you write, not for questions. Feel free to write a tutorial once you have solved your problem :wink:

Addressing your original enquiry, can you tell if the LED is disconnected?

Indeed you can, at least for red LEDs (or any) whose threshold voltage is less than 2 V.

You have the LED connected to ground with a resistor to the I/O pin. Set as OUTPUT, if you write it LOW, the LED is off and if you write it HIGH, the LED is on.

To test whether the LED is present, you set the pin to INPUT_PULLUP. This puts a high value resistance between the pin and 5 V. If the LED is connected, it pulls the pin down to the threshold voltage as the series resistor is much smaller than the internal pullup. This is read as a LOW. If the LED is not connected, then the internal pullup pulls the pin HIGH so you know the LED is no longer there.

You can do this test very fast (microseconds) and promptly go back to whatever state you previously defined as an OUTPUT, there will be no noticeable change in the LED brightness either way.

is that what you wanted to know?