N-channel mosfet

Ive got the irf510, a logic level n-channel mosfet. The gate is connected to 3.3V with a 340ohm resistor in between, the drain to the cathode of an led (which is connected to 3V with a resistor in between) , and the source to ground. There is a 3.9K ohm resistor between gate and source.

When I connect base 5V the light is much brighter than when I connected to 3.3V. Why? In the datasheet it says that the Vgs(th) is 2-4V.

And i know there should be a resistor in between gate and 3.3V, but what should its value be?

http://www.irf.com/product-info/datasheets/data/irf510.pdf

That is not a logic level mosfet. Its barely turning on at 3.3v and can only conduct a few milliamps at best.

Look at Rds(on), not Vgs(th):

2017-04-04_13-25-12.jpg

.

For 3.3V, you can use e.g. an IRF3708. They seem to be one of the best hobbyist general purpose devices that are cheaply China-available. IRLZ44N also work, but are inferior in most regards.

Yep. The irL (note the L) irL is the logic level one. Not the IRF.

eg. IRL540

Mostly, but the suggested IRF3708 is logic level.