I am using my arduino mega to read in an inclinometer, then command a relay to control a linear actuator. The linear actuator has a pot for closed-loop position. The actuator is powered from a battery, the inclinometer from a power supply, the relay from the arduino, and the pot from the arduino. I noticed that when I am commanding the relay it is pulling about 70 mA, whereas the max on the arduino is supposed to be around 20 mA. This seems to be causing the reference voltage for my pot to drop, giving me inaccurate readings.
Has anyone experienced this before or can anyone recommend a 2-channel relay that can be powered with an arduino and will not draw more than 20 mA?
I got the relay from Amazon and I don't exactly remember the supplier, but the relay looks like this one.
That relay module you posted a link to is designed so separate the driving (Arduino) side of things with the Relay side of things via an optocoupler.
Although the board allows the use of a common +ve to power the LED of the optocoupler AND the switching circuit (transistor) of the relay it would be better to use a separate power supply for this. There is a jumper on board to allow this (careful you don't move that jumper as it will short out the Vcc and Gnd pins - a booby trap if ever I saw one!). It's marked JD-VCC and is the power line for the 'other side' of the optocoupler and the transistor and the relay coil.
You can 'get by' driving it all from the Arduino (IIRC it takes about 20ma for each relay) especially during development but the resultant current requirement may well upset the rest of your circuit if you don't use a separate power line as described above.
This means you need to connect "Vcc" to your Arduino 5 V, the inputs for each relay to Arduino pins, "JD-Vcc" to your separate relay supply (5 V) and "Gnd" to the relay supply and not your Arduino. And of course you remove the link from "Vcc" to "JD-Vcc".
The exception is if you are powering both Arduino and relay supply from a fully-regulated 5 V supply in which case the 5 V and ground wires should run together from power supply to each module, but connected separately to the relay board directly from the power supply output terminals and again separately to the Arduino from those terminals. It might be advantageous to add a 220 µF capacitor directly across the relay module power terminals.
Also when programming, you digitalWrite the relay control pins HIGH before you configure them as outputs since a LOW will turn on the relay.
So, you are saying when you are using a separate power supply for the relay, and when you are connecting a digital pin from the Arduino, ground from the Arduino is not needed for that digital pin to work.
~~The return path from the digital pin of the Arduino is provided by ground, so I don't think I agree with that. ~~ But then I've been wrong about things before....
The connection to ground is through the Arduino output transistor which connects the pin either to VCC when HIGH or GND when LOW, the idea is for both isolation and reducing interference through ground loops.
The Arduino is "low side" switching.
Thanks, but I am still going to go with my declaration: the external power supply GND and Arduino GND must be connected together, and both connected to the relay board GND, for the switching to work reliably and to be an electrically acceptable circuit. If it happens to work without the grounds connected together, then fine, but I won't be wiring mine that way.
I've used that type of relay board in numerous projects, even with 12V coils in automotive projects and never used a ground wire from the Arduino, only VCC and wires to the IN pins, I used to think the same as you 'til wawa (Leo) straightened me out.
Just think about it, all the Arduino is doing is turning on an LED, only 2 wires are needed, "HOT" and "NEUTRAL", the switch (Arduino) being on the "NEUTRAL" side.
Usually, in electronics work, experience would lead to thinking that the more ground connections, the better. It seems your experiences have led you the opposite way, at least so far. That is OK. I'm glad your projects have been successful although you omitted a ground wire. I've done my analysis and think I will continue to waste my bit of wire and effort, and just hook up the grounds.
EDIT: yes, usually hook up the grounds, but it is not appropriate with an optocoupler wired like this
I see the light now, thanks. For this type of board with optocoupler it is appropriate to not connect the ground from the Arduino. It took me a while to get it. Thank you especially to dlloyd, outsider, Paul__B, Ralph_S_Bacon, Wawa. I like this learning. Sorry for being that dense. My hope is I edited my posts in such a way to add clarity.
Just to clarify some of the terminology on this thread, the Arduino does not turn the relay ON, it SINKS the current via one of its digital pins to allow current to flow from the supplied +vcc through the optoisolator to the Arduino and hence to ground.
I'm sure we all implicitly understand this but it's important to spell out that we're not supplying a signal to turn something on here (as Paul__B says, that's why you must set the pin as OUTPUT but drive it HIGH to prevent the relay immediately switching on!).
Anyway, good it's all been sorted.
Guess what the subject of my next YouTube video is going to be about?!
Ralph_S_Bacon:
you must set the pin as OUTPUT but drive it HIGH to prevent the relay immediately switching on!
And not in that order!
You always set it HIGH first. A frequently reported problem here is where code first sets it as an output, then some apparently trivial time later, initialises it as HIGH. Though it should only be microseconds, this appears to be sufficient to presumably saturate the transistor and actuate the relay for some milliseconds, creating an output flash.
Why microseconds and not nanoseconds? Well, "digitalWrite()" is not as straightforward as it might appear. Also note that the diode across the relay substantially slows its release.
Paul__B:
A frequently reported problem here is where code first sets it as an output, then some apparently trivial time later, initialises it as HIGH.
Interesting that this is such a common problem.
What's the effect of the internal pullup resistor being enabled (by doing a digitalWrite before setting the mode of the pin), I wonder? That is, having set the pin high, then setting it as output, does it release the internal pullup? I guess it must or nothing would work!
In which case, it might be better to do direct PORT manipulation which doesn't do the all the internal checking of DigitalWrite and therefore executes significantly faster. Then do the pinMode stuff?
I haven't had problems in this area but switching simple stuff on and off probably wouldn't have highlighted potential issues to me. But this is all useful to know.
What's the effect of the internal pullup resistor being enabled (by doing a digitalWrite before setting the mode of the pin), I wonder? That is, having set the pin high, then setting it as output, does it release the internal pullup? I guess it must or nothing would work!
"The pullup resistors are controlled by the same registers (internal chip memory locations) that control whether a pin is HIGH or LOW. Consequently, a pin that is configured to have pullup resistors turned on when the pin is an INPUT, will have the pin configured as HIGH if the pin is then switched to an OUTPUT with pinMode(). This works in the other direction as well, and an output pin that is left in a HIGH state will have the pullup resistors set if switched to an input with pinMode()."
The datasheet has a nice detailed circuit diagram (fig 13-2) for what hangs off a digital pin - its quite complex. The
pull-ups are specifically only enabled when the pin is an input (DDRx register bit is a 0) and the PORTx
register bit is 1 and the PUD bit in MCUCR is 0 (the default).
(Actually this is a slight over-simplification as I am ignoring the output toggling that can be done
by writing the PINx register.)