Author Topic: Arduino I/O Pin and Relay  (Read 2278 times)

0 Members and 1 Guest are viewing this topic.

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Arduino I/O Pin and Relay
« on: March 06, 2012, 12:37:20 PM »
I'm trying to use an I/O pin on the arduino to switch a 5V relay. When I connect the control circuit to the arduino ground and 5V pins, the relay switches fine. However when I try to use one of the I/O pins pulled high to replace the 5V pin, the relay doesn't switch. (The pin is being pulled high for sure).

Any ideas?


This is the relay: http://www.fujitsu.com/downloads/MICRO/fcai/relays/fbr211.pdf
« Last Edit: March 06, 2012, 12:49:49 PM by spizzak »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Arduino I/O Pin and Relay
« Reply #1 on: March 06, 2012, 01:02:22 PM »
Hi,

I'm trying to use an I/O pin on the arduino to switch a 5V relay. When I connect the control circuit to the arduino ground and 5V pins, the relay switches fine. However when I try to use one of the I/O pins pulled high to replace the 5V pin, the relay doesn't switch. (The pin is being pulled high for sure).

Any ideas?
Your relay needs 89mA (according to the datasheet) and you cannot drive it directly from an I/O, if that's what you're trying.
You need a transistor a couple of resistors (and a diode to dampen the kick back), as a driver to go in between.

Do you need a drawing for this?
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #2 on: March 06, 2012, 01:56:28 PM »
Yeah I just found this out. A diagram would certainly be helpful if you have one handy.

I'm guessing the transistor would just go between the arduino I/O and the relay input?

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #3 on: March 06, 2012, 02:48:10 PM »
It just occurred to me that I'm using the relay to power an LED array circuit. It might make more sense to just switch the LEDs with the transistor instead of the relay. Here's my current circuit:

http://i905.photobucket.com/albums/ac260/danbujak/20120306390.jpg

And I have one of these at my disposal if that can be used in place of the transistor:

http://search.digikey.com/scripts/DkSearch/dksus.dll?x=0&y=0&lang=en&site=ca&KeyWords=160-1304-5-nd


« Last Edit: March 06, 2012, 02:53:47 PM by spizzak »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Arduino I/O Pin and Relay
« Reply #4 on: March 06, 2012, 04:50:51 PM »
Hi,

It just occurred to me that I'm using the relay to power an LED array circuit. It might make more sense to just switch the LEDs with the transistor instead of the relay. Here's my current circuit:
White LED's?
A chain of two white LED's will be around 7.2V at full power, so what happens when the battery is not fully charged... If you need to be certain of full power at all times, you need some voltage head-room.

What current do the LED's draw?

Each LED (or string of LED's) should have its own resistor (or other form of current limiting). Your drawing shows them in parallel, which is a bad idea.

If you post the LED data, I'll draw you a transistor only (sans relay) solution that works at all times.


And I have one of these at my disposal if that can be used in place of the transistor:
It cannot unfortunately, but do save it for something else (like if you eg. need to interface mains voltage).
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #5 on: March 06, 2012, 05:07:27 PM »
The LEDs are white indeed but they are rated at at 3.4 V @ 20mA. My battery is about 7.5V fully charged and should be able to maintain that for quite a while.

As for the resistors I did 7.4V - (2 x 3.4V) = 0.6V  then 0.6V/0.02A = 30 ohms.

So I put 3 x 100R in parallel to give 33 ohms and then that is in series with each of the LED pairs.

The LEDs are something similar to this:

http://www.ebay.ca/itm/200-pcs-3mm-Round-white-Superbright-LED-Light-20000MCD-/120643670473?pt=LH_DefaultDomain_0&hash=item1c16ec51c9

and the battery being used is this:

http://www.horizonhobby.com/products/6-cell-7-2v-1800mah-nicd-battery-VNR1530

The battery is also powering the arduino and a BeagleBoard through a power distribution board I built.

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Arduino I/O Pin and Relay
« Reply #6 on: March 06, 2012, 07:03:27 PM »
Hi,

The LEDs are white indeed but they are rated at at 3.4 V @ 20mA. My battery is about 7.5V fully charged and should be able to maintain that for quite a while.
OK. Unless you measured the voltage yourself or read it in a datasheet on the specific LED you  have, I wouldn't trust it too much.

I have attached a circuit that will give your LEDs full power, over the entire range of discharge voltage. It might be a bit more than you bargained for, but this is the only way (short of a switching regulator) to ensure full power at all times.

If you think it's too much, just use strings of one LED plus one 180 Ohm resistor. Parallel 6 of those and switch them all with a transistor like BC337. But this will vary the intensity of the LEDs as the voltage falls.


As for the resistors I did 7.4V - (2 x 3.4V) = 0.6V  then 0.6V/0.02A = 30 ohms.

So I put 3 x 100R in parallel to give 33 ohms and then that is in series with each of the LED pairs.
Using 33 Ohm resistors would be easier :)

