ULN2003 and Arduino Programing and Testing

In our last post, we connected th UL2003 darlington pair array to the Arduino Mega. Today we will be going over programing and testing. For those of you that do not have an Arduino Mega, I will be including a programing sketch for the Arduino UNO.

Schematic with relays
Advertisements

Since you cannot see a relay activate, leds have been attached to the ULN2003 outputs. The setup is the same with the exception of the led and resistor.

Arduino Mega

For testing, I have wrote a very simple sketch that turns each led on for 1 second and moves to the next. Copy and paste the code into your editing program. From there you should be able to upload to your Arduino.

Advertisements
/*Arduino Mega ULN2003 Darlington Array Test Sketch
  https://MacarrLabs.com/
  https://KM4NMP.com/
  Author: Matthew Carr, Macarr Labs LLC 5/25/19
  Arduino Mega Sketch
*/

  
void setup() {
  pinMode(52, OUTPUT);    //ULN2003 in 1
  pinMode(50, OUTPUT);    //ULN2003 in 2
  pinMode(48, OUTPUT);    //ULN2003 in 3
  pinMode(46, OUTPUT);    //ULN2003 in 4
  pinMode(44, OUTPUT);    //ULN2003 in 5
  pinMode(42, OUTPUT);    //ULN2003 in 6
  pinMode(40, OUTPUT);    //ULN2003 in 7
 
}

void loop() {
  digitalWrite(52, HIGH); // sets the digital pin 52 on
  delay(1000);            // waits for a second
  digitalWrite(52, LOW);  // sets the digital pin 52 off
  digitalWrite(50, HIGH); // sets the digital pin 50 on
  delay(1000);            // waits for a second
  digitalWrite(50, LOW);  // sets the digital pin 50 off
  digitalWrite(48, HIGH); // sets the digital pin 48 on
  delay(1000);            // waits for a second
  digitalWrite(48, LOW);  // sets the digital pin 48 off
  digitalWrite(46, HIGH); // sets the digital pin 46 on
  delay(1000);            // waits for a second
  digitalWrite(46, LOW);  // sets the digital pin 46 off
  digitalWrite(44, HIGH); // sets the digital pin 44 on
  delay(1000);            // waits for a second
  digitalWrite(44, LOW);  // sets the digital pin 44 off
  digitalWrite(42, HIGH); // sets the digital pin 42 on
  delay(1000);            // waits for a second
  digitalWrite(42, LOW);  // sets the digital pin 42 off
  digitalWrite(40, HIGH); // sets the digital pin 40 on
  delay(1000);            // waits for a second
  digitalWrite(40, LOW);  // sets the digital pin 40 off

}
Advertisements

Just incase you don’t have an Arduino Mega, I decided to do a quick setup for the Arduino Uno. The main change is the pins for the input of the ULN2003.

Arduino UNO
Advertisements
/*Arduino Mega ULN2003 Darlington Array Test Sketch
  https://MacarrLabs.com/
  https://KM4NMP.com/
  Author: Matthew Carr, Macarr Labs LLC 5/25/19
  Arduino UNO Sketch
*/

  
void setup() {
  pinMode(1, OUTPUT);    //ULN2003 in 1
  pinMode(2, OUTPUT);    //ULN2003 in 2
  pinMode(3, OUTPUT);    //ULN2003 in 3
  pinMode(4, OUTPUT);    //ULN2003 in 4
  pinMode(5, OUTPUT);    //ULN2003 in 5
  pinMode(6, OUTPUT);    //ULN2003 in 6
  pinMode(7, OUTPUT);    //ULN2003 in 7
 
}

void loop() {
  digitalWrite(1, HIGH); // sets the digital pin 1 on
  delay(1000);            // waits for a second
  digitalWrite(1, LOW);  // sets the digital pin 1 off
  digitalWrite(2, HIGH); // sets the digital pin 2 on
  delay(1000);            // waits for a second
  digitalWrite(2, LOW);  // sets the digital pin 2 off
  digitalWrite(3, HIGH); // sets the digital pin 3 on
  delay(1000);            // waits for a second
  digitalWrite(3, LOW);  // sets the digital pin 3 off
  digitalWrite(4, HIGH); // sets the digital pin 4 on
  delay(1000);            // waits for a second
  digitalWrite(4, LOW);  // sets the digital pin 4 off
  digitalWrite(5, HIGH); // sets the digital pin 5 on
  delay(1000);            // waits for a second
  digitalWrite(5, LOW);  // sets the digital pin 5 off
  digitalWrite(6, HIGH); // sets the digital pin 6 on
  delay(1000);            // waits for a second
  digitalWrite(6, LOW);  // sets the digital pin 6 off
  digitalWrite(7, HIGH); // sets the digital pin 7 on
  delay(1000);            // waits for a second
  digitalWrite(7, LOW);  // sets the digital pin 7 off

}
Advertisements

Links

https://km4nmp.com/2019/05/25/connecting-the-uln2003-to-the-arduino-mega/

https://www.st.com/resource/en/datasheet/uln2004.pdf

https://blog.adafruit.com/2012/02/03/part-finder-friday-darlington-transistor-arrays/

Latest Post

Advertisements

1 thought on “ULN2003 and Arduino Programing and Testing

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close