0
\$\begingroup\$

I'm new to electronics but I decided I want to try and build a simple circuit to control with my Adruino UNO R3.

I want to make a relay switch on and off programmatically with my UNO.

Here is my current code:

    #define RELAY_PIN 2
    
    void setup() {
      pinMode(RELAY_PIN, OUTPUT);
    }
    
    void loop() {
      digitalWrite(RELAY_PIN, LOW);
      delay(2000);
      digitalWrite(RELAY_PIN, HIGH);
      delay(2000);
    }

Here is the diagram of my current circuit:

enter image description here

The relay I'm using is a 12 V low level trigger relay (in diagram.)

The problem is when the IN1 wire is connected to pin 2 on the UNO, the relay buzzes consistently and doesn't open/close the circuit, but when I take the IN1 wire and put it into 12V- on the power supply, the relay opens/closes.

I watched a YouTube video where a BC547 transistor was used. I tried it (UNO D2 to base, IN1 to emitter) and no success as well.

How do I get the relay to work correctly?

\$\endgroup\$
11
  • \$\begingroup\$ How is your Arduino powered? Does it share a ground with your relay board? \$\endgroup\$
    – vir
    Commented Jul 16 at 17:46
  • \$\begingroup\$ You MUST connect the Arduino Ground to the relay board/12 V power supply Ground/Negative so that the Arduino and relay board have a common reference. \$\endgroup\$ Commented Jul 16 at 17:50
  • \$\begingroup\$ @vir the Adruino is powered by the USB cable for now, no ground from Adruino to relay board (not sure where it should go becuase it's a 12v relay board). I was thinking of powering it with the same 12v power supply because the specifications seem to support 12v. \$\endgroup\$ Commented Jul 16 at 17:51
  • \$\begingroup\$ @PeterBennett so my Adruino is powered by the usb port now, is it a problem that the relay board gnd is 12v and the adruino is 5v? \$\endgroup\$ Commented Jul 16 at 17:53
  • \$\begingroup\$ Yeah the voltages aren't necessarily a problem but you need a common ground between the two (and obviously powering the Arduino from the same 12V supply counts as a common ground too). I would be slightly wary of just connecting a random USB ground to a separate power supply, especially if the USB is coming from your computer and not just a power brick. \$\endgroup\$
    – vir
    Commented Jul 16 at 17:57

2 Answers 2

1
\$\begingroup\$
  1. You need a ground wire from the Arduino to the relay module. (This has already been mentioned and didn't completely fix the problem.)
  2. Power the relay module from 5V instead of 12V. The relay have a rated coil voltage of 5V, not 12V and there doesn't appear to be a voltage regulator on the board.

This is how you should wire it using a power supply:

schematic

simulate this circuit – Schematic created using CircuitLab

You should be able to wire it this way:

schematic

simulate this circuit

That should work if the relay module only requires 5V as I suspect.


If you are really using the pictured power supply, you need to be very careful around it. There are exposed screw terminals with 220VAC on them. Touching those screw terminals could kill you.

\$\endgroup\$
4
  • \$\begingroup\$ Do I connect pin Vin on the Uno to the VCC pin on the relay, and then the GND next to Vin on the Uno to the GND of the relay and then the D2 from the Uno to the IN1 on the relay? will this work on 5v from the USB cable? \$\endgroup\$ Commented Jul 17 at 8:48
  • \$\begingroup\$ Thanks for the schematic, just to confirm: which ground on the Uno do I use? the one by the Digital pins or one of ones by the Power pins? \$\endgroup\$ Commented Jul 17 at 9:44
  • \$\begingroup\$ I tried your second circuit and the light on the ralay goes on and off, but the relay isn't clicking \$\endgroup\$ Commented Jul 17 at 9:48
  • \$\begingroup\$ The solution for me was to use a 5v relay module \$\endgroup\$ Commented Jul 17 at 20:50
0
\$\begingroup\$

You need to connect a ground wire from the Arduino to the ground of the relay board in addition to the IN1 wire you already have connected such that they are working from a common ground potential.

\$\endgroup\$
2
  • \$\begingroup\$ do I connect the Digital GND to the GND on the Relay Module and then the IN1 the D2 pin as well as have the VCC to the 12v + of the power supply? \$\endgroup\$ Commented Jul 17 at 8:14
  • \$\begingroup\$ Yes that correct \$\endgroup\$ Commented Jul 17 at 11:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.