Randoming led through ULN2003

Hi to all Arduino masters,

I am a newbie to arduino. I managed to random blink 6 leds with the mega 2560, but after adding a Uln2003 driver, only led from pin 13 through the driver light up, but the rest do not.

I tested with the regular high and low sketch it works through the driver, please let me know where I went wrong.

Can any of the masters please guide me how to code it to light up randomly after going through the driver.

Thanks

_2803_with_mega.ino (1.69 KB)

random_numbers.ino (801 Bytes)

The ULN2003A can only drive its outputs low.
To turn on an LED, you need these 3 connections: 5V-LED Anode, LED cathode-resister, resister-ULN2003 output.
Drive the ULN2003 input high, the output goes low, the LED turns on.

CrossRoads:
The ULN2003A can only drive its outputs low.

If that's the problem, why does the led on pin 13 work?

@Goofer, please post your code as described in the "please read" post. Many forum members read on smartphones & tablets and cannot open your attachments. Also please post a schematic. Hand drawn is ok. We can't understand why one led works but the others do not. The schematic may help with that.

Hi Crossroad,

Here is the schematic diagram. Please review and advise.

Thanks

Goofer

Untitled 1.doc (93.5 KB)

Hi Paul,

Schematic in earlier post.

code as below

*/
//initiate LED
const int LED = (8,9,10,11,12,13);

//initiate PUSH_BTN

const int PUSH_BTN = (A0,A1,A2,A3,A4,A5);

// a variable to hold a random number
long randomNumber;

void setup() {
// put your setup code here, to run once:
// start serial communication
Serial.begin(9600);
delay(150);

// send at start messages to the serial monitor
Serial.println("Start a new sequence of random number");

// set LED pins as OUTPUT
pinMode (LED, OUTPUT);

// set PUSH_BTN as INPUT

pinMode (PUSH_BTN, INPUT);

//close setup

}

void loop() {

//assign a random number to our variable
randomNumber = random(8,14);

//print the output to the serial monitor window
Serial.print("The Random Number is = ");
Serial.println(randomNumber);

//turn on a "Random LED"
digitalWrite(randomNumber, HIGH);

//delay to see the LED light up
delay(750);

//turn LED off
digitalWrite(randomNumber, LOW);
}

 pinMode (LED, OUTPUT);

Will only set one LED as an output not the whole list of numbers you put in brackets. The same goes for the inputs as well but you get away with that because inputs are the default state on power up.

@Goofer, why should we help you? We ask you to do things properly to help us help you. But you rudely ignore our request. Why do you insult us this way?

Hi Paul,

Sorry if I have offended you in anyway, as you know I am a newbie and first time using the post.

My apologies to you,

Hi Mike,

Can you please explain more in details, as I am a bit slow in coding.

Thanks

The Fritzing picture shows the "COM" pin connected to ground.
That should light up all the LEDs, independent of what's on the input pins.
The "COM" can be left disconnected for non-inductive loads.
Not sure why there is a 0V pin, and why it's connected to ground.
Leo..

Goofer:
as you know I am a newbie and first time using the post.

PaulRB:
@Goofer, please post your code as described in the "please read" post.

Can you please explain more in details, as I am a bit slow in coding.

https://www.arduino.cc/en/Reference/pinMode

pinMode (8, OUTPUT);
pinMode (9, OUTPUT);
pinMode (10, OUTPUT);
pinMode (11, OUTPUT);
pinMode (12, OUTPUT);
pinMode (13, OUTPUT);

Thanks to everyone who try to help. Will try to fix it.

Hi Mike,

Thanks for the advice. I've got it up and running. Much appreciated.

Regards