First project - help with code and vibration motor

One thing I'm noticing, based on your little drawing of a transistor: if that's a bottom view of the 2N2222 (it's more likely that it would be a PN2222), then you have your transistor backwards. Reverse the Emitter and the Collector.

Also, several times, decades ago, 1N4001's in circuits similar to this (where the role of the rectifier is to absorb Reverse EMF) wound up failing. Since then, I have always used, at least 1N4004's (maybe overkill but, they cost the same, so why not!).

Update: I just checked Mouser, and it appears that 1N4004 are, actually, less expensive than the 1N4001.