Controlling DC Motor with Potentiometer [solved]

Hi,

I am busy taking my first steps toward building an RC car. In my current project I am trying to control a DC motor with a potentiometer.

I have started by setting up a circuit with a potentiometer and motor and by doing the necessary coding to accomplish the task. The problem I have, is that, when the potentiometer is turned completely anti-clockwise (so that the analogue reading is 0 on the serial moniter), the motor still rotates at half speed when it should be stationery. Turning the potentiometer clockwise does increase the speed of the motor as it should though.

Here is my code:

const int motor = 5;
const int ptmeter = A0;
const int minReading = 0;
const int maxReading = 1023;
int potVal = 0;

void setup() 
{
  pinMode(motor,OUTPUT);
  Serial.begin(9600);
}
void loop() 
{
  potVal = analogRead(ptmeter);
  potVal = constrain(potVal, minReading, maxReading);
  potVal = map(potVal, minReading, maxReading, 0, 255);
  analogWrite(motor, potVal);
  
  Serial.print("analog value = " );
  Serial.println(potVal, DEC);
}

I have also attached a picture of my circiuit. Keep in mind that the motor is a 3V motor so I connect an external power source.

Obviously I don’t want a RC car that cannot slow down past half speed or that can’t be stationery!

Any help would be appreciated.

Thanks,
Jason

Hi,

Please use code tags.. See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Can you please post a copy of your circuit, in CAD or picture of hand drawn circuit in jpg, png or pdf format.

Also can you keep your picture memory size down please, I notice on your picture only two connections to the pot.
You should have three.

The diode should be across the motor terminals, cathode end to positive on motor, anode end to negative on motor.

It looks like you are across the MOSFET drain to source/gnd. In fact the cathode of the diode needs to be moved to the positive motor supply and it should be fine. The current config explains why you have half speed at zero.

Tom..... :slight_smile:

I think the previous observation about the diode polarity is the reason the motor is still turning. It would help if you could just draw the schematic on a piece of printer paper and take a photo of it and post it.

The flyback diode should ALWAYS go directly ACROSS the INDUCTIVE component, be it a relay , solenoid or motor, with the CATHODE connected to the POSITIVE terminal of the device and the ANODE connected to the NEGATIVE terminal of the inductive device. It looks like your diode is either backwards or it is across the power supply. (can't tell for sure)

I notice on your picture only two connections to the pot.
You should have three.

He has three. The center is a resistor to A0. That is correct.

steinie44:
He has three. The center is a resistor to A0. That is correct.

Why does he need the resistor?

Hi,

I edited my original post and uploaded a new picture (and inserted my code using the hash). I drew my circuit on paper... I really hope I did it correctly.

Thanks for the help so far!

Electrally I think it is ok but the format is upside dowm.
The motor should be at the top of the page and the transistor is always shown below it. I didn't see a flyback diode across the motor.

I am new to this so I apologise for some things not being 100% professional. Could you explain exactly what a flyback diode is?

It's a diode that looks like it's placed wrongly, ie the cathode of the diode is on the +ve of the power supply to the motor. If you're like me, you'll go with the flow, ignore the technicalities, and just remember to put it there to prevent components getting fried when the motor turns off

Attached is a pic of a motor, flyback, transistor and pot all hooked up to an Arduino. I didn’t do it for you specifically, so the pins might not match.

motor and pot.png

What is the difference between that and the 1N4001 diode I have connected? (The black arrow on my circuit is my diode... It isn't very clear)

JayCol:
What is the difference between that and the 1N4001 diode I have connected? (The black arrow on my circuit is my diode… It isn’t very clear)

It’s not across the motor, see attached.

btw… please in future make your pix smaller. 3M is way too big: a hundred k or so is better so it opens fully on the screen with no scrolling. I usually just open pix in paint, resize and save as.

flyback.PNG

Thank you so much JimboZA! It now works perfectly. problem solved!

JayCol:
Thank you so much JimboZA! It now works perfectly. problem solved!

Great.

Also just for future reference, heed what raschemmel said, and have power coming down the page from positive to negative. That's the convention and it makes schematics more generally readable: see eg in my schematic, the position of +ve on the motor at the top and all the grounds at the bottom.

Just for the record, I posted this back in Reply#2. (we're on Reply#14 now).

The flyback diode should ALWAYS go directly ACROSS the INDUCTIVE component, be it a relay , solenoid or motor, with the CATHODE connected to the POSITIVE terminal of the device and the ANODE connected to the NEGATIVE terminal of the inductive device. It looks like your diode is either backwards or it is across the power supply. (can't tell for sure)

Hi, good to hear you got it performing correctly.
Look at reply #1.

Tom..... :slight_smile: