user18905: I'm using my Arduino to control a relay switch, which has an extension cord attached to it (see photo).
The relay is connected to the Arduino via pin 9, which is set to pinMode(9, OUTPUT);
Do I need any resistors or capacitors or diodes attached to this? Almost feels too simple, given I'm running AC power through the relay. But maybe no?
It definitely works, but I want to make sure I'm not going to burn something out (or down).


user4143: Yes, that is too simple.
The Arduino's IO pin is not designed to directly drive a relay. It needs to go through a transistor first, and you must include a diode to absorb the back-EMF generated by the collapsing magnetic field.
Google for "Arduino Relay" and you will find hundreds of thousands of examples.
In short, the circuit you need to create is this:


18905: <p>I'm using my Arduino to control a relay switch, which has an extension cord attached to it (see photo).</p>

<p>The relay is connected to the Arduino via pin 9, which is set to <code>pinMode(9, OUTPUT);</code></p>

<p>Do I need any resistors or capacitors or diodes attached to this? Almost feels <em>too</em> simple, given I'm running AC power through the relay. But maybe no?</p>

<p>It definitely <em>works</em>, but I want to make sure I'm not going to burn something out (or down).</p>

<p><a href="https://i.stack.imgur.com/N13sD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/N13sD.png" alt="enter image description here"></a></p>
 4143: <p>Yes, that is too simple.</p>

<p>The Arduino's IO pin is not designed to directly drive a relay. It needs to go through a transistor first, and you must include a diode to absorb the back-EMF generated by the collapsing magnetic field.</p>

<p>Google for "Arduino Relay" and you will find hundreds of thousands of examples.</p>

<p>In short, the circuit you need to create is this:</p>

<p><a href="https://i.stack.imgur.com/42Shn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/42Shn.png" alt="enter image description here"></a></p>
