Interfacing of Relay with Arduino using ULN2003

For interfacing of relay with arduino using ULN2003, we need ULN IC (it can also be done with transistor but ULN is better option) in between arduino & relay because relay can generate back EMF because of its coil and this back EMF can affect our arduino board, so to save our controller or development board side circuitry we will use ULN2003 IC as relay driver.

REQUIRED COMPONENT

S.N. COMPONENT QUANTITY
1. Arduino Uno 1
2. Relay DC 12 V 1
3. ULN2003 IC 1
4. Button (switch) 1
5. Resistor 1K ohm 1
6. Resistor 220 ohm 1
7. LED 2.2 V, 10 mA 1
8. Power Supply 12V, 1A 1
9. Connecting Wires

INTERFACING OF RELAY WITH ARDUINO USING ULN2003

ARDUINO CODE INTERFACING OF RELAY WITH ARDUINO – DC LOAD (5V, 12V, 24V….)

INTERFACING OF RELAY WITH ARDUINO USING ULN2003
ULN with DC LOAD

ARDUINO CODE INTERFACING OF RELAY WITH ARDUINO – AC LOAD (~ 220 V)

We can connect LEDs for low voltage or high voltage appliances like 110/220 V, 60/50 Hz AC appliances using a relay. For connecting, AC appliances see the circuit diagram below and code remains the same.

AC LOAD WITH ARDUINO AND ULN2003
ULN with AC LOAD

As we know ULN IC are Darlington pair IC and have transistors on the chips, we know transistor has 3 terminals namely base, emitter, collector so the inputs are base ranges from 1B to 7B with grounded common emitter to all seven drivers and corresponding collectors as output for each base input. +12V to COM point is for a flyback diode that protects the circuitry from back EMF.

PROGRAMMING CODE

/* don't use keywords for variables that are predefined by the software Arduino IDE
    that’s why we are using ip instead input and op instead output
*/
#define del 20
int ip = 2, op = 13;

int buttonState = 0;
void setup() {
  pinMode(ip, INPUT);             //ip=2
  pinMode(op, OUTPUT);       //op=13
}

void loop() {
  /* reading the state of input either HIGH (button pressed) or LOW (button not pressed)
     if button pressed appliance will ON otherwise not
  */
  buttonState = digitalRead (ip);
  if (buttonState == HIGH) {
    digitalWrite(op, HIGH);
    delay(del);
  }
  else if (buttonState == LOW) {
    digitalWrite(op, LOW);
    delay(del);
  }
}

WORKING FLOW

  1. Initial conditionpin 2 is LOW (input) and pin 13 is LOW (output).
  2. Push the button connected at pin 2 this will give a HIGH signal at pin number 2. This will give output HIGH from pin 13.
  3. Input 1 (1B) of ULN receiving a HIGH signal, as ULN invert logic, you will get LOW at the output (1C ).
  4. Relay’s one terminal is connected at +12 V power (HIGH), and the other is getting LOW from pin 1C. This will energize the relay coil and attract relay lever to normally-open (NO) contact.
  5. This lead to turn ON appliance connected to relay

OUTPUT

When you push the button it gives a HIGH signal, which in turn gives a HIGH signal as OUTPUT from pin 13 to trigger the relay, this will turn ON either DC or AC appliance. And as you release button, appliances will turn OFF.


READ NEXT
INTERFACING OF ALPHANUMERIC 16×2 LCD WITH ARDUINO


5 1 vote
Article Rating
Subscribe
Notify of
guest
1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments
Ron
Ron
2 years ago

I am very interested in using the ULN2003 to drive a relay module called “5-30V 2-Channel 4-Way Relay Module for DC Motor Loads“(see attached image). Note: I will be using a 12 volt power supply to drive both the Arduino board and the purchased 4-way relay module. This device drives two DC motor loads either forward or backwards depending on the status of 4 inputs A1,B1,C1, and D1. (See the attached image once again to understand the input codes for controlling the relay module). Obviously using the ULN2003 to generate the 4 inputs is a good use for this IC… Read more »

Relay Extension Module Signal Driver Selection.jpg
1
0
Would love your thoughts, please comment.x
()
x