how to connect arduino with MOSFET

hello i want to fade 12 volt lamp like fade leds with arduino how to build it, i have this MOSFET 40n03p this datacheat http://pdf1.alldatasheet.com/datasheet-pdf/view/106061/ETC/SSM40N03P.html and 35w 12volt lamp and arduino duemilanove

i want fade in stop 1 sec and fade out what i need and what is the code to do that

thank you

Well the good news is that is a logic level MOSFET so its very easy to interface to.

Choose one of the PWM pins (3,5,6,9,10 or 11 on the normal Arduino’s, Arduino Mega has more) and connect it to the FET gate via a 220 to 1k ohm resistor. For safety also connect the gate to the source with 10k to ensure its switched off by default.

The FET source connects to Arduino ground and to the 12V supply ground. The drain connects to one bulb contact and +12V to the other bulb contact.

Then use analogWrite () on the pin to control lamp brightness, 0 for off, 255 for fully on.

Code something like

for (int i = 0 ; i <= 255 ; i++)
{
  analogWrite (pin, i) ;
  delay (4) ;
}
delay (1000) ;
for (int i = 255 ; i >= 0 ; i--)
{
  analogWrite (pin, i) ;
  delay (4) ;
}

Should fade in for about 1s, stay on for 1s, fade out for 1s.

thank you so much i will try this today, thank you regards

hello thank you so much it's worked and all ok i have translate it to arabic http://reemcreations.com/arduino/%d8%b7%d8%b1%d9%8a%d9%82%d8%a9-%d8%b9%d9%85%d9%84-%d8%aa%d8%a3%d8%ab%d9%8a%d8%b1-%d8%a7%d9%84-fade-%d9%85%d8%b3%d8%aa%d8%ae%d8%af%d9%85-%d8%a7%d9%84%d8%a7%d8%b1%d8%af%d9%8a%d9%86%d9%88/

thank you