Go Down

Topic: Randoming led through ULN2003 (Read 1 time) previous topic - next topic

Goofer

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

CrossRoads

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.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

PaulRB

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.

Goofer

#3
May 10, 2017, 09:08 pm Last Edit: May 10, 2017, 09:27 pm by Goofer
Hi Crossroad,

Here is the schematic diagram.  Please review and advise.

Thanks

Goofer

Goofer

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);
  }

Grumpy_Mike

Code: [Select]
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.

PaulRB

@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?

Goofer

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,

Goofer

Hi Mike,

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


Thanks

Wawa

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..

PaulRB

as you know I am a newbie and first time using the post.
@Goofer, please post your code as described in the "please read" post.

Grumpy_Mike

Quote
Can you please explain more in details, as I am a bit slow in coding.
https://www.arduino.cc/en/Reference/pinMode


Code: [Select]

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

Goofer

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


Goofer

Hi Mike,

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


Regards


Go Up