First of all, to protect your MCU it's a good idea to use a 33 ohm resistor between your PWM pin and the Gate of the MOSFET or transistor.
While the PWM pin should be either
LOW, there could be situations where your Gate pin can have nothing as input, for example when the MCU is powered off. Therefore it's also a good idea to use a pull-down resistor between
GND and the Gate pin. This ensures that your MOSFET stays off if the MCU is not connect or is powered off.
I would say a 10k ohm or even a 1k ohm would suffice, it depends on the amount of noise and power consuption. Use the 1k ohm on higher-noise environments.
For the sake of your MOSFET protection, unless your current load is higher than the MOSFET's current take or the transistor's Icc, you don't need to worry about it if you are only using it to control LEDs or even lamps. Most MOSFETs can flow up to 3 Amps of current, while normal transistors' aren't that much. Use a current meter to check how much current your device consumes at the highest level (e. g. when all parts of it are turned on at the hgighest level and speed.)
However, you should also consider an extra protection if your device has any kind of a Electromagnetic Coil inside it, like the Solenoids, Motors and Relays.
This is because the coils generate a reverse voltage spike when the power is switched off, which could damage your MOSFET or transistor. This is a side effect called Inductance.
To prevent this, a diode is usually used know as the flyback diode or the kickback diode. It is generally a normal diode which is conncected reverse-biased in the circuit near the consumer device, which allows the reversed current to be looped inside the diode and the device, thus allowing the current to be drained. Wikipedia has a nice article around it.
As for your case, you are planning to use a motor, which has a coil inside it, so try to put a diode near the motor and away from the MOSFET (if possible) to drain the unwanted reverse current.
If you can't put it on the consumer device, at least use it on your PCB along with the MOSFET, it's better than nothing.
I would say a 1N4007 could suffice here, just remember to put it backwards in the circuit (
Anode goes to the
Drain pin of the MOSFET and
Cathode goes to the
VIN of your device. Unlike resistors, diodes must be used in the correct direction.)
Please be sure that you are supplying enough current to your circuit. It's also a good idea to use a 220 μF cap to regulate the
5V input of your ATTiny.
As for the protection against short circuits, you could either:
a) limit the current with a resistor
b) use a resettable fuse.
Obviously, limiting the current here would be a stupid idea, so you could use a resettable fuse to prevent flowing too much current into the circuit.
A Resettable fuse (or PTC) is a device which blocks too much current from flowing until you remove the load and break the circuit; In this case shorting the circuit will flow all of its current through it!
The PTC's discussion goes beyond to the answer of your questions, so try looking it up on Google.
Have a great fun playing with the electronics.
Hope I've helped you!