Using Ardunio can you use multiple LED's with same terminals?

I am new to Ardunio. I have created some circuits on the breadboard and am now ready to start on my layout. I plan on going from the Ardunio to a terminal strip or strips and then to the projects. Using the example below

Example: Two seperate building away from each other. Same brightness and same on and off rate. Another words same circuit.

My question is this.

  1. Once I build the first circuit on the terminal strips can I add the second LED for the other building to the same terminal posts after the resistor and the other side to the ground post?

If this works how many LED’s can I use?

because the LED current varies significantly with voltage, two LEDs in parallel may not be the same intensity even if the resistor is halved. LEDs would draw equal current if wired in series.

there are inexpensive 10/20 ma regulator designed specifically for LEDs. depending on the supply voltage, one or more LEDs can be wired in series, such as for one structure.

an arduino can drive an external transistor, pulling an LED circuit to ground to turn on/off LEDs wired in series with a regulator possibly powered by 12V which is higher that the arduino supply voltage.

The Arduino is a slick device but you must limit each output to a Max of 40ma!!!

I make an expansion modules for voltages higher than 5 volts and currents higher than 40ma to drive my goodies.

There are blank expansion boards available for the Arduino UNOs and MEGAs on eBay.

I make expansion boards for the NANO.

I keep the Arduino outputs to under 30 ma to be on the safe side.

The best driver chips (7 channel/output) I’ve found are the ULN2003 (inverting) and TD62304 (non inverting), they will sink 500 ma up to 50 volts per output.

For single circuit drivers I use a Darlington Transistor, MPSA13, it will sink 500ma up to 30 volts.

Mel

My Model Railroad
http://melvineperry.blogspot.com/

Bakersfield, California

I’m beginning to realize that aging is not for wimps.

The limit of the microcontroller used in the Arduino Uno/Nano is 40ma per pin, with a total maximum of 200ma for the entire chip - so you can;t just load each pin up to 40ma.

The small SMD LEDs are plenty bright with 5ma or less, so you could potentially put 2 or 4 in parallel. They may not light equally bright, but if they are different structures not next to one another, this might not matter. Series is best, but with white LEDs, you’d be lucky to get 2 in series to work with a 5 volt supply. If you really want to drive a lot of LEDs with one Arduino, look to specific LED driver boards or examples of a simple circuit as Greg says. That way, the LED supply can be a higher voltage, allowing more LEDs in series, the limit there being the sum of the voltages of each LED versus the supply voltage fo the circuit - those LED strips typically link 3 LEDs in series with a single resistor and run on 12 volts. 4 LEDs would be too much for 12V. Each group of 3 LEDs is wired in parallel with each of the other groups of 3 LEDs to make the tape. This takes several amps for a full reel.

–Randy

I just finished working on two different projects on the breadboard connected to the Ardunio. Both projects work fine. When I download one the other goes off.

How do I fix this?

Harold

the arduino can only run one program (“project”) at a time.

sounds like you need to combine the two projects.

send me a PM with a copy of both projects and I can help

Sorry greg. What is a PM?

The project are two simple ones

  1. A blinking yellow traffic light in town

  2. A flickering Blue and White LED going in the farmhouse to simulate a TV Set.

What good are all the outputs on the Ardunio if it will only operate one at a time?

Harold

personal message.

click my picture and click “start conversation” under “Add as Friend” to the right of my picture on my profile page

reminder to some of you to check your messages

a single program can control all the outputs.

OK I understand now. So for the beginers like me. You have to combine all project into one script. I plan on about 10 projects so it is going to become one big script. And yes I will watch the MA for the total.

Thanks

Stay Safe

Harold

The Arduino will not multitask easily if at all using delay.

https://melvineperry.blogspot.com/2019/01/january-16-2019-arduino-multasking.html

https://www.youtube.com/watch?v=Myz6oiG2Vyk

Mel

My Model Railroad
http://melvineperry.blogspot.com/

Bakersfield, California

I’m beginning to realize that aging is not for wimps.

There’s actually a library that makes that easy - called Metro (for metronome I suppose, not the game or as a reference to the area around a city). That easily lets you run multiple things each with their own intervals. I use it in my turnout controller so it can monitor the local buttons, the remote inputs, and move the servos all at the same time.

The repository for it will tell you that it’s old and point you to a replacement, which has more parameters (which for most of these purposes just makes it more complicated) so I’ve stuck with the Metro library.

Once the library is installed, in addition to your pin definitions and other setup, you declare a Metro object with the desired delay (this comes BEFORE the Setup() function):

Metro hbMetro(750)

That creates a Metro object called hbMetro with a trigger time of 750ms

In your main Loop(), you just encapsulate everything in an If conditional:

if (hbMetro.check() == 1) {

(stuff you want to happen every 750ms)

}

For example, in my servo controller, I use this to blink a heartbeat LED so I know the program is running. The full code is:

if (hbMetro.check() == 1) { // Heartbeat LED

if (hbstate == HIGH) hbstate = LOW;

else hbstate = HIGH;

digitalWrite(HBLED, hbstate);

}

Every 750ms, it simply turns the LED on if it was off, or turns it off if it was on.

The obvious (or maybe not so obvious) thing is that the code inside the if block cannot take longer than the time interval to actually execute or the timing will be messed up. Arduino and ATMega328 micros do not do preemptive multitasking like say Windows does - if one block takes a long time to execute, any following blocks with different intervals will not happen on time.

Note there is no delay() used - that’s because what’s inside the if only r

    static unsigned long msecLst = 0;
           unsigned long msec    = millis();

