Help on using 10K? potentiometer on DC motor via Arduino Uno

Hello,

I'm building a project that's very similar to this --> http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads

just like stated in this website. I'm doing this for a short project.

I did everything that was in that website but when I try to rotate and adjust the 10K ohms potentiometer, the DC motor seems to be spinning in same rate regardless of whether I increase or decrease the load from the 10K potentiometer. It's not supposed to happen because if I increase the load on the potentiometer, the DC motor is supposed to rotate fast but if I decrease the load on the potentiometer, the DC motor is supposed to slow down but it doesn't seem to do any of that.

So how can I fix this to make the DC motor run (fast or slow) depending on how I adjust the potentiometer?

Here is the video btw

Here is the code btw

#include <Wire.h>


const int transistorPin = 9;    // connected to the base of the transistor

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

 void loop() {

   // read the potentiometer:
   int sensorValue = analogRead(A0);
   // map the sensor value to a range from 0 - 255:
   int outputValue = map(sensorValue, 0, 1023, 0, 255);
   // use that to control the transistor:

   analogWrite(transistorPin, outputValue);
   digitalWrite(transistorPin, HIGH);
   delay(1000);
   digitalWrite(transistorPin, LOW);
   delay(1000);


 }

I would appreciate the help and thank you in advance.

   analogWrite(transistorPin, outputValue);
   digitalWrite(transistorPin, HIGH);
   delay(1000);
   digitalWrite(transistorPin, LOW);
   delay(1000);

Why do you write the pin HIGH and LOW? That turns on the Motor full on, then full off.
Get rid of the digitalWrites, and the delays. Let us know how it works.

Also, using the map function to divide by 4 is overkill.

So I got rid of the digitalWrite HIGH and LOW and got rid of delay and only using this portion of the code but now the dc motor driver doesn't run at all...

const int transistorPin = 9;    // connected to the base of the transistor

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

 void loop() {
   // read the potentiometer:
   int sensorValue = analogRead(A0);
   // map the sensor value to a range from 0 - 255:
   int outputValue = map(sensorValue, 0, 1023, 0, 255);
   // use that to control the transistor:
   analogWrite(transistorPin, outputValue);
 }

so how should I make the code so that the DC motor will run according to how I adjust the 10 K potentiometer?

Once again, thank you for the replies.

Put in a print statement to see what value you are sending to the pin.

It gives me errors when I print in statements of what I'm sending to the pin.

I tried doing this code that I found online... which seems like it would be able to drive the 10 K potentiometer to control the DC motor

but even this doesn't seem to work...

#include <Wire.h>


 const int potPin = 0;           // Analog in 0 connected to the potentiometer
 const int transistorPin = 9;    // connected to the base of the transistor
 const 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);
 }

^ It gives me this error immediately

"assignment of read-only variable 'potValue'

sketch_mar25a.cpp: In function 'void loop()':
sketch_mar25a:13: error: assignment of read-only variable 'potValue'
"

what would I have to change in the code to make it run?

You define pot value as a constant and then you try and change it. Ofcourse that will give you an error.

^ I took off the "const" and now it seems to work although the DC motor doesn't run as fast but nevertheless it works now when I adjust and change the 10 K potentiometer, the DC motor seems to run according to how I change the 10 K potentiometer.

Thank you for the help everyone who replied, I really appreciate it once again.

DC motor doesn't run as fast

Could be due to the transistor voltage drop when saturated, or running the transistor unsaturated, or an insufficient power supply.

Does the motor run faster with the HIGH and LOW in the code?
If so it could be you are not getting the full range to pass to the analogWrite().

^ yes the motor does run little fast on the HIGH and LOW part...

how do I allow full range to pass to the analogWrite()?

so is there any way for me to have the resistance input (10K potentiometer) to be shown on screen ?

like when I twist the knob of the 10K potentiometer to vary from 1K to 10K, can I get a resistance input shown
on serial input? and what about the speed of the dc motor? can it be shown on the serial input as well ? if so
how would I do that? Instead of having to rely on tachometer or speedometer, I want the outputs to be shown
on the serial monitor.

and my DC motor runs but if I use a toothpick or some outside interference friction applied to the spinning dc motor,
will I be able to have a code to allow the microcontroller to regulate more energy to the DC motor to spin more
harder if I apply outside interference? is there a code that allows me to do that?

so is there any way for me to have the resistance input (10K potentiometer) to be shown on screen ?

I said a few posts back, use a Serial.print() statement to display the reading you get from the analogue input pin.
That should change from 0 to 1023. If you divide this by four you get a range of numbers from 0 to 255. This is the number you pass to the analogue write on the PWM pin controlling your motor. See:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

and

http://www.thebox.myzen.co.uk/Tutorial/PWM.html

Grumpy_Mike:

so is there any way for me to have the resistance input (10K potentiometer) to be shown on screen ?

I said a few posts back, use a Serial.print() statement to display the reading you get from the analogue input pin.
That should change from 0 to 1023. If you divide this by four you get a range of numbers from 0 to 255. This is the number you pass to the analogue write on the PWM pin controlling your motor. See:-
http://www.thebox.myzen.co.uk/Workshop/Motors_1.html

and

http://www.thebox.myzen.co.uk/Tutorial/PWM.html

I did try that before but it's giving me blank screen on the serial monitor.

Then you are not doing it right or the program is never getting to that part of the sketch.
Did you have a Serial.begin in the setup function?
Is the arduino's serial monitor set at the same baud rate as you put in the Serial.begin() statement?

Grumpy_Mike:
Then you are not doing it right or the program is never getting to that part of the sketch.
Did you have a Serial.begin in the setup function?
Is the arduino's serial monitor set at the same baud rate as you put in the Serial.begin() statement?

For some reason when I did it again, it worked this time...

Do you know how I can output a graph from serial monitor? Is it possible with Arduino Uno,

say... for example I wanted an output of a dc motor speed shown on graph (graph of speed of dc motor) from serial monitor, will it be possible?

I try to search for codes for "know how" on that matter but I couldn't find anything on that.

Do you know how I can output a graph from serial monitor? Is it possible with Arduino Uno

Basically no.
You can output the date to Processing that can draw a graph.

is there a sample code where I can get the arduino uno to spit out the speed of the dc motor to the serial monitor screen?

I been looking for examples everywhere but couldn't find it. Is there a sample code where I can get arduino Uno to show the (rpm) speed of the
dc motor (the values) and have that shown on a serial monitor?

Is there a sample code

What is the difference between sample code and code that does exactly what you want to do?
There is plenty of sample code that shows the Arduino sending data to processing and processing drawing a graph. There is probably not one that meets your specific requirements because there are many ways of expressing the speed only one of them is RPM.
How do you have the speed measurement at the moment? How is this calibrated into RPM?

^ well I thought if there is a sample code then it can help me start somewhere.

And as of now, I'm interested in getting the speed of the dc motor and have the values shown on serial monitor. Since making graph from that seems impossible, I will just focus on getting and obtaining the values of the speed of dc motor.

I guess it's something I would have to look for myself then.