# How to GND the relay coil using program?

**URL:** <https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224>\
**Category:** Programming\
**Created:** [November 20, 2023, 7:20am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224 "2023-11-20T07:20:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 7:20am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/1 "2023-11-20T07:20:41Z")

</div>

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

```arduino
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](https://www.amazon.in/xcluma-Channel-Module-Expansion-Arduino/dp/B072J3QT1J)

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 20, 2023, 7:57am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/2 "2023-11-20T07:57:16Z")

</div>

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 **un** professional.

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

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [November 20, 2023, 8:04am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/3 "2023-11-20T08:04:08Z")

</div>

> [@robotbramhana](#):
>
> L293D

Dump it and use a modern (MOSFET) driver.

> [@robotbramhana](#):
>
> mistake I am committing

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

> [@robotbramhana](#):
>
> setting the bit to LOW on a microcontroller would sink the voltage/GND the circuit.

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.

---

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 8:08am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/4 "2023-11-20T08:08:20Z")

</div>

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](https://i.stack.imgur.com/C6fdi.jpg)  
I connect the IN1, IN2 headers using jumper wires to Arduino digital pins.

---

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 8:21am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/5 "2023-11-20T08:21:37Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 20, 2023, 8:29am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/6 "2023-11-20T08:29:42Z")

</div>

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

> [@robotbramhana](#):
>
> I have wired the relays like in this image [https://i.stack.imgur.com/C6fdi.jpg](https://i.stack.imgur.com/C6fdi.jpg)  
> I connect the IN1, IN2 headers using jumper wires to Arduino digital pins.

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

> **[OWON OW18B 3 5/6 Smart Digital Multimeter | owontechnology.eu](https://www.owontechnology.eu/product/1361022/owon-ow18b-3-5-6-smart-digital-multimeter)**
>
> OWON OW18B with Bluetooth Module is a 3 5/6 bit resolution Digital Multimeter that Supports NCV non-contact voltage sense and True RMS test is supported

which can be bought at a low price here

> **[OWON True RMS Bluetooth-Multimeter OW18B](https://www.pollin.de/p/owon-true-rms-bluetooth-multimeter-ow18b-830830)**
>
> Das OWON True RMS Bluetooth-Multimeter OW18B bietet neben den Standardfunktionen weitere nützliche Zusatzfunktionen wie Echteffektivwertmessung,

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

---

<div class="post-metadata">

**Author:** ![DrDiettrich](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/drdiettrich/32/219048_2.png) [@DrDiettrich](https://forum.arduino.cc/u/DrDiettrich)\
**Post date:** [November 20, 2023, 8:29am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/7 "2023-11-20T08:29:58Z")

</div>

> [@robotbramhana](#):
>
> cathode and anode for adding a flyback diode?

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

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 20, 2023, 8:32am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/8 "2023-11-20T08:32:41Z")

</div>

> [@DrDiettrich](#):
>
> That depends on your circuit. Better use a motor driver board.

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

> **[Adafruit DRV8833 DC/Stepper Motor Driver Breakout Board](https://www.adafruit.com/product/3297)**
>
> Spin two DC motors or step one bi-polar or uni-polar stepper with up to 1.2A per channel using the DRV8833. This motor driver chip is a nice alternative to the TB6612 driver. Like that chip, ...

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

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

> **[Double BTS7960B DC 43A Stepper Motor Driver H-Bridge PWM For Arduino Smart Car...](https://www.ebay.com/itm/334899613479)**
>
> Able to reverse the motor forward, two PWM input frequency up to 25kHZ;. Double BTS7960 large current (43 A) H bridge driver;. Just need four lines from MCU to driver module (GND. two heat flow passing through an error signal output;. ).

best regards Stefan

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 20, 2023, 8:41am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/9 "2023-11-20T08:41:03Z")

</div>

> [@robotbramhana](#):
>
> 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?

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

 ![H-bridge with switches](https://europe1.discourse-cdn.com/arduino/original/4X/b/f/3/bf36264ed55d3863560b4b0a1a59d4c976f6e75d.jpeg)

---

<div class="post-metadata">

**Author:** ![StefanL38](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/stefanl38/32/713548_2.png) [@StefanL38](https://forum.arduino.cc/u/StefanL38)\
**Post date:** [November 20, 2023, 9:11am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/10 "2023-11-20T09:11:34Z")

</div>

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

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/2/3/b23b5f80e0ea70f16cea739609ff219611215592.jpeg)

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

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [November 20, 2023, 9:45am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/11 "2023-11-20T09:45:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [November 20, 2023, 11:05am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/12 "2023-11-20T11:05:20Z")

</div>

> [@StefanL38](#):
>
> As far as I understand it you would not need any diodes in a **relay** -H-bridge

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.

 ![Diodes](https://europe1.discourse-cdn.com/arduino/original/4X/5/5/6/556f365d63bb93803468a768c5df3827897d02ed.png)

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.

> [@StefanL38](#):
>
> 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?

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.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [November 20, 2023, 11:30am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/13 "2023-11-20T11:30:11Z")

</div>

![71TWos73PrL.SL1100](https://europe1.discourse-cdn.com/arduino/original/4X/3/e/3/3e331d9c4b5b1861a6e13c811aec0c93b480b124.jpeg)

---

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 11:30am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/14 "2023-11-20T11:30:13Z")

</div>

That did not help ☹

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [November 20, 2023, 11:32am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/15 "2023-11-20T11:32:18Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 11:41am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/16 "2023-11-20T11:41:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [November 20, 2023, 11:45am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/17 "2023-11-20T11:45:46Z")

</div>

Is the relay board GND connected to Arduino GND?

---

<div class="post-metadata">

**Author:** ![robotbramhana](https://avatars.discourse-cdn.com/v4/letter/r/e47c2d/32.png) [@robotbramhana](https://forum.arduino.cc/u/robotbramhana)\
**Post date:** [November 20, 2023, 11:50am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/18 "2023-11-20T11:50:04Z")

</div>

Yes

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [November 20, 2023, 11:51am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/19 "2023-11-20T11:51:38Z")

</div>

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.. 😀 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [November 20, 2023, 11:52am UTC](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224/20 "2023-11-20T11:52:28Z")

</div>

And relay board VCC connected to Arduino 5V?

[Next page](https://forum.arduino.cc/t/how-to-gnd-the-relay-coil-using-program/1191224.md?page=2)
