Controlling DPDT relay from Mega digital pin

For my latest project I want to use a latching switch that has 2 colour LED indicators. The LEDs are wired in parallel opposing each other, so that applying a voltage in one direction will light one LED (e.g. red) and reversing the polarity lights the other LED (e.g. green).

Reversing the polarity of the supply isn't a problem; I'm going to use a DPDT relay which is switched by a Mega digital output.

The relay boards I've seen don't allow for an external power supply, and have no optocoupler isolation, and I'm thinking the drive current might also exceed 40mA.

What's the easiest/best way to supply the relay from the external 5v PSU (which also supplies the Mega through the barrel connector), and switch it from a Mega digital pin?

Hi,

Much easier, I think, to use easily-available opto-isolated relay boards.

Tell us more about what this is used for. Are the LEDS the only active thing happening?

"Latching" can be done in Arduino in software.

How big are the LEDS? How much current?

A single Arduino output can run two LEDS with a series resistor like 200 ohms, and the LEDs connected to =%V and Ground, respectively. No relays needed.

See Arduino Power here: ArduinoPower - ArduinoInfo

The specification for the relay link you provided tells it all:

DR21B01 5VDC one Channel DPDT Relay Board

Operating Voltage : DC 4.5-5.5V(5V)
Operating Current(Relay ON): 36MA
Standby Current(Relay OFF) : <1MA

Input control signal voltage:
0V - 0.6V Low stage (relay is OFF),
0.6V – 2.5V (unknown state).
2.5V - 24V High state (relay is ON).
Input control signal high state current:
2.5V: 0.15mA
5V: 0.4mA <<<<<<<<<<<<-----------

Relay Load : 1A 125VAC;2A 30VDC

Size : 22.86x18x14
Weight :6g

The input current from the mega will be 0.4ma when driving it high. And the board is powered by external power.

Also:

The Mega output pin can drive the transistor of this 5v relay board.

If you want to power the Mega via the on board jack, use 7-12vdc.

Connect the Mega 5v pin to the Vcc pin on the relay board.

That relay board seems to have all the supporting parts on it (drive transistor, etc).
It means relay coil current comes from the 5volt power pin of the Mega, and not from an output pin.
It also means you don't need an external supply (for one relay).
Current capability of the 5volt pin depends on how you supply the Mega.
With USB supply it's about 400mA.

A 2-pin bi-colour LED (or a made-up one) can be driven between two output pins.
One pin HIGH, and the other one LOW lights up one LED.
Can have brightness control if one pin is PWM capable.
Don't forget the current limiting resistor in series with the bi-colour LED.
Leo..

You do not use a relay board to switch a couple of indicator LEDs!

You use two Arduino outputs and a series resistor. Total resistance should be no less than 220 Ohms - is there a resistor already in the switch assembly for the LEDs?

Game rules:

  • Give a web link to the switch.
  • Explain your purpose, and the rest of your system.
  • Show code and wiring schematic, etc...