Problem with IRF510

Let me start by saying that I'm a novice when it comes to electronics. I'm a programmer by trade, and my experience with electronics is limited to the digital stuff and Ohm's law...

I'm working on a small project where I'm controlling all the lights on a motorcyle with an ATmega128. The purpose of this is to save weight by removing most of the original wiring. Putting all the logic inside the 128 saves a lot of wirint - the original loom is about 4Kg, the replacement less than 1Kg.

I've prototyped this on a breadboard using LEDs to represent the various lights, and I got the software working properly, interfacing with the original switchgear. I'm now trying to hook this up to the lights on the bike (all lights except headlight replaced with lightweight LED lights) using some IRF510 MOSFETs I had. This apparently works fine, but there is a problem - I can't switch the lights completely off. Even with the gate grounded there seems to be a small leak, as there is a constant faint glow in all lights.

I know very little about MOSFETs, or transistors in general. The datasheets doesn't tell me much as I understand very little of them ;) It could be that the IRF510 isn't suitable for my application, I don't know. Any good suggestions on what to do?

I'm not entirely sure without seeing your circuit (nor am I much of an expert but I have had similar issues), but have you tried a pull-down resistor on the transistor's gate?

Or perhaps you have ground issues?

No, I haven’t tried a pulldown resistor on the gate, but I have tried grounding the gate. There was no difference. I will try a pulldown though.

but I have tried grounding the gate

Then a pull down will do nothing for you. In which case the FETs are possibly the wrong way round or they are faulty or your ground is at fault.

Depending on how you like your electrons (virtual or live) you might like to simulate your circuit on something like LTspice, which is free as in beer.

If the simulated circuit works fine but not the real one, there is a difference between what you think the circuit is, and what it really does. Could be how you wired a part, or the part is faulty, like Mike suggested.

If it does the same thing as the physical circuit, you need a new circuit, but you can try stuff on the simulator before you break out the piggy bank and the soldering iron.

Thanks for the tip about Spice, I will try it. I guess it has improved since I used it on my Atari ST in 1992 ;)

It's also quite possible that I got the circuit completely wrong. Here's a crappy Paint-schematic:

I think I solved the problem. Adding a 20K resistor between gate and the Arduino pin seems to work. There is still a very faint glow, but it’s barely visible even in a dark room.

There is still a very faint glow,

There shouldn't be any glow. The faint glow is an indication that something is wrong. Are you sure you have identified the three connections on the FET correctly? A 20K resistor between the FET gate and the arduino pin is not going to do anything on a correct built circuit.

Also you need a current limiting resistor in line with the LED if you are not to fry things.

The pins on the MOSFET is correctly identified, unless the picture on the datasheet is wrong. Actually, I'm quite sure that the MOSFET is wired up correctly, as grounding the gate switch the LED lamp completely off. I don't know why this didn't work before, most likely I didn't connect the gate to ground at all the last time I tried it.

I suspect that the MOSFET is drawing a small amount of current from the Arduino pin even when the pin is low. I tried a 10KOhm pulldown resistor but that didn't make a difference.

The LEDs are actually 12V LED lamps, so they contain the necessary current limiting resistors.

I suspect that the MOSFET is drawing a small amount of current from the Arduino pin even when the pin is low

No a MOSFET has a very high impedance it will not draw anything much.

It could be that the arduino pin is not pulling down completely so try your 20K series resistor and the 10K pull down. That way you will cut down on any residual voltage on the pin with a zero on it. Is the internal pull up enabled? It should be but try disabling it and having a high pull up say 100K.