Relay control with Arduino

Hello all,

I have some problems in controlling relay using Arduino. I am using Some electronics to switch ON/OFF the relay. I use circuit from the following link.

I am using the following code to control the relay.

int relay = 8;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(relay, OUTPUT);
  
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(relay, HIGH);
  delay(1000);
  digitalWrite(relay, LOW);
  delay(1000);

}

I have 5V relay.The relay is not switching as per the code given above. I am connecting Arduino to PC Via USB cable. I also tried connecting the battery to power relay coil(If there is not enough current supplied from the USB) What am I doing wrong?

I'm very new to this myself but I'd use an led and resistor between pin 8 and ground to confirm the code was working the way I expected.
That way you know whether it's the code or the electronics where your problem is.

Hi guys.
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html

@Whitey2505 suggestion is a good one.

Also check that your transistor connections are correct.

Can you post a picture of your project so we can see your component layout please?

What transistor are you using?
What is the spec/data on your relay?

I presume you are using the output circuit in this image?

Tom... :slight_smile:

if you change

int relay = 13;

you should see the LED on the Arduino flash on/off at 1 second intervals

I am uploading the images. You can see the connections on the breadboard. The RED and Green Wires parelllel to the diode is connected to the relay. Second image is my relay connections.

@TomGeorge.. Yes that is the correct image

https://i.imgur.com/dJmGXj7g.jpg

Hi,

Your diode is the wrong way around, the end with the white strip is the cathode and it should go to the positive side of the relay coil, the other end of the diode to the transistor collector side of the relay coil.

Tom... :slight_smile:

what load are you switching?
if it is a low voltage use a reed relay if it mains voltage use an opto coupled relay

Relay itself says 6V, not 5V.

Connect the relay to your power supply directly, you should hear it clicking (or at least using your multimeter you can see whether contacts are made and broken).

Yes now the things are working!! :slight_smile: :slight_smile:

The relay is switching from USB supply of Arduino.

if it is a low voltage use a reed relay if it mains voltage use an opto coupled relay

I will switch to the mains power using relay(230VAC), I dont have optocoupler at present. My question is There should be no risk as the relay coil contacts and NO/NC contacts are always isolated.

Shouldn't be indeed... The opto is there simply as additional safety feature.