is my optoisolator broken or is it me?


I have an atmega328 connected to an lcd and a optoisolator (SparkFun Opto-isolator Breakout - BOB-09118 - SparkFun Electronics) which is connected to a relay (SparkFun Beefcake Relay Control Kit (Ver. 2.0) - KIT-13815 - SparkFun Electronics), the idea is to eliminate switching noise from the relay which is garbling the lcd.

When connected up as bellow id expect the isolator to mirror the switching of pin9 in out1 but at the voltage supplied by Hv (5v). This does not seem to happen.

Pin9 outputs 3.8v, Hv is a constant 5v but out1 peaks at 1.8v and is insufficient to trigger the relay.??

I expect there is an obvious c***up somewhere, any help thanks

On the atmega side of the isolator:
gnd - atmega gnd
in1 - pin d9

On the relay side of the isolator:
Hvg - gnd of separate 5v power supply - relay gnd
Hv - 5v of separate 5v power supply - relay +5v
out1 - relay ctrl

Instead of wiring so that the relay is in the emitter of the optoisolator, move it to between 5v and collector.


Sorry I think im having a slow day :frowning:

When the power is connected but not the relay the isolator seems to function correctly, Out1 mirrors the movements at In1 but at the 5v supplied via Hv. When the relay Ctrl wire is connected to Out1 the voltage drops to 1.1v and barley lights the relay led.

Schematics are attached in case I didnt describe correctly. The PS is 5v 1000mA rated and the relay requires 3.75v 185mA to activate.



Optoisolator-v12.pdf (11.8 KB)

RelayBoard-Large-v16.pdf (30.5 KB)


Looking at the proper circuits of the modes I see that:

A HIGH from your Arduino into the optoisolator turns on the LED which in turn, turns on the opto transistor that turns off the Q1 transistor. This applies HIGH to the relay module transistor and turns the relay on. This assumes correct voltage on HV and RAW on there respective modules.

Your rough drawing does not show any power connected to the relay module.



Thanks for the circuit explanation, this is as id suspected, unfortunatly I cant see why the isolator output drops when connected to the relay ctrl?

If the relay is connected only to the 5v ps switching can be performed by connecting ctrl wire to 5v. ok good
If the isolator is connected only to the ps and arduino it outputs 5v on O2 mirroring I1. ok good
If isolator, relay and ps are connected without the ctrl wire (relay ctrl - opto 02) O2 output is correct. ok good
If the ctrl wire is connected (ctrl - O2) the voltage output drops and is unable to operate the relay. bad!!

Ive tried both channels of the isolator, changed the ctrl wire in case of shorts but always the same behavior: works fine until ctrl wire is connected then 1.1v output fails to switch the relay. If id damaged transistors id expect an alway on/off problem. The power requirements of the relay + isolator cant be browning out the ps. So why the voltage drop?

Sorry but Im not sure I understand about the diagram, the switching side of the relay is powered as shown? via the 5v PS as is the Hv connection of the isolator. The load side isnt drawn but the relay does not require a load for the switching mechanism to operate.


When tho opto transistor turns off, there is a 10k R from the HV to the output pin. If nothing connected to it, the multimeter will read the HV. When the relay board is connected, there is a 10k from the HV, a 1k R into the base of the relay board Tr and the base of the Tr.

This gives a voltage divider of HV to 10k, to 1k and B-E junction. I would expect a voltage of about (very roughly) 2v at the connector.

Your photo of the connections is far too blurry to be of any use.

Please confirm you have power of the correct voltage connected to the relay board.



I believe the correct voltages are supplied to the relay board with the exception of the CTRL pin.

The relay is a 005 model so requires 3.75v to pickup, its rated for 5v but recieving 5.22v.
The isolator would seem to be within any breakdown voltage ranges but may be oversupplied on the IN terminal? as it receives 3.6v and the input forward voltage max is 1.5v
The datasheets for the boards are attached.

How im understanding the voltage divider created by the resistors running from Hv to relay Tr and Grd (i.e. 10k + 1K vs 10k) is 5.22*(11/10+11)=2.7v entering the relay Tr base but this does not match readings which are 0.76v when high. Neither are enough to activate the relay (3.75v). All the relay resistors seem to be the correct values.

