How to GND the relay coil using program?

Greetings,
I am new to hardware programming and have very little basic knowledge.

I am building a robot arm with geared DC motors which I would like to operate using Arduino. I am using this[1] 4 channel relay board to build an H bridge as L293D gets heated up and burns on prolonged usage. When I connect the input header to ground manually with my hand, relay coil gets energized and the circuit completes, motor rotates etc (no problem here, thus the connections).

On the other hand, during my college days, I was told that, setting the bit to LOW on a microcontroller would sink the voltage/GND the circuit. I have connected a diode to prevent the current flow to the input header of the relay from microcontroller when I set the bit HIGH. When the bit is set to LOW, diode allows the current to pass through into the microcontroller and the coil energizes completing the circuit as expected. But soon after the motor starts, in a fraction of a second arduino seems to be rebooting! Can anyone help me how to go around this problem or point me out the mistake I am committing?

Here is the program I have been using

void setup(){
pinMode(5, OUTPUT);
}

void loop(){
digitalWrite(5, HIGH);
delay(2000);
digitalWrite(5, LOW);
delay(2000);
}

Reference:
[1] : https://www.amazon.in/xcluma-Channel-Module-Expansion-Arduino/dp/B072J3QT1J

For a really helpful answer you should use a freehand-drawing to show how you have things wired together. Avoid using fritzing! Frizzing pictures are very common. But it is highly unprofessional.

You can't use the arduino as a powersupply !

It might be that the relay is drawing too much current or the motor if you supply the relay or the motor from the arduinos 5V pin

best regards Stefan

Dump it and use a modern (MOSFET) driver.

Add the flyback diode over all inductive loads (motors...) or better use a motor driver board.

What else would you expect? Inputs expect a high or low voltage, outputs provide that voltage levels.

Relay boards etc. with opto couplers require some input current.

Thank you Stefan. And sorry, I am new to this. Please help, I am ready to learn.

I am using an external 5V power source (mobile phone charger) for motors.
Since I am using a readymade relay board I only have access to NO, NC and COM.
I have wired the relays like in this image https://i.stack.imgur.com/C6fdi.jpg
I connect the IN1, IN2 headers using jumper wires to Arduino digital pins.

Thank you DrDiettrich.
Since my motor has to rotate in both directions, can I choose any of the terminals as cathode and anode for adding a flyback diode?

forgot to say "Hi and welcome to the arduino-forum."

it is common to post pictures directly into the textinput of the postings.
To get the allowance to do so you must reach trust-level one in the forum.
Which is easy to do
Get to trust level 1 by…

  • reading at least 5 topics
  • Reading at least 30 posts
  • Spend a total of 10 minutes reading posts

This is a picture in combination with a worded description.
You should really draw a hand-drawn picture that shows how you have things wired together.

And you should take a picture from vertical above that shows how you have things wired together.

Additionally post

  • a datasheet of your motor
  • the specs sticker of the motor

If you start building things with an arduino you should have a digital multimeter for measuring voltages, currents and resistance.
Any digital multimeter in the $10-20 range will do.
if you can afford more money I recommend this one

which can be bought at a low price here

Very good price perfomance ratio
it can additionally measure duty-cycle, frequency, transistor-gain, diode-forward-voltages 20A (which most DMMs can't and has bluetooth and an app for receiving measurings and record measurings at low speed.

best regards Stefan

That depends on your circuit. Better use a motor driver board. You may have to add 4 diodes between the motor and supply.

I second that depending on the motors current you could use this driverboard

Which can be used for DC-motors and for stepper-motors

if you need more amperage you could use this one
BTS 7960 chip

best regards Stefan

No you can't. You have to use four diodes like in this diagram.

Hi @Grumpy_Mike

maybe I have a knowledge-gap that I'm not aware of and if this is the case
I would like to close this knowledge-gap.

As far as I understand it you would not need any diodes in a relay-H-bridge

Here are the four possabilities how the relay-contacts could be switched

Either there is connected GND to GND
or
plus to plus which is no problem
or the motor is inbetween Plus and GND but that is how you connect the motor anyway.

So what makes it nescessary to add the diodes?
Is this because if you change polarity while the motor is at maximum rpm the motor acts as a generator and would feed in a voltage that could destroy anything?

I appreciate it very much if you would explain the details.

best regards Stefan

You need to remove the jumper from the JD-VCC connector and supply 5V from an external supply to the JD-VCC pin

The diodes are needed to prevent the back EMF from the running motor. If you look at the data sheet of a ancient chip like the L293 you will see that these diodes are incorporated into the chip internally.

But note this is only for one of the three motor drivers. If you want to make the other pair of motor drivers into a H-Bridge to need to add these external diodes.

If you are using relays to implement a H-Bridge then you need these diodes, for exactly the same reason, that is the interference caused by the motors. The fact that one end is connected to ground doesn't matter without a flyback diode you will still get interference generated.

No, what happens there is that the motor becomes a generator of opposite polarity and discharges the energy into the the motor itself to stop it turning. This is called regenerative breaking and the motors stop quicker. In fact in Switzerland the electric (battery run) busses use this regenerative breaking current to actually charge up the batteries. A dam clever idea.

Hope that helps.

1 Like

That did not help :frowning:

You connected a 5V, 0.5A power supply between JD-VCC and GND?

Yes.

+ve to JD-VCC
- ve to GND

  • The signal LOW in arduino seemed not to have any effect. If I connect IN1 to GND of this relay board, motor runs. But if I connect to arduino's GND, motor does not run.

Is the relay board GND connected to Arduino GND?

Yes

Hi,
Can you please post some pictures of your project?
So we can see your component layout.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

And relay board VCC connected to Arduino 5V?