I'm building an Arduino-compatible circuit that flashes some lights for an hour then turns itself off. I built the power circuit copying the Arduino AA Undershield schematic and all works well, like this:
User presses momentary switch which connects the batteries to the power circuit
The ATMega328 boots and pulls a pin high
This pin completes a 5V relay circuit
The relay's switch is in series with the momentary switch, so once the chip's booted it stays on.
After 1 hour the code pulls the pin low, which breaks the relay, which kills power to the circuit.
As I said all is working, but I'm a programmer by trade and am new to hardware. Is there a more efficient way to do this? I tried using an optoisolator but couldn't get it to work, but I may have easily been doing it wrong.
The output current from an opto isolator is limited to a few mA, if you want more then you will have to have a transistor at the receive end. There is not enough current for an opto to directly control a relay.
It looks like the LEDs will draw about 500ma when all are on, but most of the time they blink so it's closer to 150 - 200.
I did put a resistor between the Arduino and the Optoisolator but didn't think about putting a transistor on the other side, to increase the amount of current the optoisolator can switch. I will look into that.
but most of the time they blink so it's closer to 150 - 200
Yes but be aware when designing things it needs to be able to handle the peak current as if they were all on at once.
The fact they are on an on / off duty cycle only helps with the power (heat) dissipation.
Hi thanks for the example but for this application I didn't need a high powered relay -- I have a 5v one that works directly off a digital pin.
I was looking to see if using an optoisolator + transistor instead a relay reduced power consumption enough to make running the system of AA batteries viable, but I think the draw from 96 LEDs means I'm stuck with a wall wart or D cells.
I have a 5v one that works directly off a digital pin.
Are you saying that you are driving a relay directly from the output pin of an arduino?
That is surprising if you find a relay that pulls in at less than 40mA? If so what is the maker and part number?
The small 5V Omron relays (e.g. type G5V) have a coil resistace of approximately 175 Ohm's. Also I've seen Tyco electronics offer small relays (OMR series) with a coil resistance of 250 Ohm's.
That is surprising if you find a relay that pulls in at less than 40mA?
Are you thinking that the inrush current may be damaging to the Arduino over time when interfacing to the above relays directly?
Well 175R gives you a current of 28mA so that should be OK, however you do need a diode across it or you will damage the output pin with revers voltage.
Are you thinking that the inrush current may be damaging to the Arduino
Inrush current concerns only really applies to capacitors and motors. A relay is an inductor and when you first apply apply a voltage to it there is a delay as the current increases. That is the inrush current starts off at zero and ramps up to the full value given by the resistance of the coil.
You might think a motor is an inductor but in that case the inrush current ramps up to the stall current, before the motor starts turning. Once going a DC motors take less current due to the constant change in direction of current in the rotor.
Yes that relay looks OK for direct drive from an arduino. Things to note:-
You do order the one whose order code ends in 10 or 50 as that has the diode option.
This means the relay coil must be wired the right way round. If it is the wrong way round you will effectively short the output through the protection diode.