Your battery won't be 7.4V for long though.
It will start at around 8.4V to 8.7V and can be considered flat at somewhere between 5.4V and 6.6V depending on the current drain (the larger the current drain, the lower EOD-voltage).
This would mean that the LED current (assuming the 3.4V LED drop) would start at 58mA and going to 0mA a good bit before the battery is discharged.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #7 on: March 06, 2012, 08:17:29 PM »
Thanks for the diagram Soeren, but my problem is that I'm very limited for space on my board right now so I'm trying to do this with as few components as possible. Variations in brightness of the LEDs isn't a big issue and they wont be on for very long at a time. It's more of an additional feature and will most likely only be used to demo.

Considering this, I have tried to make some changes to the circuit you provided. Would this be a reasonable setup?



Not sure what value to use for R3... If the LEDs can handle a fully charged battery maybe I can omit it entirely. Also, is there a reason for putting a resistor on each of the parallel LED circuits instead of putting one in series with them all?
« Last Edit: March 06, 2012, 08:19:41 PM by spizzak »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Arduino I/O Pin and Relay
« Reply #8 on: March 06, 2012, 10:04:48 PM »
Hi,

Not sure what value to use for R3... If the LEDs can handle a fully charged battery maybe I can omit it entirely. Also, is there a reason for putting a resistor on each of the parallel LED circuits instead of putting one in series with them all?
LED's must have a resistor as a current limiter and you need more voltage for even a crude "regulation", hence only one LED per series string and each string needs to have it's own resistor, or a few of the LEDs will soon hog the major part of the current (due to small imbalances in voltage drop, even if they all come from the same production batch).

LEDs can tolerate more than the 20mA, but with reduced life time - up to around 30mA should be fine for your purpose and you will still have grown from the 'bot long before the LED's are down to half intensity.

Small bicycle lamps are run at a much higher current, but they don't need 50,000 or 100,000 hours of life, so who cares, they still outlive their batteries numerous times and most people just buy new ones when they go flat.

I have attached the minimal circuit you can get away with without being violent towards the LEDs (from ~34mA down to ~16mA when the battery reaches 6.0V) and if you're short of PCB space, you could wire it all up in a "birds nest" and add a blob of RTV silicone with the 3 connection wires sticking out, to make it an "external" unit.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #9 on: March 06, 2012, 10:11:37 PM »
Great, thanks! Just 1 question:

Do I connect the battery's ground to the arduino's? (Or what does the 0V on the schematic represent?)
« Last Edit: March 06, 2012, 10:14:41 PM by spizzak »

Offline Soeren

  • Supreme Robot
  • *****
  • Posts: 4,672
  • Helpful? 227
  • Mind Reading: 0.0
Re: Arduino I/O Pin and Relay
« Reply #10 on: March 06, 2012, 11:29:34 PM »
Hi,

Great, thanks! Just 1 question:

Do I connect the battery's ground to the arduino's? (Or what does the 0V on the schematic represent?)
You're welcome :)
And yes, the 0V of the circuit connects to the 0V of the Arduinos ("Ground") otherwise it won't work.

The 0V is the reference when you say something like "I have +5V at this or that point".
Same thing when you probe with a voltmeter, where you need the black lead on 0V to measure the +5V. Imagine that you put the black lead on +2V or -4V (thus reading 3V or 9V) or just didn't connect it.
Without the proper reference, you get improper results.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?
Please remember...
Engineering is based on numbers - not adjectives

Offline spizzakTopic starter

  • Full Member
  • ***
  • Posts: 102
  • Helpful? 1
Re: Arduino I/O Pin and Relay
« Reply #11 on: March 06, 2012, 11:45:30 PM »
Yeah I understand that, I just wasn't sure if the arduino and the battery should share a common ground. Although I guess they do anyway since the battery is being used to power the arduino as well.