5v relay on a nano. Why isn't it switching

Hi,

I have a relay (RSB-5-S) and I am using the digital output 6 from my nano and it wont switch . I don't know why. Here is a circuit diagram:

Here is an overview of the code:

#define OUTPUT_RELAY 6

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(OUTPUT_RELAY , OUTPUT);  
  digitalWrite(13, LOW);
  digitalWrite(OUTPUT_RELAY , LOW);  
  Serial.println("begin");
}

void loop()
{
    digitalWrite(13, HIGH); //tap on
    digitalWrite(OUTPUT_RELAY , HIGH); //relay on
}

I have put a voltmeter across the relay and I get 3.85v when it is powered by a USB and then I get 4.05v when poweered of a 9v battery. I am guessing that I need to up the power to the nano but wondered if there is anything obvious I have done or could do

Here is the datasheet if you would like to see it https://www.jameco.com/Jameco/Products/ProdDS/139977.pdf

I have tried the 12v circuit with the always on part of the relay and it does work

Nominal current for that relay is 80mA. How much can you draw from one pin on a Nano? The Uno is 40mA MAX.

You should be using a transistor to drive the relay.

the relay you chose has an operating current of 80mA which is far more than a digital pin can supply.
There are very small relays operating at 25mA that can be used directly on a digital output but usually you need a transistor to operate the relay

Right just read up a bit about transistors. Would you use a transistor or use a lower current relay? I what the circuit to use as little current as possible so not sure how the transistor would affect this?

http://www.pighixxx.com/else/

Here is what I will do now. Is this correct?

Close but not quite. Try this link:

http://pighixxx.com/PNG/156.png

So I need the diode in parallel with the relay. I thought the diode in series would be better or should I put the diode in series before the relay to prevent and current going the wrong way which I think can happen with a relay when it powers down?

The diode does go in parallel with the relay, but the negative end towards positive. This is to deal with the brief burst of energy created when the relay is turned off. Not having it risks damaging the transistor.

Ahh I think I got it now so:

Well I have an understanding of transistors and now am stumped about which one to get. I am using the Arduino nano so that is the starting point and it is very easy to get to maplins so was going to get the transistor from there.

From what I worked out to get the 80mA I need for the relay I should use this one: BC635 the data sheet http://www.micropik.com/PDF/bc635.pdf

I believe this one will not give me enough gain 2N3904 the data sheet Intelligent Power and Sensing Technologies | onsemi

To be honest with you I am not entirely sure what I am looking at on the datasheets about the gain to voltage. Help on this would be great

Your drawing is still wrong. The right hand connection to the relay wants to go to +5v.

A general purpose transistor for playing around with is the 2N2222 which at a glance Maplin don't seem to stock, so you might want to consider eBay? I would suggest Rapid Online, but you need to assemble a fair sized order to get free delivery!

Failing that, the 2N3904 looks fine for the job. Minimum gain of 100 (from the Maplin site) so for 80mA you'll be drawing .8mA from the Nano pin. 200mA max, 40 volts, all within spec.

The relay is going to positive?

Looks like it's going to the base of the transistor to me?

The only voltage I have is coming from D6 which is the 5v. I hadn't intended to provide a second power source which is what I think you are getting at.

Should I then use an additional power source D7 and put 5v to the collector? Or are you saying put the right hand connection of the relay before the resistor to D6?

Wishwashy, use the schematic dannable already posted.

I am sorry but I just don't get it.

I have a single power source of 5v and that is going to the base and the container. The emmiter goes to ground.

What is "Out" on the diagram that dannable posted meant to be I assume the 5v?!

I really appreciate this help but I just am not getting it

"OUT" on dannable's schematic is the Arduino pin you're digitalWrite()ing to.

So D6 is is High and goes to the base. Check
The emmiter goes to ground. Check
The container goes to the relay then in parallel with the relay is the LED. Check
So where does the right hand side of my relay go to? I assume back to D6 as I have only one source of power?! <- This is the bit I think I a struggling with. Why is this not correct? Should I put another 5v from D5 through the right hand side of the relay?

+5VDC will go to one relay coil terminal and to the diode.

The other relay coil terminal will go to the diode and to the transistor collector.

When the Arduino pin goes HIGH, the transistor will allow current to flow from the collector to the emitter. The transistor acts like a light switch, channeling current flow through the relay coil into ground when current is applied to the base.