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.
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.
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.
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).
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.