I have recently made an internet controlled switch with an arduino mkr1000 and the software part worked just fine. I'm new to electronics and i have a few questions for the wiring part. I have a opto-isolated relay module (datasheet) which have 2 power pins operating at 5V and 2 logic pins. I power both the relay and arduino separately with a 5V power supply and i've connected directly the logic wirings (mkr1000 work at 3.3V). I've tried putting a led for protection just because i had no other diodes but it seems it drains too much current and the relay does not work. I've searched on the internet but the aswers related on using a transistor and a diode consider using the same power supply, does a separate one change something? I got all the stuff working but is it safe to drive a relay like this? Do i have to add a diode or a transistor?
If the relay is already opto-isolated, you may very well not need any sort of diode for dumping the coil's stored energy. If you want an led for indication, simply put it in parallel with the data pin and ground with a resistor for current limiting.
The use of diodes for non-isolated relays is very important in preventing the coil from sending a voltage spike back to the chip when the signal is removed. as you energize the coil, current will begin to flow and the coil builds up a magnetic field. when you remove the voltage, the current can't stop instantly, and will build up a charge on the negative terminal of the coil (technically backwards because real charge is primarily provided by electrons which have a negative charge). if there is nowhere for this charge to go, it can build up a relatively large voltage (on what is supposed to be your ground pin). putting a diode across the coil so current can flow from the negative terminal to the positive terminal allows this the current to flow in a loop through the coil and the diode to dissipate more slowly. there will still be a voltage generated at the negative terminal, but it will be limited to the turn-on voltage of the diode.
for more information on relay protection diodes, see wikipedia...