I'm currently working on a project where I need to use a 2 channel relay module for controlling a DC motor in both directions.
When I started the project I anticipated that I would need digital outputs to activate the coils in the relays. However I came to the realization today, that I needed to connect "IN1" and/or "IN2" to ground, rather than giving them 5V, in order to activate the coils in the relays.
However I am already very far in the project, and have most things soldered on my control board, so I don't have time nor resources to start over, and plan on making this a new way.
My question here is:
How can I use a digital output to "open" the connection between for instance "IN1" and Ground on the Arduino? I was thinking of using a transistor, however my electrical knowledge is limiting me here, and I could need some advice.
Should I use transistors for connecting "IN1" and "IN2" to ground on demand, using digital outputs? If yes, would I need PNP or NPN transistors?
Please bear with me and my limited knowledge. I tried googling this for some time too, but I didn't have any luck cooking down my question to keywords that give a useful result on Google.
A schematic and code would help a lot because as I am imagining it you don't have a problem.
I am guessing that you have 2 digital pins defined as output connected to each of the inputs to each relay. You thought you'd make the pin high to turn the relay on but now you find you have to make it low. Reverse the logic in your code.
I'm afraid I don't have much in schematics. I have uploaded a photo from Google, that I wired the output side of the relay with.
I'm using a 12V power supply for main power for the entire circuit, and a 5V voltage regulator for push buttons, LEDs etc. I'm using an Arduino Pro Micro processor, and powering it with 12V through its RAW input.
For the input side of the relay, I have wired it as following:
VCC: 12V from mains (it doesn't work with 5V, it is not enough to close the coil), IN1: Arduino pin 8, IN2: Arduino pin 9, GND: Ground
The program is near non existant right now. It just mirrors the state of two button inputs on the arduino. Plans are that the motor will be changing direction every 24 hours using the arduino's output.
I understand what you are suggesting - using the output pins as ground. However I'm afraid that they will be damage since I can see from my lab power supply, that the relays consume 0,04 amperes and 0,48 watts at 12 volt, which I believe I have heard, is the absolute maximum the pin can withstand, acting as ground.
Please read the post at the start of any forum , entitled "How to use this Forum".
OR https://forum.arduino.cc/index.php?topic=712198.0
Then look down to "code problems" about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.
Can you post a picture of your project including how you are powering it and so we can see the relay board.
You need to get a pen(cil) and paper out and draw your circuit, then post a picture of it.
You connect "IN1" and "IN2" to the respective Arduino or ESP pins. You only need 5 mA to drive the optocouplers.
In your code, you first write these pins HIGH, and then you use pinMode to set them as OUTPUTs.. To operate a relay, you write that output LOW.
Remove the link connecting "VCC" to "JD-VCC". Connect "VCC" to the "5V" line on the Arduino. Connect "JD-VCC" and "GND" directly - by a separate pair of wires running together - to 12 V and ground of the relay supply itself, you do not otherwise connect the "GND" to the Arduino.
What are you using to provide 5 V for the Arduino?
Thanks a lot for your good answer. This was what I needed.
I'm sorry for the late answer to everyone, I've been busy lately.
The relay module in your picture, Paul, is the exact same as I'm testing with right now. I didn't realize that there were different VCC pins. I will try what you are saying.
I'm using a 6-36 VDC to 5VDC 2A voltage regulator. However the arduino is powered directly from the 12VDC 4,2A meanwell power supply in its RAW input. I meant to take the power from the UREG to power the relays.
I've attached a picture of how I initally planned on wiring it, and how I believe that you, Paul, want me to wire it.
You have a 5V power supply, you should use it to power Arduino by connecting 5V from the power supply to the 5V pin on the Arduino.
By 'regulator' do you actually mean a buck converter or do you mean a linear regulator? A regulator turns excess voltage into waste heat, a buck converter swaps voltage for current with very little waste.