Controlling a fan/cooler

Yep. standart cooler. Can u give me an example of the code? Can i use a potentiometer instead?