Controlling waterpump speed

Hello,

I'm making a timefountain and I want to control the speed of the 12v pump im using. I'm using a MOSFET to control the pump and a potentiometer as variable input.

I thought a simpel fade script should do the trick but when I turn up the potentiometer the pump only makes a difference between on and off and I can't get control over the speed.

I'm using the following script:

int pumpPot = A2; // Analog input pin for first potentiometer
int potValue = 0; // value read from the pot
int pump = 9; // PWM pin that the pump is on

int ledPot = A0; // Analog input pin for second potentiometer
int led = 5; // PWM pin that the led's are attached to

long onTime = 250;
int minDelay = 1;
int maxDelay = 100;
long strobeDelay = 0;

void setup() {
pinMode(pumpPot, INPUT);
pinMode(pump, OUTPUT);

Serial.begin(9600);

pinMode(ledPot, INPUT);
pinMode(led, OUTPUT);

}

void loop() {
potValue = analogRead(pumpPot);
analogWrite(pump, potValue/4);
Serial.println("hello");
delay(10);

strobeDelay = map(analogRead(ledPot), 0, 1023, minDelay, maxDelay);

digitalWrite(led, HIGH);
delayMicroseconds(onTime);
digitalWrite(led, LOW);
delay(strobeDelay);
}

Does somebody know what I'm doing wrong?

Instead of using delays everywhere, try using time intervals as in the blink without delay sketch.

Simple code to test your PWM:

int pump = 9;  // PWM pin that the pump is on
int led = 13;

unsigned long previous = 0, interval = 20;
byte duty = 0;

void setup() {
  pinMode(pump, OUTPUT);
}

void loop() {
  if (millis() - previous >= interval)
  {
    analogWrite(pump, duty);
    analogWrite(led, duty);
    duty += 1;
    previous = millis();
  }
}

Sorry I might not explained my code right, half of the code is an stroboscope code also controlled by another potentiometer

Only the pump lines are for the pump

This is the code i use to control my pump

int pumpPot = A2; // Analog input pin for first potentiometer
int potValue = 0; // value read from the pot
int pump = 9; // PWM pin that the pump is on

void setup() {
pinMode(pumpPot, INPUT);
pinMode(pump, OUTPUT);

Serial.begin(9600);
}

void loop() {
potValue = analogRead(pumpPot);
analogWrite(pump, potValue/4);
Serial.println("hello");
delay(10);
}

The test code is just to verify if you can get smooth speed control of the pump ... just a quick operational test of your PWM circuitry to see if your pump can smoothly ramp up its's speed. Used the same pin numbers as your code but that's it ... pwm is ramped up slowly over a number of seconds and repeats in a sawtooth pattern.

kaskop:
Does somebody know what I'm doing wrong?

using a blocking function to stop any and all operations while delay is in operation.

@dlloyd

Thanks, I tried the code and i can see the water in the tube "hop" a bit once every 3 seconds but it doesn't make the water flow.

What does this mean?

It means we can't help much further without seeing your circuit (schematic and image would be ideal) and part #s for your components and pump.

I used:
MOSFET: "N-Channel Power MOSFET 2N60 Low Gate Charge 2A 600V TO-251"
Pump: 12V, 4.8W, DC (on the pump is: IP68)
potentiometer: "10K OHM Linear Taper Rotary Potentiometer 10KB Pot with XH2.54-3P Wire BK19"
arduino: UNO R3
external power supply: 12V DC
the arduino is powered by my USB

I don't really know how to draw everything so ill try to describe it as detailed as possible and add photo's.

the positive pole of the pump is directly wired with the positive of the power supply.
the negative pole of the pump is connected to the drain of the MOSFET (middel pin/black wire) the source of the MOSFET (right pin/brown wire) is connected to the negative site of the power supply and to the GND of the arduino.
the gate of the MOSFET (left pin/yellow wire) is connected to the arduino (PWM able pin).

The potentiometers are connected on the other side of the board to the 5V, GND and two analoge pins.

What sort of pump is it ?

It may not be possible to speed control it.

as described im guessing its diaphram at that wattage.

I have a 50 w flojet if i try to speed control it it just gets hot very quickly.

Only way to control pressure is with a spring bypass valve

Edit
mine draws 2 amps approx , if i limit to 1.8 amps it stops

I used this pump:

That has a brushless motor.

Internal electronics do the commutation.
Its not possible to control those.

You can test if your circuit is working with a simple electric motor if you have one

Edit, before i get flamed.

Some brushless motors can be speed controlled but i dont think thats one of them.

Have you tried running it with different supply voltages ?

DC not pwm

The MOSFET you're using can't be controlled properly with a 5V signal on the gate (see fig 2). You'll need to use a suitable logic level MOSFET or NPN transistor. http://aosmd.com/res/data_sheets/AOI2N60A.pdf

Thanks for all the response but i get mixed ideas now

dlloyd:
The MOSFET you're using can't be controlled properly with a 5V signal on the gate (see fig 2). You'll need to use a suitable logic level MOSFET or NPN transistor. http://aosmd.com/res/data_sheets/AOI2N60A.pdf

It does work for my LED's in the same set-up, which MOSFET of transistor should be more suitable?

Boardburner2:
That has a brushless motor.

Internal electronics do the commutation.
Its not possible to control those.

Any idea what kind of pump should do the trick, or is it easier to just use a valve at the and of the hose?

A simpler way to test your programme may be with a 12 v lightbulb,
See if it dims.

An ordinary pump with brushed motor should work

Boardburner2:
A simpler way to test your programme may be with a 12 v lightbulb,
See if it dims.

An ordinary pump with brushed motor should work

If i put the LED's on the MOSFET with this code it dims so the principle works, only the pump doesn't cooperate :stuck_out_tongue:

Confused.

He is pointing out a different problem.

Im saying that you should check that that pump can be controlled before you waste time playing with programming when you might have a perfectly workable programme.

Its fairly easy to check your programming and circuit withe the tests i have described.

Varying the dc voltage into the pump will tell you if its controllable.

You could have more than one problem.

Eliminate the simple ones first.

The 2 main problems to resolve - the type of pump (as mentioned by Boardburner2) and the PWM MOSFET circuit.
Logic Level MOSFET: IRL530

EDIT: Your existing MOSFET circuit will only control a very small amount of current (see figure 2 in the datasheet as mentioned earlier). Compare this with the IRL530 which will switch up to 15A with 5V on it's gate.

Example of a circuit (except they should have used the IRL530, not IRF530): Building an Arduino controlled pump

Yes , led is a low current device.
This iwhy i suggested a light bulb

Further to that , just because the mosfet you have runs the motor on off it does not mean it will correctly switch pwm, you would need a scope for that.

Easier to order a new one.