Controlling pump power using potentiometer

Hi I am a newbie!

I am trying to control my pump's speed using a potentiometer however idk how to connect the potentiometer to the circuit, below is the circuit I used and the code I have so far, please help!!

const int Pump = 5;


void setup() {
  // put your setup code here, to run once:
pinMode (Pump, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite (Pump, HIGH);

}```

Potentiometer has three terminals. Hi - connect to +5, lo - connect to Gnd, and (center) wiper - connect to AI. Value will read from 0, full left if wired correctly, to 1023 at full right.
This value can be scaled or used directly to control whatever speed mechanism you're using.

Hey mark,
How can i implement this in the circut i attached above?
Thanks for you time youve been a great help to me!

Basic test sketch.
Leo..

const byte pumpPin = 5; // pin 5, not pump 5

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

void loop() {
  analogWrite (pumpPin, analogRead(A0) >> 2); // write to pump what has been read on A0 and converted from 10 to 8-bit (0-1023 to 0-255)
}

The Arduino is NOT a power supply. You need an external, SOLID PS to do any real work. 20mA/pin with 200mA total for the board makes power management one of everyone's primary concerns.
As long as you buffer the output and the operating current doesn't flow thru the Arduino you should be fine. I normally use motor controllers because I tend to use fractional or full HP motors instead of the little racecar crap that comes in a kit. These typically have a 0-5V in with the max speed at 5V being set by a pot on the controller. THEN you can write code like this:

analogWrite(motorSpeed, analogRead(potentiometerWiper) );

and have a reasonable expectation of it working. Motor controllers also have direction and enables so you'll have

const int motorDirection = xx; // Put your D line here
const int motorOff = yy;  // Ditto, low true enable
const int motorDirSw = zz;  // Direction switch input
//
// In setup()
//
pinMode(motorDirSw, INPUT_PULLUP);
digitalWrite(motorOff, true);  //Force hi while still input to prevent glitch
pinMode(motorOff, OUTPUT);
digitalWrite(motorOff, true);  // LOW makes it run
pinMode(motorDirection, OUTPUT);
digitalWrite(motorDirection, digitalRead(motorDirSw) );

// Later, in loop()
digitalWrite(motorOff, true);  //Don't change dir when running
// delay optional to give motor time to stop
digitalWrite(motorDirection, digitalRead(motorDirSw) );   // Switch controls direction
analogWrite(motorSpeed, analogRead(potentiometerWiper) );  //Pot sets speed
digitalWrite(motorOff, false);  // let 'e rip!

Hi, @karimtamer2
Can you post a proper circuit diagram plase, not a Fritzy picture?
An image of a hand draw circuit would be fine, please include all power supplies, component names and pin labels.

A picture of your project would also help.
What is the spec/data of your pump?

Thanks... Tom... :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.