6v battery 3v motor

Hi with this same circuit http://luckylarry.co.uk/arduino-projects/arduino-control-a-dc-motor-with-potentiometer-and-multiple-power-supplies/ and code how can i use the potentiometer to have the max output to only 3 volts because my motor is only 3 volts and i have a battery which is 6v..

Will there be a change in code or in the circuit hope somebody can help me with this one thanks a lot. CIRCUIT


int potPin = 0;                           // Analog pin 0 connected to the potentiometer
int transistorPin = 9;                  // connected from digital pin 9 to the base of the transistor
int potValue = 0;                       // value returned from the potentiometer
void setup() {                          // set  the transistor pin as an output
  pinMode(transistorPin, OUTPUT);
void loop() {                           // read the potentiometer, convert it to between 0 - 255 for the value accepted by the digital pin.
  potValue = analogRead(potPin) / 4;    // potValue alters the supply from pin 9 which in turn controls the power running through the transistor
  analogWrite(9, potValue);

say i have a 9v motor and 9v battery the potentiometer adjust the voltage from min to max and i think the min is 0v and max is 9v because you have a battery that is 9v..

The thing is what if i want to only have 3 volts max output when using a 6v battery?. so the motor wont overheat because the motor is only rated 3v. Really need help on this one.

You are reading a value from the potentiometer. That value will be in the range 0 to 1023, representing 0 to 5V.

You divide that value by 4, resulting in a value between 0 and 255. You then write this value to the PWM pin, resulting in turning the transistor off and on many times per second. The mechanical inertia of the motor can't react to the off/on nature of the current flow, so it doesn't start and stop each time the current does. Because the current is interrupted so often, the motor doesn't run at full power/speed.

When the current is flowing, though, the voltage IS 6V with a 6V battery. There is nothing in that circuit that changes that fact. Whether that is bad for the motor, or not, depends on the design of the motor. Typically, it isn't.

If you never have the transistor on more than 1/2 the time, the motor should not have problems. To limit the transistor on time to less than 1/2, never write more than 127 to the PWM pin.

This is easily done by dividing by 8 rather than 4 in the code.

Wow thanks for info this gives me a better understanding of using PWM. I always googled for answers and not satisfied with what i read, now i found it and it's all thanks to you. really appreciate ur help. More power to you and again thanks. :)

Got another question..

what if i want the pot to start at 1v whenever the circuit power up because less than 1v is useless to me. i only want the motor to start at 1v so it spins up as soon as the power is turned on?. Should i map() it out? thanks for the your help.

Should i map() it out?

Or simply add an offset to the PWM value (something around 255/5).

The TIP120 will drop between 1v and 3v (depending on the current taken by the motor) anyway, so you'll need rather more than 50% PWM to run the motor at full speed. Alternatively, use a logic level MOSFET instead of a TIP120, then 50% PWM will be near enough exactly the right value to drop 6v to 3v.

If you want to get exactly full power, use a multimeter to meausre cnumberurrent when running at 3v full speed, say using two aa batteries, then measure it with various pwm levels until the measured current matches, you never know maybe you can get away with a higher pwm level then just map your 0/1023 from the pot to the pwm range

use a multimeter to meausre cnumberurrent

I have several multimeters. I don't believe that any of them have a setting to let me measure that. Whatever that is.

Lol sorry my phone must have typoed, I mean current