
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.

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.

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.
/*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 }
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 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 }
Links
https://km4nmp.com/2019/05/25/connecting-the-uln2003-to-the-arduino-mega/
https://blog.adafruit.com/2012/02/03/part-finder-friday-darlington-transistor-arrays/
Latest Post
1 thought on “ULN2003 and Arduino Programing and Testing”