I've been working on a project for awhile now, and I ran into a problem a week ago I couldn't solve. I'm using an Arduino uno R3.
My project involves the use of 4 relays triggered by the digital pins. Write a HIGH value, relay clicks. Write a LOW value, relay unclicks. Rather simple.
One day, I come back to it to discover it can no longer click the relays. No changes were made to my code that worked previously. The relay light came on, but no click. Could it be that I sent HIGH to 4 at the same time? My theory is that I could've drawn too much power at the same time, weakening it in a way that causes it to not output as much as it did previously.
I tested a relay on a different board and it works perfectly fine.
-
1how are the relays powered?jsotola– jsotola2021年04月06日 06:12:14 +00:00Commented Apr 6, 2021 at 6:12
-
The relay has 3 pins. 5V in, GND, and signal. It's powered by the board. Reconnecting the signal wire from the PWM pin to the 5V triggered the relay, so it's not a voltage problem or a relay problem. I've also tested many relaysMelBel03– MelBel032021年04月06日 08:47:52 +00:00Commented Apr 6, 2021 at 8:47
-
1stop calling it PWM pin. it is a digital pin. you don't use PWM to control a relayJuraj– Juraj ♦2021年04月06日 10:15:59 +00:00Commented Apr 6, 2021 at 10:15
-
3Relays need a certain current and Arduino pins can only provide a small amount of current. Normally you don't power the relay coil directly from a pin. Please post a schematics of your wiring, as well as a reference or datasheet for the relay you're using.Sacha– Sacha2021年04月06日 13:19:29 +00:00Commented Apr 6, 2021 at 13:19
-
Are you recommending I use the relay in a different way? I'm unable to provide a visual diagram for my wiring, but it goes like this: 5V power to DC+; GND to DC-; PIN6 to IN1.MelBel03– MelBel032021年04月07日 02:02:56 +00:00Commented Apr 7, 2021 at 2:02
1 Answer 1
Not knowing the reference of your relay, my answer is generic but should suit your needs.
Relays need 2 things in order to work properly: a sufficient voltage source, and one that can provide enough current.
The Arduino output pins provide 5V on 5V boards or 3.3V on 3.3V boards. BUT, most Arduino GPIO can provide only 20 mA of current. That might not be enough for your relay. The solution here is to use a transistor to drive the relay.
Also, relay coils are inductive loads that generate voltage spikes when current is turned off. That voltage can rise much higher than 5V and damage your Arduino pins and weaken or destroy them. The solution to this problem is to add a flyback diode.
This is what a typical circuit with relay driven by an Arduino looks like:
When the Arduino pin is LOW, the transistor is turned off and no current goes through the relay.
When the Arduino pin turned ON, the transistor turns on fully saturated and the relay coil is energized.
When the Arduino pin is turned LOW, the coil generates a negative voltage and current is allowed to go through the diode, dissipating energy in the relay coil. More information on flyback diodes: https://en.wikipedia.org/wiki/Flyback_diode
-
inductive loads generate reverse voltage spike when it is turned OFFSBF– SBF2021年04月07日 08:12:17 +00:00Commented Apr 7, 2021 at 8:12
-
-
There is another thing: the SUM of currents (driving or sinking), may be a thing. Despite proper operation of one relay, even two, when situation comes to drive all relays this may be too much when all currents add. For ATMEGA328P-PU sum of currents may not exceed 200mA. Recommended lecture: Arduino Uno R3 microprocessor's datasheet (ATMega328P-PU)smajli– smajli2021年04月07日 10:09:00 +00:00Commented Apr 7, 2021 at 10:09
-
For 4 relays, the OP would be limited by the per pin current limitation way before being limited by the per chip limitatation. Using a transistor would reduce the current provided by the chip to way below both limits.Sacha– Sacha2021年04月07日 12:35:38 +00:00Commented Apr 7, 2021 at 12:35
-
Post a link to the relay you are using, I do not know if it is a plane relay or a relay module for the arduino. The modules are less then a buck from your favorite china supplier.Gil– Gil2021年04月07日 20:42:24 +00:00Commented Apr 7, 2021 at 20:42