That I cant calc the readings im getting suggest I dont understand something here or its busted? :frowning:
If it wasnt for this I would consider replacing the base - ground 10K with 20K to up the voltage to the relay base [5.22*(11/11+20)=3.85v].

Thanks for your help

ild205t.pdf (115 KB)

Relay.JQX-15F.pdf (212 KB)

Is this what you’re trying to do?
(see attached)

The 0.7v you are measuring on the base is the fwd voltage drop of the BE junction. It is as expected.

Have you measured the voltage across the relay coil?



the idea is to eliminate switching noise from the relay which is garbling the lcd.

Sorry, but the first question should have been...
What was your circuit like that had the relay garbling problem.
Can you please post a copy of your circuit that had the problem, in CAD or a picture of a hand drawn circuit in jpg, png?

Did you have a reverse biased diode across the relay coil?
Did you drive the relay directly from the arduino output, or use a BJT or MOSFET driver?
Have you put bypass capacitors on the supply to the LCD?
How long are the wires from the arduino to the LCD?

I assume you have a UNO controller.

Can you post a picture of your project so we can see how you have layed everything out please?

What is the application?

Thanks.... Tom..... :slight_smile:


Sorry, long rambling post.

@ Runaway Pancake. Yes, ive connected both Hv and RAW to a single 5.22v ps that is separate from the atmega chip supply.

@ weedpharma. Assuming I have the right terminals the relay coil voltage is 0-1.34v. The voltage across the coil diode is 0-1.35v so this seems right.

@ TomGeorge. The original circuit was Uno based (see sketch) directly switching the relay which controlled a main water pump, probably not recommended?. When the relay switched often the lcd would garble with non text characters. Initially I tried using two ps (relay and uno), swapping the CTRL wire with a diy two strand twisted wire with tinfoil shielding. Essentially the easy to do from

There is a diode in the relay board, I understand this prevents discharge from the coil when switching?

The relay is driven directly by uno as the pin output onto CTRL was sufficient to switch the relay, current circuit has an optoisolator in between and uses atmega328 (pics) and no longer switches the relay. Is the advantage of the bjt/mosfet to step up the output switching voltage?

The wires are ~6inch breadboard connectors.

I have not included a bypass cap for the lcd, it doesnt seem like there is one in the board(pdf). Im guessing the cap would be installed connecting the lcd +5v to gnd? and reduce the surge entering the lcd. I will look into this after the isolator is working unless it is easy to size it? I had previously looked at including a snubber across the mains load but is seems there is a bit to understand about their design and sizing. Please correct any confusions here.

A general query. If the surge scrambles the lcd memory surely it must also be possible to corrupt data in the uno/atmega memory or slowly degrade the chips performance it in some way?

Thanks for your helps





1602+LCD+Shield+Sch.pdf (163 KB)


@ weedpharma. Assuming I have the right terminals the relay coil voltage is 0-1.34v. The voltage across the coil diode is 0-1.35v so this seems right.

Sorry this is not right, the voltage across the coil diode should be 5V, have you got ALL the gnds connected together?
When you activate the relay and get 1.34V, what is the RAW input voltage measurement?

The relay assembly is shown as needing assembly, did you assemble it, if so is the coil diode in the right way?

Tom..... :slight_smile:


The diode is the right way round and the relay works fine when not connected to the isolator. If the CTRL is connected to the +5.2v (RAW) line you get a steady 4v across both diode and coil.
The relay also works when connected directly to the Uno and recieved 3.4v onto the CTRL line and 4.6v on RAW.

If I measure diode - gnd then its 5.17-5.2v from the cathode and 3.8-5.2v from the anode. Sorry but the 1.34v 'across' was anode to cathode.

What I dont get is both boards work in isolation but not when connected together.

As I understand it when the two are connected the 10k R on the isolator Out is linked to the relay board Ctrl and rebalanced the voltage divider to provide a lower voltage to the relay Tr.

Unfortunately the voltage observed is much lower than what is calculated (i.e. 1.15v rather than 2.7v). Why the difference?

I could ignore it, remove the 10K R in the relay board and replace with 20K to get a higher V into the relay Tr base but I really want to know whats going on with the voltage difference, where is it going?


