Controlling a relay

Hi everyone

Beware, I'm a newbie.

I can't find any tutorials on how to control a simple relay from the Arduino. I've got LED's blinking and input running, but getting control of my 9V relay seems difficult.

Thanks
Carl Emil

as far as I know, ther is no complete tutorial yet, but here is the schematic, which is posted in the Playground:

You can use the same code as you would use for driving an LED. Instead of connecting an LED and to the Arduino, you would connect the resistor and GND, as shown in the diagram.

hi,

this diagram is great, thanks. i think it's shown me that i was trying to do this the wrong way. i was assuming that you could control the relay directly as if it were an LED or something, which seems to sort of work. can anyone tell me what the transistor and rectifier actually do?

Uph! I forgot to return to this thread. Thanks for the diagram, it's all I need =)
Carl Emil

hi,

this diagram is great, thanks. i think it's shown me that i was trying to do this the wrong way. i was assuming that you could control the relay directly as if it were an LED or something, which seems to sort of work. can anyone tell me what the transistor and rectifier actually do?

the Arduino can source about 20 millimaps of current through a pin.. a relay typically takes 100-300ma. So the transistor is there to amplify the signal from the Arduino to the current level required by the relay. Try googling "transistor amplifier theory", or "NPN Switch" if you want to know more.

D

Thanks a lot. That's a huge help. I know it's not your job to explain electronics 101 to me, and I really appreciate it.

hey

no sweat. Try getting a copy of the ARRL Handbook, it has terrific explanations of basic electronic theory.
D

I wish there was a step-by-step picture walkthrough for retards. I can't seem to get this circuit to work... and i'm afraid i'm building it wrong. I've somehow managed to burn out three transistors now, and i can't tell what i'm doing wrong.

I feel retarded, if it's any consolation.

Could you say a bit more about how you're building the circuit? What transistor, what relay, what voltages? I'm just trying to get to the bottom of why it's not working for you, 'cos I'd really like to hear that it's working!

Well, I duplicated someone else's design exactly. I'm a programmer really and this particular project is way out of my territory.
]

This is my relay:

Right now I just want to see if it works in the first place. I think I might have a dead one. I connected the two close pin to ground and 5V. I set an old meter to ohms and it spikes over to 0 when you touch those two terminals, so they are definitely the coil. I small tick can be felt when you connect it to the 5V.

So I assume the circuit is closed on the other side no? Apparently, wrong. the same setting on that meter doesn't spike when touching the other two, ever. Basically, I can't get my relay to close a circuit period. I also tried plugging it up to 3 AA's... wish I had a 9V sitting around.

Grrr, I wish I was 200 miles away at my state college, because I could probably ask anyone there to explain it and have a 50/50 chance of them working it out for me :stuck_out_tongue:

Tomorrow or whenever I find a camera i'll just take a picture of it, it's embarrassingly simple.. so it should work... But I think tomorrow i'll try a new relay too. I didn't think relays ever got stuck open

Well,
This is a simple fault searching method, sorry if it is to basic.
1 Locate the article number on the relay - confirm that it ends with 5V DC

2 Locate the coil terminals on the relay
3 Measure the coil resistance - according to your data sheet shall it be 31ohms +/- 10%
4 connect the power supply to the realy and confirm that it clicks
5 if it does not click - reverse the power supply and try again.
6 Here would I normally give up and get another relay
If you are really serious can you measure the current through the coil. Another option is to increase the realy voltage.

It is very possible that the relay contacts can have been welded together if you got this as a surplus relay. Then should you also get a new one

Magnus

If you want to know about how a transistor works try the first part of this article. After that it gets a bit heavy:-
http://www.thebox.myzen.co.uk/Hardware/Transistor_Tester.html

Then as an encore look at the relay at the end of this:-
http://www.thebox.myzen.co.uk/Tutorial/Power_Supplies.html
it is basically the same as the schematic linked before but there are some words of explanation with it.

I do have a 12v DC relay here that I know is good, but... no 5v. How would I switch it>? How CAN I switch it? I have not been able to get any of these relays to "click"

I have not been able to get any of these relays to "click"

You've tried multiple relays? And none of them will "click"? Hmmm... Makes me wonder if something else is wrong, like trouble with your power source. Or even a dud piece of wire somewhere that's making all your tests fail!

You should be able to take a battery, some wires, and a relay, and get a small but audible "click" when you connect power to the coil. You may see a small spark when you disconnect the battery, too.

Can you describe your setup for us, a little more clearly?

I made this Instructable probalby it solves your probelm:
http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

greetz Daniel

ERROR 404: No such instructable.

We're sorry, the URL http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/ is either incorrect or no longer available.

:frowning:

For me it works maybe give it another try

greetz daniel

Works for me, too.

It wasn't there this afternoon but it is this evening. :-?

I just use a ULN2803A.

Very simple to install and it Isolates the board a little , so you can have 8 relays upto 50v.

My standard I buy in bulk item of the day !!!!