Output Signal From Digital Pin to Switch Relay, Suggestions?

Greetings,

I'm using the G5LE PBC Relay. Datasheet here: http://www.kosmodrom.com.ua/pdf/G5LE.pdf

The goal is to turn a Relay on or off using a digital output from the Arduino so it can be done on-demand/dynamically. The relay when on, allows the throughput of a 12v, 1.5A power supply.

Currently, my set up is using Digital Pin 2 (also tried others) to output a signal to the Relay. The output from the Pin 2 when OUTPUT is HIGH is ~4v/~40mA (milliamps).

According to the Relay's datasheet, the relay requires the following volts/amps to switch:

  • 3v@136mA
  • 5v@79mA
  • 6v@67mA
  • 9v@45mA
  • 12v@33mA
  • 24v@17mA
  • 48v@8mA

With the above listed data, I calculate it'd take a minimum of ~100mA+ at the 4v output to perform the switch, so the 40mA I'm receiving from Pin 2 isn't enough. Unfortunately I'm a noob still learning, so I didn't understand this when I purchased the relays.

The confusing thing for me however, is that while the Digital pin isn't capable of switching the relay, the direct 5v pin on the Arduino is. When I measure the "5v" pin, I read 4.1v @ 47mA which is barely more than Digital Pin's output is. If one doesn't work, I'm a bit confused why the other does.

That being said, what is the recommended course of action to provide the appropriate volts/amps to the relay to successfully perform and hold the switch?

  • Buy a different relay requiring lower switching volts/amps, still allowing for 12v, 1.5A throughput? Would anyone be willing to offer some suggestions?
  • Add another relay (solid-sate or otherwise,) which when powering the Digital Pin, allows the throughput of the 5v Pin to power the relay?
  • Possibly swap voltage for amps? According to me calculations, even is volts dropped to 3.3, I'd only end up when 67mA when I'd need 136.
  • Something else I haven't considered?

I'd really like to keep the circuit as simple as possible, however I'll do whatever necessary to bring this project to fruition.

Thanks so much for your time!

Josh

That relay comes in versions with different nominal coil voltages, as in the list you gave. It sounds like you bought the 5V coil version. You need an NPN transistor to drive it. See http://t1.gstatic.com/images?q=tbn:ANd9GcT6fucx3aX-zTgJRxyTKkDyY29jUtv6C2Uis7rRji7xlRvUcSmg4w for a suitable schematic, but where it says +12V use +5v. Suitable components are:

Transistor: BC337 or 2N2222A
Resistor: 1K
Diode: 1N4148

dc42,

Thanks for taking the time to read over and respond to my post.

If I am understanding you correctly:

  • +5V should come from the power source, through the relay coil, and into the NPN Transistor?
  • And when the 4V from the Arduino Pin is passed through the 1k resistor and into the NPN Transistor, that will cause the relay to switch?

Here is a diagram of the circuit I've constructed; if someone notices anything wrong or odd or just straight up not right, let me know. I'm eager to learn and willing to listen:

I'd be more willing to just go for it and see if it works, but burning things out has a tendency of also damaging one's wallet.

The emitter of the transistor should just go to Gnd.
12V Gnd needs to connect to Arduino Gnd.
Get rid of D1, D2.
By Power+ on the '328, is that the 5V Pin? If yes, put a diode from 5V (anode) to Vin (cathode) to avoid reverse driving the regulator.

12V Gnd needs to connect to Arduino Gnd.

What is the reason?

It should be noted that in the above diagram, the GND symbol and "-" side of the Power Sources are redundant. I essentially have two power outputs on a single power supply: a 5V, 1.5A and 12V, 1.5A.

The emitter of the transistor should just go to Gnd.

It essentially does go to GND, with the exception of first passing through D2. I'll remove that as you mentioned, though.

12V Gnd needs to connect to Arduino Gnd.

Wouldn't this potentially burn out the device depending on the amount of electricity that passes through it? Why not connect it directly to the 12V GND? What benefits do I gain through passing it through the Arduino?

Get rid of D1, D2.

Done deal.

By Power+ on the '328, is that the 5V Pin? If yes, put a diode from 5V (anode) to Vin (cathode) to avoid reverse driving the regulator.

The "Power +" on the 328 Arduino refers to the Power Input to drive the Arduino, and the "Power -" refers to the pin which must go to GND to complete the circuit.

