Relay Circuit NEVER switches (but relay functions apart from circuit)

Hi all,

I am trying to turn an LED on and off with my relay and I can't get it to work (my LED constantly remains on and never switches off). I'm following the instructables lesson found here (https://www.instructables.com/id/How-to-use-any-relay-with-your-arduino-the-safe-wa/) except that I don't have the same parts as the original writer. I am using:

2 x 220 ohm resistors

1 x MC7815C transistor

1 x HP 6N136 optocoupler

1 x JS1-5V-F relay

1 x 1N4005 diode

1 x NS-AC1200 insignia ac adapter (for the 12V supply)

I am connecting my optocoupler to pin 5 and using this program:

int in1 = 5;
void setup() {
// put your setup code here, to run once:
pinMode (in1, OUTPUT);
digitalWrite(in1,HIGH);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(in1, LOW);
Serial.println(digitalRead(5));
delay(5000);
digitalWrite(in1, HIGH);
Serial.println(digitalRead(5));
delay(5000);
}

With my multimeter, I can see that pin 5 is operating properly and outputting 0 Volts and 5 Volts when low and high, respectively. I can also see that the optocoupler is functioning, but I'm not sure if I have it hooked up correctly. I've tried hooking pin 8 of the optocoupler to the 12V power supply and also not hooking it to the 12V power supply. I've also tried running the 12V power supply through pin 6 of the optocoupler.

I know my breadboard picture isn't great, but I did try to print out the instructables sheet and relabel the components and pin numbers with how I am assigning them and linking things together. Sorry it's handwritten.

Can anybody help me? I'm really stuck.

0334_001.pdf (40.6 KB)

The MC7815C is a voltage regulator, not a transistor. Of course it will not work.

Avoid Instructables -- they are almost all crap, written by people who have no idea what they are doing. Some will lead you to destroy your equipment, and this one is no exception.

The 6N136 optocoupler output is rated for 16 mA maximum. However, with 12V on the collector and 220 Ohms for the base resistor, the output current could be higher than 11V/(220R) = 50 mA, destroying the optocoupler output transistor.

If you want to continue with the circuit, buy a TIP120 transistor, a new optocoupler, and change R2 to 1K. With the 6N136 you MUST connect pin 8 (the photodiode cathode) on the optocoupler to 12V, as suggested in the optocoupler data sheet.