Arduino will not operate external relays

I built a signal light controller to switch these relays that will control higher amperage lamps. The Nano works great and operates the LEDs from the digital pins, but refuses to close the relays.

When the digital pins go LOW they will not go low enough to close the relay. The relay will close if I jump straight to ground.

The LEDs are common anode and are switched on the cathode side.

Is the problem with the LED circuits on the digital pins?

Thanks!

Please provide a full schematic including all power connections.

Please provide clickable links (to datasheets) for all components that are connected to the Arduino.

How do you know that they don't go low enough? Did you measure? If pins don't go low enough, it indicates that you're overloading the pin (max. safe current is 20 mA).

Code might be useful as well.

We hope you have not foolishly attempted to connect a relay coil directly to an Arduino pin! :roll_eyes:

Hi,
Do you have current limit resistors on each of the LEDs?

Tom.... :slight_smile:

That would certainly follow on from my question! :grinning:

// this constant won't change:
 const int  buttonPin = 2;    // the pin that the pushbutton is attached to
 const int ledPinred = 11;       // the pin that the LED is attached to
 const int ledPinwhite = 10;       // added
 const int ledPinyellow = 9;  // added
 const int ledPingreen = 8;
// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED as an output:
   pinMode(ledPinred, OUTPUT);
   pinMode(ledPinwhite, OUTPUT); //added
   pinMode(ledPinyellow, OUTPUT); //added
   pinMode(ledPingreen, OUTPUT); //added
   // initialize serial communication:
   Serial.begin(9600);
}


void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);

   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
     // if the state has changed, increment the counter
     if (buttonState == HIGH) {
       // if the current state is HIGH then the button
       // wend from off to on:
       buttonPushCounter++;
       Serial.println("on");
       Serial.print("number of button pushes:  ");
       Serial.println(buttonPushCounter);
     } else {
       // if the current state is LOW then the button
       // wend from on to off:
       Serial.println("off");
     }
     // Delay a little bit to avoid bouncing
     delay(50);
   }
   // save the current state as the last state,
   //for next time through the loop
   lastButtonState = buttonState;


   // turns on the LED every four button pushes by
   // checking the modulo of the button push counter.
   // the modulo function gives you the remainder of
   // the division of two numbers:

   //added
   if (buttonPushCounter == 1) {
     digitalWrite(ledPinred, HIGH);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, LOW);
   } else if (buttonPushCounter == 2) {
     digitalWrite(ledPinred, HIGH);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, LOW);
     digitalWrite(ledPingreen, HIGH);
   } else if (buttonPushCounter == 3) {
     digitalWrite(ledPinred, HIGH);
     digitalWrite(ledPinwhite, LOW);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, HIGH);
   } else if (buttonPushCounter == 4) {
     digitalWrite(ledPinred, LOW);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, HIGH);
   } else if (buttonPushCounter == 5) {
     digitalWrite(ledPinred, LOW);
     digitalWrite(ledPinwhite, LOW);
     digitalWrite(ledPinyellow, LOW);
     digitalWrite(ledPingreen, LOW);
   } else if (buttonPushCounter == 6) {
     digitalWrite(ledPinred, LOW);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, LOW);
   } else if (buttonPushCounter == 7) {
     digitalWrite(ledPinred, LOW);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, LOW);
     digitalWrite(ledPingreen, HIGH);
   }else if (buttonPushCounter == 8) {
     digitalWrite(ledPinred, LOW);
     digitalWrite(ledPinwhite, LOW);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, HIGH);
   }
   
   else {
     digitalWrite(ledPinred, HIGH);
     digitalWrite(ledPinwhite, HIGH);
     digitalWrite(ledPinyellow, HIGH);
     digitalWrite(ledPingreen, HIGH);
     buttonPushCounter =0;
   }

}

IMG_9607.png

IMG_9607.png

Hi,
Thanks for the info, but where is the button you refer to in your code?

If the button is between the input pin and gnd, have you got a pull_up resistor between the input pin and Vcc?

If the button is between the input pin and Vcc, have you got a pull_down resistor between the input pin and gnd?

Thanks.. Tom..

TomGeorge:
Hi,
Thanks for the info, but where is the button you refer to in your code?

If the button is between the input pin and gnd, have you got a pull_up resistor between the input pin and Vcc?

If the button is between the input pin and Vcc, have you got a pull_down resistor between the input pin and gnd?

Thanks.. Tom..

Correct. I have the push button going to digital pin 2 with a 1k resistor.

Hi,
Fine, can you please post a picture of your project so we can see your component layout?
Especially a picture of the relay assembly so that we can identify it from the many relay modules on the market.

Do you have a DMM?

What is your external power supply?

Thanks.. Tom... :slight_smile:

See attached Picture. I am using a very large power supply that puts out 12V and apppears to be regulated. It is overkill at the moment but the 12v lights it will be switching on the high side of the relay will be using this power supply also.

The relay is one of those cheapo amazon 4 bank relays.

Sorry what is a DMM?

IMG_9605(1).jpg

IMG_9605(1).jpg

So far, the relay modules I have used with Opto-isolation have had, on those modules, LED's to indicate power and relay energized. Because, I'd guess, the OP is using the proper relay modules with opto-isolation, the LED's would be redundant, w the 1K resistors.

Oh, just saw the posted pic, I noticed the relay modules power LED is not illuminated.

That is true it does have a LEDs built-in that illuminate when the relay is activated. I could remove the LEDs on the Arduino side for simplicity.

That picture does not show it illuminated but when I connect the low side of the relay to the Arduino they automatically activate. Regardless if the pin is higher low.

Post a close up of the relay module.

The OP mentions 12V. I was wondering if the relay is 12V or 5V, which would make a difference with the JDC-VCC pin.

I looked at my 4 realy module and did not see a power LED but do see IN1-IN4 for the relay activations.

I mention the LED's in your circuit as being not needed to eliminate, the not needed as possible causation.

Ah ha! That was it! I hooked the low side of the relay to the Arduino 5V and ground and it actuated when the pin went low.

I got confused because on the Amazon reviews people said you need to power it off a separate power supply and that the Arduino would not supply enough power to switch the relay.

I will work on it tonight and get the whole thing built and see if it works as a whole, then I will post the project.

thanks guys!

You do need a separate power supply to power the relay module.

The relay module should not be sourced through the Uno 5V pin.

The grounds of the Uno and the 5V power to the relay module should be connected together.

Will do. Thanks!

This is somewhat confused.

Is the relay unit specified at 12 V or 5 V?

What voltage is the power supply?

If it is a 5 V relay module, you need a 5 V power supply. You connect "JD-VCC" and "GND" on the relay module directly to the 5 V power supply by a pair of wires; when I say "pair", I mean they travel together, such as using a sort of "figure 8" cable.

You connect from the power supply to your Nano using a separate pair of wires, to ground and the "5V" pin. You do not use "Vin" - it is useless.

You connect your Arduino outputs and 5 V to the relay board "IN" pins and "VCC" with ribbon cable (5 wires together). This separates the relay power supply from the Arduino power supply in order to avoid the switching current of the relays interfering with the Arduino, making use of the opto-isolators.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.