DC motor 12 volt

Hi ,

I am a new arduino user, I am looking for a code to control multi small pumps running by 12 volt DC. Since 12 volt is required; therefore I have used an external power supply and applied the circuit shown in (http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads) to control the speed of motor through a potentiometer, but I need to switch the pumps on and off through arduino as well as their speed control. I was thinking to use optocoupler to control the pumps operation (ON/OFF) , but I would appreciate if somebody have a simple solution through arduino (circuit and code)

Thanks alot

See this:-


but I need to switch the pumps on and off

For "off", what's wrong with "analogWrite (pumpPin, 0);" ? "On" would then just be "analogWrite (pumpPin, analogRead (potPin) /4);"

Thank you for your suggestion. Actually I am using the following code:

const int potPin = 0; // Analog in 0 connected to the potentiometer const int transistorPin = 9; // connected to the base of the transistor int potValue = 0; // value returned from the potentiometer

void setup() { // set the transistor pin as output: pinMode(transistorPin, OUTPUT); }

void loop() { // read the potentiometer, convert it to 0 - 255: potValue = analogRead(potPin) / 4; // use that to control the transistor: analogWrite(9, potValue); }

Please can you edit the code according to your suggestion.

If you look at the circuit shown in the website which I 've mentioned above you will see the power supply is connected directly to the board, i.e. not through arduino. So do you think the signal through pump pin is active to stop or run the pump. Please advise

Here is the image for the setup

I hate that web site it is so rubbish. You need a resistor in line with the base of the transistor otherwise you destroy your arduino.

Note using the PWM signal acts as a speed control and on/off control. It is hard to write you code as you haven't said what you want it to do. Please read up about PWM signals:- http://www.thebox.myzen.co.uk/Tutorial/PWM.html

Great image by the way!

Sorry, it is my fault ... I 've tried to use (insert image) icon .... I don't know how to do it. Any way .. I need to control the operation of 3 pumps via arduino (motor speed as well as motor ON/OFF). Any suggestions ??

Many thanks

I 've tried to use (insert image) icon .

You put your image on a file shairing web site like Flicker and get a URL for it. You then paste that url between those brackets that come up with the image icon.

So after reading my site and the rubbish one you still don't know what to do? You need a transistor for each motor. You need a resistor in the base to the arduino. Emitter to ground collector to one end of the motor. Other end of the motor to 12V. Diode across the motor and connect the 12V supply's ground to the arduino's ground. Make sure the output pins you use a PWM capable then do an analogue write to them with 0 being off and any other value being on at the speed you want, up to a maximum of 255 which is full on.

Thank you so much for help. Below is the image for the setup:

[http://www.4shared.com/photo/Ii3rIl0Z/pump_motor_dc_12_volt.html ]

I've used the following script:

int pumpPin = 9; void setup(){ pinMode(pumpPin,OUTPUT); } void loop() { analogWrite(9,255); delay(6000); analogWrite(9,0); delay(6000); }

The motor worked fine with maximum speed at (255) and minimum at (0) but I need to stop the motor after a while, i.e. switch the motor ON and OFF through Arduino . Is it possible !! please advise.

Thanks again

If the motor is still running with an analogWrite(0);, then I think there's something wrong with your transistor wiring.


You appear to be using the convention that black is + and red is - this is not at all conventional and it is normal that this is the other way round. Please check that the black wire is +ve.

Can you try the photo from another angle as I can't see the wiring around the transistor.

Please find a link for other pictures:

http://www.4shared.com/photo/iNhQNbkv/IMG_1311.html http://www.4shared.com/photo/4kuBNugf/IMG_1312.html http://www.4shared.com/photo/AQmxSsvM/_2__IMG_1313.html

The black wire is positive .. Thank you

Thanks for every body comments. The circuit is now working fine after changing the board.