#define Period  200
    if (msec - msecLst > Period)  {
        msecLst = msec;

        digitalWrite (pin, ! digitalRead (pin));
    }

Please see if you can give me the code for something simple. I had a project for a TV with Blue & White LED’s lights blinking fast. (FLICKERING)

void loop() { // Yellow Blicking Traffic Light

digitalWrite(yellowLED,HIGH);

delay(500);

digitalWrite(yellowLED,LOW);

delay(500);

digitalWrite(blueLED,HIGH);// TV

delay(20);

digitalWrite(blueLED,LOW);

digitalWrite(whiteLED,HIGH);

delay(20);

digitalWrite(whiteLED,LOW);

The TV portion started out as a stand alone project. With the code above the blinking was FLICKERING and looked good. Because I found out yesterday from you guys that Ardunio only can run the one program you download at a time. I combined the TV project with the YELLOW BLINKING TRAFFIC LIGHT.

The TV project is Blinking at a much slower rate. I have reduced the Delay rate but still can not get it back to flicker. I assume this is because the Blinking light traffic light is now at work. I intend to add more projects such as lights in different rooms at the farm house. I have a feeling this is going to make the situation worse. I really am not yet at the stage where I understand Greg’s code. Is there any simple tutorials on this type of code.(BASIC). I don’t want to just start copying code with no idea of what I am dong or why.

Thanks in Advance. Stay SAFE

Harold

I am tempted to tell you to model the ACTUAL sort of television flicker – which is ‘modulated’ by the program, much brighter during the ads – perhaps by reading some analog source like a video or audio signal and driving amplitude of the LEDs proportionally – like those screen saver ‘visualizers’ Apple provided. (Don’t forget that in this age of sound decoders, TV watchers have a soundtrack, too, that you could probably crib from YouTube nostalgia videos…)

I think gregc ought to walk you through his code (not just as if fully commenting it but explaining his syntax conventions and internal algorithmic logic) as none of this code is particularly intuitive even to people familiar with older ‘consumer’ programming approaches.

use millis() to capture the number of milliseconds since the start of the program. perform some action when it exceeds some timestamp and reset the timestamp to the current value of milliseconds

have separate functions for your two separate activities, each using msec independently.

each function simply toggle an LED, if on turn it off, if off, turn it on (! digitalRead (pin))

change the led pins to what you are using. i picked values from my hardware

#define yellowLed  10
#define blueLed    11
#define whiteLed   12

unsigned long msec;

// -----------------------------------------------------------------------------
void
setup (void)
{
    pinMode (yellowLed, OUTPUT);
    pinMode (blueLed, OUTPUT);
    pinMode (whiteLed, OUTPUT);

    digitalWrite (blueLed,  HIGH);
    digitalWrite (whiteLed, LOW);
}

// -----------------------------------------------------------------------------
void
tv (void)
{
    static unsigned long msecLst = 0;

#define TvPeriod  20
    if (msec - msecLst > TvPeriod)  {
        msecLst = msec;

        digitalWrite (blueLed,  ! digitalRead (blueLed));
        digitalWrite (whiteLed, ! digitalRead (whiteLed));
    }
}

// -----------------------------------------------------------------------------
void
trafficLight (void)
{
    static unsigned long msecLst = 0;

#define TlPeriod  500
    if (msec - msecLst > TlPeriod)  {
        msecLst = msec;

        digitalWrite (yellowLed, ! digitalRead (yellowLed));
    }
}

// -----------------------------------------------------------------------------
void
loop (void)
{
    msec    = millis();

    trafficLight ();
    tv ();
}

please message (“start conversation”) me with questions

Search for Geoff Bunza Harrys TV shop - slightly more modern COLOR TV simulation using those little OLED displays you cna get for Arduinos. There’s an article on how to go about building it as well as a YouTube video of it working - pretty neat, but too new for my layout.

Geoff’s B&W TV flicker randomizes the delay around a range so it looks more like the variation between a program and the commercials and so forth. It’s a bit of a dig to get the code, and it can’t be linked here because it requires linking a competing magazine’s web site. But a little searching will get you pointed to the right place. I was pretty sure I had the file with the sample code in it, but I can’t find it, or I’d paste the bit that controls the randomizing of the delay.

–Randy

My era is still black and white TV sets. Thanks Greg ,I took my first tutorial on Millis.

In the tutorials they use the Anolog pins. Is there a reason?

Harold

i don’t believe it matters. post a link to the tutorial

does the code I posted make sense to you?

If they are simply turning the pin on and off - the analog pins work as digital outs just fine. If the circuit needs to use PWM output to simulate a varying voltage, then only certain pins can be used, only some support hardware PWM (it’s not the analog pins - they are the analog pins because they support analog INPUT).

The analog pins can also be used for digital inputs with no problem - like a pushbutton.

–Randy

I use all 20 I/O pins for outputs on the UNO for my random lighting controller. As I use incandescent bulbs that draw well over the Arduino max I built a high current output expansion module using 7 channel driver chips.

The inputs can be used for outputs too.

By using the driver chips I can use a higher voltage to operate the bulbs without dinging the Arduino. I use a DC to DC Buck Converter to reduce 12 volts to 8½ volts. The 12 volt Grain of Wheat bulbs draw between 70ma and 100ma each, I set the bulb voltage to 8½ volts for more realistic 1950s lighting and increased bulb life.

Mel

My Model Railroad
http://melvineperry.blogspot.com/

Bakersfield, California

I’m beginning to realize that aging is not for wimps.