You know, your drawings all have designators associated with the components.
It would aid intelligent discussion if you refer to the designators (R1, Q2, etc.) in your accounts and inquiries.

Fair enough,

As I understand it when the two boards are connected the Isolator R6 is linked to relay board Ctrl and rebalances the voltage divider R2, R1 to provide a lower voltage to the relay Transistor Q2 but it is 1.15v rather than the 2.7v calculated. Why the difference?

Replacing Relay R1 with a higher value should provide a higher voltage at Q2 but I would like to know what the problem is before I try to fudge a solution.


What voltage do you measure

From the anode of the coil diode to gnd?
From the cathode of the coil diode to gnd?
From the base of the relay switching transistor to gnd?

When you have tried to turn on the relay via the opto.



When the relay is activated by the isolator the on/off voltages are:

From the anode of the coil diode to gnd: 3.8 - 5.22v
From the cathode of the coil diode to gnd: 5.16 - 5.22v
From the base of the relay switching transistor to gnd: 0.75 - 0.01v

Just incase its important the signal supplied to the isolator is generated via a simple sketch on the atmega and output on a digital pin.


I don’t know if you are using Q1 or Q2, but I think you need to change R5 (if OUT2) or R6(if OUT1) to a lot lower value - put 1k in parallel with it.
Right now you have approximately squat (<1mA) for base current into the relay transistor (the “Q2 2N3904”).

the idea is to eliminate switching noise from the relay which is garbling the lcd.

I commend everyone who has had the patience to stay on this post. I for one would like to see a schematic of the circuit that included the LCD that was alegedly garbled by the relay, including the relay and everything else that was connected at the time. I would be especially interested to see if there were any filter caps on the power bus , for the LCD and/or the relay.

This , BTW, is not uncommon with breadboarded circuits built by people who have never heard of capacitors.

If it were me, I would separate the LCD power from the relay power. I frankly don’t see how a relay running off one power source can glitch an LCD running off a separate power source. It seems a no brainer. I have witnessed garbage on an LCD running off a power supply plugged into an AC outlet that an electric drill was plugged into . I am surprised a relay could cause the same symptom. I think I would start at the source and put a large cap on the relay power . If that didn’t work I would add a cap on the LCD power bus. If that didn’t work I would separate their power sources.

If you look at Runaway Pancakes schematic (ATTACHED) , you will see that there are 4 stages there , each with their own power source, (not counting the mysterious switched “LOAD” at the far right).
STAGE-1 : This is obviously the arduino , where “IN1” and “IN2” are driven by arduino outputs.
STAGE-2 : This is the secondary side of the dual optocoupler , isolated from the arduino side, having both separate Power source (“HV”) and GND.
STAGE-3 : This is the relay stage , having a common GND with the SECOND STAGE via PIN-1 of the connector, but having a separate power source “RAW” which powers the relay which switches some
UNKNOWN load (undoubtedly the AC device which is feeding back to the LCD power supply)
STAGE-4 : The “Load” (JP3) is some unknown device that is ultimately the reason for the existance of the first three stages. The OP has omitted both the schematic of how the LCD was connected (which stage ?) AND the nature of the mysterious “Load” . What EXACTLY is the “Load” ? Is it possible that the garbage on the LCD is not caused by the relay coil switched by Q2 but in fact by the current surge of the “Load” when it is turned ON/OFF ?
Will we ever know ?
What is STAGE 1 ? (ie: arduino GPIO ?)
HV = 5V
What is RAW ? (VOLTAGE ?)

Why do we have to ask all these questions ? (Why is this information not provided in original post ?)

Out-1 is pulled up by the 10 k resistor when the transistor is off and pulled low by the transistor.
Out-2 is connected to a transistor base resistor.

Can you try this for me please.
Just using the relay board, and the 328 controller on the protoboard, nothing else.
Connect Pin1 of the relay to gnd of the board/328.
Connect Pin2 of therelay to the output pin on the 328.
Connect Pin3 to 5V on the supply.
Then write a simple sketch to turn the relay on and off every 5 seconds.

Then tell me what happens, no LCD or other components added.
Lets get this relay working first.
Post a picture of it as well please.

Tom… :slight_smile: