0
\$\begingroup\$

I've got a silly situation. I have an Arduino board (2009). There's just one inbuilt LED but can't do much with it beyond blinking. I have five LEDs (3 yellow, 2 green), breadboards, jumper wires but not resistors. (And there is a total lockdown here) I wish to play with these LEDs but can't risk it putting it directly. I tried using them in series but that did not light them up. I know each LED needs a 330ohm resistor but that I don't have. I even have a 2x 7 segment display too but the same problem.

Any way to use them? Thanks.

Update:

On suggestions, we have got two resistors from a faulty solder gun (blue-grey-orange-gold = 68k) and a (brown-black-brown-gold = 100) and 1 IN4000 diode.

\$\endgroup\$
7
  • \$\begingroup\$ What else do you have that has resistance? Potentiometers? \$\endgroup\$
    – Justme
    Commented Jul 23, 2020 at 13:45
  • 1
    \$\begingroup\$ Use PWM. AVR timer has CTC mode of operation. Using it you can implement PWM in any register/bit. I don't know much about Arduino. But they have libraries for using any feature of AVR. \$\endgroup\$
    – Sadat Rafi
    Commented Jul 23, 2020 at 13:46
  • \$\begingroup\$ Don't have them. \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 13:46
  • 6
    \$\begingroup\$ PWM will still drive too much instantaneous current. Both the MCU and the LED will have their ratings exceeded, so no, do not use PWM. \$\endgroup\$
    – Justme
    Commented Jul 23, 2020 at 13:52
  • 1
    \$\begingroup\$ @SadatRafi RMS values are useful for linear devices. LEDs are inherently non-linear, and will experience large, damaging currents during the on-portion of each PWM cycle, no current during the off-portion, and will not be saved by the fact that the RMS voltage is low enough \$\endgroup\$
    – nanofarad
    Commented Jul 23, 2020 at 14:23

6 Answers 6

4
\$\begingroup\$

Try this as the loop function of your Arduino sketch:

void loop() {
pinMode(2, INPUT_PULLUP); //Pull up is built in to the Atmega chip. 
//It will be at least 20k - very little current will flow through the LED.
// LED should light dimly.
//May need to turn off room lights or cover with hands to see.

delay(1000);  // Wait one second.
pinMode(2, INPUT); //Input mode turns off the pull up.  No current to LED.

delay(1000);  
}

Connect an LED to GPIO 2 (or use another pin and change the code to match) with the LED cathode connected to the Arduino ground.

It may be very dim. The built in pull up will be at least 20k, and may be as high as 200k depending on which processor is built in to your Arduino.

Information on "pinMode".

Information on Arduino pull ups.


The above is a trick, and may not work. I haven't tried it out.

Whether it works or not will depend on how efficient your LEDs are and which processor you use.

Try it out. It cannot hurt your processor or your LED.

Do not change the pin mode to output. That may damage your processor (though probably not.)


This is the same idea that Sadat Rafi had except using the Arduino library functions rather than generic Atmega code.

The same cautions about LED efficiency that I've given here apply to that answer as well.


Pin 13 was a poor choice on my part. It is used for other things on the Arduino.

I've changed the code to use GPIO 2, which shouldn't have any conflict.

Do NOT use GPIO 0, 1, or 13 with this trick.

Those pins are connected to other things on the Arduino board. Those other things could cause damage to the Arduino if there are LEDs attached, and will almost certainly interfere with normal operation of the Arduino.

\$\endgroup\$
6
  • 1
    \$\begingroup\$ It worked! Though when sketch writes the code to the chip, my yellow LED gives two full bright blinks. And then plays the loop in dim blinks. \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 14:48
  • \$\begingroup\$ Changed to GPIO 2. \$\endgroup\$
    – JRE
    Commented Jul 23, 2020 at 14:52
  • \$\begingroup\$ Last question, which all pins support this trick? Can I use all of 2-13? \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 15:14
  • \$\begingroup\$ All except 13. As you've noticed,13 is connected to an LED and is used to signal progress while the code is being flashed into the processor. I shouldn't have used in the example when I first wrote, but it slipped my mind the GPIO 13 is different. \$\endgroup\$
    – JRE
    Commented Jul 23, 2020 at 15:19
  • \$\begingroup\$ Also GPIO 0 and GPIO 1, but most Arduino users avoid those anyway - they are used for programming the Arduino flash. \$\endgroup\$
    – JRE
    Commented Jul 23, 2020 at 15:26
4
\$\begingroup\$
#include<avr/io.h>
#include<util/delay.h>

int main(void)
{
    SFIOR &=~ (0<<PUD);
    PORTC |= 0x01;

    while(1)
    {
    DDRC ^= (1<<0);
    _delay_ms(10);
    }
}  

AVR microcontroller has a built-in 10K resistor with every output pins. Arduino should have libraries related to it. They are called pull up resistors. I checked it using the code I provided. enter image description here
This screenshot is taken from the AVR datasheet. You can see that there is a Resistor inside that can be operated by switching the internal MOSFET.

So, ask in the Arduino forum about the library associated to it.

