How to test if an led exists.

My apologies if this is in the wrong section.

I have a simple circuit. An arduino pro mini. 8, 10 or 16 LEDs and their resistors connected to the pro mini. One per pin. And an ldr to check light level to initiate the led sequence.

My question is: Is it possible for the arduino to test which pins are connected to an led and which aren't?

In other words. If I have a single program on all of the arduinos and the arduino self configures itself for an 8 10 or 16 led sequence. Just means I don't have to change the program for each led configuration.

BTW. I can't use the ldr mentioned above as it's out of sight of the LEDs.

I don't want to add additional by hardware.

Thanks.

Jason.

You can use one analog input and different voltage dividers to get the info on what you plugged in, assuming you have some circuit board that you plug in and not individual LEDs.

Hello Jason

I'm new to arduino but I have worked with Atmel processors in the past. The solution I always used was to configure the output pins as inputs first, there is nothing in the documentation limiting this action to the setup loop and should work. With the pin as input; read the value of the pin, here you will have to experiment with your setup to determine if the pin will be pulled high or low.

After you have read the value you can reconfigure the pin to become an output to drive the LED's.

I hope this helps.

If the pin controlling it is an ADC pin, just set the pin input_pullup, then analogRead the value, if it's not close to 1024, there's something on the pin.

But you can only do that on pins with an ADC....

the LED's are 'additional hardware'

you have additional hardware of an 8 LED set you have additional hardware of 2 more LED's to make 10 or you have additional hardware of 8 more LED's to make 16.

if the choices are strictly and only 8, 10 or 16,

once you realize that your premise is to have additional hardware, you just have to add one more part. tie pin 9 of the 8 LED set to a cap tie pin 11 of the 10 LED set to a cap tie pin 17 of the 16 LED set to a cap.

maybe IntrCol might be able to tell you how to have a pin go to output, then to input and test if there is a cap attached. this way the base hardware you have installed will be detectable.

otherwise, just tell us your professor has given you an assignment to figure out how to get the guys on the Arduino forum to figure out how to test a pin to see if there is an LED attached.

Hi, Can the LDR see the LEDs?

If so, then drive each output in turn to turn an LED ON, if there is one connected to the output then it will be seen by the LDR. One pass of sequencing the outputs and you will know which pins are connected to LEDs.

Tom.... :)

one resistor to one analog pin, 500 ohms for 8 leds, 1k for 10, 2 k for 16

since you have to connect the LED's one more wire would be simple.

Thanks.

An update..

The idea of the project is a wall display unit. When it gets dark, the LEDs flash in a determined sequence.

The ldr can't see the LEDs, so can't be used to test LEDs 11 and 9.

I don't really want to add extra hardware in the firm of caps. It dents potential profitability. Lol.

Oh. And there is no professor. I'm not asking you to do my homework for me. :)

Using part of the above suggestions though.

What if.. On the 8 led layout I wire pin 9 to ground. On the 10 led layout, pin 11 to ground etc..

So all I do is get my programming to test for a grounded pin. Or, I connect it to vcc and test for it being high.

Guessing it being high is better than it being low. Would it need a resistor as a pull up / down setup?

Jason.

If I understand this right.. Just connecting the pin mentioned above to vcc would be sufficient wouldn't it? No need for a resistor.

Wouldn't even need to connect pin 17. As .. if pin 9 isn't connected to vcc or pin 11 isn't connected. Then there must be 16 LEDs fitted. :)

Jason.

Hi,

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom.... :)

As requested, here is some code that tests if the LED is available and enable the connected LED if present. I used pin 47 with the LED connected to the pin with a 220 ohm resistor. It will work on any pin but it may need some tweaking when using transistors to do the switching.

//Global Vars volatile boolean LEDOn = 0;

void setup() { // Set pin as input pinMode(47,INPUT); //Enable pull up resistor digitalWrite(47,1); //Read pin state LEDOn = digitalRead(47);

pinMode(47,OUTPUT); //Test if pin was pulled down and enable LED if (LEDOn == 0) { digitalWrite(47,HIGH); }

}

void loop() { // put your main code here, to run repeatedly:

}

Tom.

I can. But my circuit is very simple.

Pin 2. 220ohm resistor. Led. Ground. Repeat with pins 3 onwards. :)

IntrCol. Thanks for that. I'll give it a go later this evening.

Jason.

My pleasure, let us know how it turned out.

IntrCol.

Your code worked beautifully. It did exactly what you said it would.

Thank you very much.

Jason.