Distributing current evenly between two parallel programmes

Hello,

I have a problem and was wondering if anyone could please help me.

I am trying to blink two LEDs simultaneously at different rates, each LED with its own parallel circuit and programme (I have included the code which I used down below). The only thing is that when I upload the programme nearly all the current goes to the the first LED (Pin 9), whereas almost none goes to the other LED (Pin 8).

Does anyone know of a way that I can distribute the current evenly to each pin?

Any help would be very much appreciated.

Thanks

Tim

Here is the code that I am using:

const int ledPin = 9;
const int led = 8;

int ledState = LOW;
int ledstate = LOW;
long previousMillis = 0;
long previousmillis = 0;
long interVal = 1000;
long interval = 2000;

void setup() {
pinMode(ledPin, OUTPUT);
}

void loop() {
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;

digitalWrite(ledPin, ledState);

}

unsigned long currentmillis = millis();
if(currentmillis - previousmillis > interVal) {
previousmillis = currentmillis;
if (ledstate == LOW)
ledstate = HIGH;
else
ledstate = LOW;

digitalWrite(led, ledstate);

}
}

The LEDs draw whatever current they need, you don't really have any control over that. Why do you think you need to balance the current?

Try using a pin other than 13 - it has a led on it already on the board.

You say you have connect first LED to pin 9, but in your program you have define pin 13,

your second LED on pin 8, you have not define pin 8 as output.

const int ledPin = 13;
const int led = 8;

void setup() {
pinMode(ledPin, OUTPUT);
}

Sorry, I made a mistake with typing the code out onto this forum. It was supposed to say led pin 9 instead of 13. All the current seems to go to the first pin, even though both leds are on parallel circuits and have the same resistor.

I made a mistake with typing the code out onto this forum.

How can you make a mistake with cut and paste?

Do you have a schematic?

Hi, hope we can help.

All the current seems to go to the first pin,

How do you deduce this?

even though both leds are on parallel circuits and have the same resistor.

Does this mean you have two LEDs each connected to an arduino output, but both using the same current limit resistor?

Give each LED its own separate resistor.
Also are the LEDs the same, that is same colour, specification?

Tom....... :slight_smile:

I have attached a schematic highlighting the way I have wired up the circuit. I am trying to get equal amounts of current going to each LED, therefore they will hopefully both light up with equal brightness.

thanks for all the replies so far

Tim

Schematic - LEDs.tif (14.8 KB)

Have you set both pins to be outputs?

Thanks, that completely fixed it. I cant believe I missed that, sorry, kinda new to this.

Do you know of any way that I can run this programme but have two 'sequences' of LEDs running simultaneously? Almost like two 'for' loops running simultaneously.

Thanks again.

Tim

The standard answer to your question is to look at the blink without delay example. Unusually, this does not apply in your case - you're already using millis rather than delays to do your timing. Just replicate what you have for your second sequence but use different variables to keep track of when you last did stuff on the new sequence.

you need one copy of each of the variables such as " previousmillis" per led. !!!

Mark

Would this be the only way? I want to have 60 LEDs controlled by one programme, and 12 on another, with both running in parallel.

Tim

You only have one program running on the Aduino at any time! The code you showed is not two programs it one.

You also need to set both pins as outputs not just one!.

Take a look at arrays and structs.

Mark