\$\endgroup\$
5
  • \$\begingroup\$ This might work, but those LEDs had better be efficient. The pull-up equivalent resistance is between 20k to 50k. That doesn't provide very much current, resulting in very dim LED light. \$\endgroup\$
    – glen_geek
    Commented Jul 23, 2020 at 14:27
  • \$\begingroup\$ Since it's Arduino, why don't you use digitalWrite and pinMode? \$\endgroup\$ Commented Jul 23, 2020 at 14:32
  • \$\begingroup\$ I've heard that ATMEGA series has 10k. I searched in the datasheet but didn't find the value. \$\endgroup\$
    – Sadat Rafi
    Commented Jul 23, 2020 at 14:33
  • \$\begingroup\$ digitalWrite() function doesn't use pull up. Arduino is simply a huge collection of libraries. If you need to use pull up then you will need to find the function associated to it. The code I provided will be inside that built-in function. \$\endgroup\$
    – Sadat Rafi
    Commented Jul 23, 2020 at 14:37
  • 1
    \$\begingroup\$ Thanks @SadatRafi the pull up trick worked. \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 15:24
2
\$\begingroup\$

I'm sorry for you, but no, there's no way of connecting LED's to Arduino without resistors, without risk of damages to your Arduino's ports or the whole chip itself.

Even if you try to connect them in series of 2 (2.5V per LED) or 3 LED (1.6 v per LED), it is not advisable.

Don't you have a broken electronic device that you could scavenge for resistors? Even a burnt CFL or LED lamp can have some resistors that you could use. 330 ohm is just a minimum value, but as you want only an initial learning experience with Arduino, LED's values from 330 ohm to even 10k ohm can permit Arduino to light a LED safely.

CFL lamps have diodes, you could connect a series of 4 diodes to make a 2.4/2.6 V reductor, this series of diodes could permit using a lower value resistor (CFL lamps usually has a low value resistor, under 100 ohm).

What are the LED's colours? Their voltage depends on colour.

\$\endgroup\$
6
  • \$\begingroup\$ 3 yellow and 2 green LEDs \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 14:01
  • \$\begingroup\$ This link would change your quarantine's Arduino play in an emergency resistor building task. Once a time I saw a guy online telling about his father, that was from the resistence in WWII, used this method to build resistors for his radio transmitters. \$\endgroup\$
    – mguima
    Commented Jul 23, 2020 at 14:08
  • \$\begingroup\$ A generic yellow LED, a generic green LED, and a single diode from a burn CFL could work, too. \$\endgroup\$
    – mguima
    Commented Jul 23, 2020 at 14:18
  • \$\begingroup\$ Great idea. We have ~6 clamps to use and lot of pencils. \$\endgroup\$
    – thevikas
    Commented Jul 23, 2020 at 14:19
  • \$\begingroup\$ To be honest: the idea seemed better than really is. I've just did some tests here. I connected directly to the graphite leads, and resistance is too low (about 20 ohms). I tried a hatched stripe in paper, I barely lighted a red led using a small distance of only 2mm. \$\endgroup\$
    – mguima
    Commented Jul 23, 2020 at 14:35
0
\$\begingroup\$

If you have higher valued resistors, try those. I've had up to 20K series resistance with a red LED (high luminosity, admittedly) and it was still clearly visible in office/lab lighting. You can go for more intensity later, but this may be sufficiently visible for bench debug. How high you can go on resistance is probably different for each device, and I've tried this with exactly one sample, so YMMV.

\$\endgroup\$
0
\$\begingroup\$

Anything between about 250 ohms and 10K will work fine. Surely you can sacrifice something and pull resistors out of it and maybe extend the leads a bit.

\$\endgroup\$
-4
\$\begingroup\$

In case a 5V VCC if you dont want any resistors you can connect 2 leds of voltage drop of 2.7V in series. One of the LED's wont be completely forward biased and will limit current.

\$\endgroup\$
11
  • \$\begingroup\$ How do you know what voltage drop LEDs the OP has? If they are red LEDs, two of them in series will burn with overcurrent. If they are blue or white, two of them will never even light up. \$\endgroup\$
    – Justme
    Commented Jul 23, 2020 at 13:57
  • 1
    \$\begingroup\$ And if the LEDs were the same type they would have the same voltage drop at the same series current. \$\endgroup\$
    – Transistor
    Commented Jul 23, 2020 at 14:15
  • \$\begingroup\$ One LED will shine and the other wont and we have limited current without resistors. \$\endgroup\$ Commented Jul 23, 2020 at 14:19
  • 2
    \$\begingroup\$ @HelenaWells Sorry, that isn't quite right. If the LEDs are in series, they have the same current and thus the same number of charge carriers crossing the junction, hence both must light up. You're still likely to have very poor current regulation: no light if the voltage drop is too high, and LED damage if it is too low. \$\endgroup\$
    – nanofarad
    Commented Jul 23, 2020 at 14:25
  • 1
    \$\begingroup\$ Connecting LEDs, or diodes in general, directly to a voltage source without a negative current feedback (in ther simplest case: a resistor) is a very bad idea. Diodes have very steep voltage-current-curves and even the slightest increase in voltage can cause a tremendous increase in current and damage the diodes. For the same reason it is not a good idea either to put diodes in parallel. \$\endgroup\$
    – GNA
    Commented Jul 23, 2020 at 18:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.