Arduino Relay Module not switching with transistor

My Problem:

I have a relay module that won't switch when I wire it using a transistor. I followed this tutorial to no avail. I also used the circuit found in this stack exchange answer.

If I don't use the transistor the relay works fine, however I have a larger project i'm trying to add the relay to but with an LCD screen and 4x4 keypad attached to it, it seems to stop outputting enough power to switch the relay. I setup this separate circuit just to see how to get the transistor / relay setup to work and I can't get it to...

I'd like to know what I am doing wrong...

My Equipment:
Arduino Uno
3V Relay Module
2N3904 Transistor
1N4001 Diode

My Setup:
See Fritzing Sketch

My Code:

SparkFun Inventor's Kit 
Example sketch 13


  Use a transistor to drive a relay

  A relay is a electrically-controlled mechanical switch.
  It can control much more voltage and current than an Arduino pin
  (or the transistor included in your kit) can. If you want to use
  the Arduino to control a 120V bulb, coffee maker, or other high-
  power device, a relay is an excellent way to do that. Because
  the relay needs more power to switch than an Arduino pin can
  provide, we'll use a transistor to drive the relay in exactly
  the same way we used a transistor to drive a motor in circuit 12.

  A relay consists of a coil of wire, and switch contacts. When
  you apply power to the coil, it becomes magnetized, and pulls
  the switch contacts closed. Since the switch contacts are 
  completely isolated from the Arduino, you can safely use a
  relay to control normally dangerous voltages (but please only do
  this if you already know how to safely work with high voltage!).

  The relay has three contact pins, COM (common), NC (Normally
  Closed), and NO (Normally Open). When the relay is turned off,
  the COM pin is connected to the NC (Normally Closed) pin. When
  the relay is turned on, the COM pin is connected to the NO
  (Normally Open) pin.

  This code is very simple - it turns the relay on for one second,
  and off for one second, the same as the blink sketch!

Hardware connections:


    The transistor has three pins. Looking at the flat side with
    the pins down, the order is COLLECTOR, BASE, EMITTER.

    Connect the BASE pin through a 330 Ohm resistor to digital pin 2.

    Connect the EMITTER pin to GND.

  Relay coil:

    The relay has pins for a coil (which you use to control the
    relay), and contacts (which you connect to the device you'd
    like to switch). The top or bottom of the relay should have
    a symbol indicating the coil pins.

    Connect one side of the coil to the COLLECTOR pin
    on the transistor.

    Connect other side of the coil to 5V.


    The relay has a coil that you energize to close the switch.
    When you disconnect power from a coil, the coil will generate
    a voltage spike that can damage the transistor. This diode
    protects the transistor from the voltage spike.

    Connect the side of the diode with the band (cathode) to 5V

    Connect the other side of the diode (anode) to the COLLECTOR
    pin of the transistor.

  Relay contacts and LEDs:

    We'll use the relay contacts to turn LEDs on and off, but you
    can use them to switch almost anything on and off.

    Connect the COMMON side of the switch to a 330 Ohm resistor.
    Connect the other side of the above resistor to 5V.

    Connect the NC (Normally Closed) side of the switch to the
    positive (longer) leg of LED 1.

    Connect the NO (Normally Open) side of the switch to the
    positive (longer) leg of LED 2.

    Connect the negative sides (shorter leg) of both LEDs to GND.

This sketch was written by SparkFun Electronics,
with lots of help from the Arduino community.
This code is completely free for any use.
Visit for SIK information.
Visit to learn about the Arduino.

Version 2.0 6/2012 MDG

const int relayPin = 2;     // use this pin to drive the transistor
const int timeDelay = 1000; // delay in ms for on and off phases

// You can make timeDelay shorter, but note that relays, being
// mechanical devices, will wear out quickly if you try to drive
// them too fast.

void setup()
  pinMode(relayPin, OUTPUT);  // set pin as an output

void loop()                    
  digitalWrite(relayPin, HIGH);  // turn the relay on

  delay(timeDelay);              // wait for one second

  digitalWrite(relayPin, LOW);   // turn the relay off

  delay(timeDelay);              // wait for one second

Why is there a wire from Vin to the relay? Vin is for an external voltage to be applied to the board.

You also appear to be using 5v via a transistor. The Tr will drop too much voltage across it to allow sufficient voltage to turn on the relay.

Please supply a proper circuit. Hand drawn and photographed will do.


The relay module that you are using already has a transistor and opto-isolator fitted.

There is no need to use an additional transistor with it.

You have connected the transistor in "open collector" configuration. This can only pull the input low, or allow it to float.

Maybe you need to take the input high to turn on the relay?
This is something that your present circuit can't achieve.

I think you will have more success if you remove your transistor and collect the input to the relay module directly to an Arduino output.

Okay, I did not know that this had a transistor built in already.

I wired it the IN port directly to the Digital Pin on the arduino and it switches perfectly. The only reason I attempted to add a transistor is because with original circuit the relay will only switch within the first 10-15 seconds of when the arduino turns on... After that the relay no longer is triggered and I don't know why...

I attached my circuit...

Well thank you John... You pointing out that the transistor was already built in made me double check my code and I had a bug in my code where the digital output wasn't being set to high but for maybe a couple milliseconds so it wasn't triggering the relay.

Ahhhh I think I figured it out now. Thank you both for your insight though! I've been struggling with this issue for several days now... Time for bed.