So when you say 5V pin, are you referring to the 5V output pin, or are you referring to the connector which is used to power the Arduino (as I am doing now)?

JDBurnZ:
Currently, my set up is using Digital Pin 2 (also tried others) to output a signal to the Relay. The output from the Pin 2 when OUTPUT is HIGH is ~4v/~40mA (milliamps).

Since the "absolute maximum" rating for Arduino output pin current is 40mA you shouldn't be doing that -
a sensible safe upper limit is around 25mA per pin. The voltage drops when current is drawn as the output
transistors on the chip have a certain resistance (a few tens of ohms). When driving the base of a transistor
through 1k the pin will be much closer to 5V as it is much more lightly loaded.

The circuit posted by dc42 is exactly what you need - if your relay is 5V winding then substitute 5V for 12V in
the diagram. Grounds have to be commoned for circuits that talk to each other. Note that the relay itself
isolates circuits, the contacts are not connected in any way to the winding.

12V Gnd needs to connect to Arduino Gnd.
Wouldn't this potentially burn out the device depending on the amount of electricity that passes through it? Why not connect it directly to the 12V GND? What benefits do I gain through passing it through the Arduino?

I know this is a hard one to wrap your head around - it used to always trip me up when i begin with microcontrollers (as i am from the software not hardware side)

Basically (repeat after me) GROUND is GROUND is GROUND is GROUND. :smiley:

It does not matter (there are some caveats) what the +ve voltage is - ground is always essentially Zero volts.

Craig

Quote
12V Gnd needs to connect to Arduino Gnd.
Wouldn't this potentially burn out the device depending on the amount of electricity that passes through it? Why not connect it directly to the 12V GND? What benefits do I gain through passing it through the Arduino?

Basically (repeat after me) GROUND is GROUND is GROUND is GROUND.

In this application (as shown in the schematic) there is no reason to connect the 12V GND to the Arduino Gnd.

There most certainly is a reason ... without the grounds connected, what is the return current path for the emitter of the transistor??? You put a logical high into the 1K resistor where is the current flow? It MUST be the base-emitter junction and the only way that happens is if the Arduino ground and the transistor's emitter are CONNECTED.

Re. reply #2 schematic.

return current path for the emitter

The return path is to the 5 volt supply ground not the 12 volt supply ground.

Arduino ground and the transistor's emitter are CONNECTED

The transistor is referenced/powered from the 5 volt supply not the 12 volt supply.

I said: there is no reason to connect the 12V GND to the Arduino GND.

The 12V supply switching the solenoid is isolated from the rest of the circuit by the relay contacts so LarryD is correct in saying there is no need to make the grounds common in this circuit. That is the whole point of using relays instead of transistors or FETs the circuits are isolated.

You are right if using Larry's schematic. I was referring to DC42's diagram which runs the relay from 12V. In this instance you do need 12V and 5V grounds connected. The discussion is essentially moot because he has a dual supply and the grounds are generally connected internal to the supply. --Rob

Why does the output high voltage from my Arduino Uno not turn on the relay. It acts in the opposite logic. When I set the output high with a delay of 5 seconds for the NO contacts, it does not work. It is the NC contacts that stay on for 5 seconds??
The basic code is good and I have also tried setting the pin high at the begging of the program, this does not solve the issue.

Regards

That type of "opto-coupled" relay board uses "low-true" logic, the coil is energized by a transistor when input pin is LOW, look at the schematic. It will make sense a little further down the learning road. :slight_smile:
How to setup low-true relays in your Arduino code, assume your relay is on pin 4:

void setup()
{
  digitalWrite(4,HIGH);      // set pin  HIGH before setting to OUTPUT so relay will be OFF on startup
  pinMode(4,OUTPUT);
}
void loop()
{
  DigitalWrite(4,LOW); // turn relay ON
  delay(1000);
  DigitalWrite(4,HIGH); // turn relay OFF
  delay(1000);
}

OptoRelayChannelData-575.jpg
OptoRelay4X_Wiring.png
EDIT: You must stop thinking "HIGH is ON" and "LOW is OFF", in digital logic, either could be either, depending on hardware requirements.

OptoRelayChannelData-575.jpg

OptoRelay4X_Wiring.png

That's great thank you for your reply, it makes sense; but initially confusing as there is no information about it via the relay data or Arduino. My basic electronics experiences relates to switching on a relay via a transistor input signal from a pic. Can you purchase relays that will operate on a high input?