Diode doubt

i want to no which one i should use and why

Current will never flow through #2; the diode is pointing in the wrong direction. Even if it were pointing in the correct direction it would do nothing but cause a voltage drop when the relay is energized.

#1 is correct. It is pointing in the correct direction; current will not flow through it when the relay is energized. When the relay is switched off it will allow the voltage spike to circulate back to the other side of the coil.

As an aside, your circuit assumes that your relay will not pull more than the 40ma output capability of a single Arduino pin. Make sure your relay meets those specifications or you will need to use a transistor to drive it.

A relay operates by turning electrical power into a magnetic field that attracts an "Armature" that has or moves an electrical contact from one position to another.
When the power is released the magnetic field caused by the passage of the current through the relay coil is concerted back to a voltage of nearly equal energy but reversed polarity and it is this 'Back EMF" or "Inductive Kickback" that must be eliminated as it is not only unnecessary electrical noise but is very damaging to other semiconductors in circuit. The conductive properties of a silicon diode are used to "'Short Out" the reverse or back emf pulse.
The diode parallel diode (across the coil or 1.JPG) is connected such that it doesn't conduct normally, just when thew voltage across it is reversed.
The series diode (2.jpg) has the diode reversed in the drawing but if reversed conducts normally when the circuit is energized and an open circuit when the power is removed, workable but very poor engineering. Either method will work but 1.jpg is preferred as there is no loss across the diode and the back EMF pulse is dealt with by being damped or shorted by the diode.
As Chagrin pointed out there are current restrictions on the individual Arduino pins and connecting any kind of inductive load to an Arduino is NOT ADVISED, even a speaker has a series resistor.
{Edit RKJ}

Bob

but in one

wont the current go to the pin as well as ground?
(parallel ?)

harshvardhan:
but in one

wont the current go to the pin as well as ground?
(parallel ?)

No, recall that a diode can only conduct current in one direction, and will block current flowing through it if the voltage is of the wrong polarity.

Lefty

I think he means that the voltage spike can go both to GND and back to the pin. And that's true, except the spike will never reach the high voltage level that it would reach if the diode were not in place.

I think he means that the voltage spike can go both to GND and back to the pin. And that's true, except the spike will never reach the high voltage level that it would reach if the diode were not in place.

yes , i mean EXACTLY that

so, can u tell me approx how much current goes in back to the pin(with the diode attached)?

harshvardhan:

I think he means that the voltage spike can go both to GND and back to the pin. And that's true, except the spike will never reach the high voltage level that it would reach if the diode were not in place.

yes , i mean EXACTLY that

so, can u tell me approx how much current goes in back to the pin(with the diode attached)?

Perhaps if you check out more reference sources on the topic you can find something that will make it 'click' for you? Try this one:

Lefty