I sat in on a couple of classes like this where students are learning Arduino for the first time, and I've seen a couple of mistakes that are the most common, which I will try to outline here.
First of all, this is very simple code and it probably works fine, so the question is, why is it not doing what you expect? Some possibilities include:
- You are never reaching the threshold value, so the pump is never turning off. Check your sensor or potentiometer.
- Your motor is directly connected to power, so even if the Arduino is toggling the transistor correctly, it is not interrupting the power to your motor.
- You have other wiring mistakes. Review how a breadboard works and make sure that you aren't accidentally shorting things out or thinking that they are connected when they are not.
- Check your power circuitry. Is the right voltage powering your Arduino and on the right pins? Are you using a different power source for your motor? Is the GND connection to the Arduino and every power supply connected so that everything shares a common ground?
Show us a picture of your schematic, and show us a picture of your physical setup. The problem here is almost certainly a ground wire that isn't connected or another wire that is improperly connected.