How transistors work...

Another good resource for how to use a transistor as a switch:

It includes things like how to determine if a particular transistor will meet your requirements.