# Controlling a 12v 80 watt dc motor with an Arduino

#### Pommie

##### Well-Known Member
In the IDE you should be using "Sketch->Upload" - not "Sketch->Upload using programmer".

Also, what does it say next to port on the Tools menu?

Mike.
Edit, can you get a list of connected devices and see if the port exists?

#### Raymond3231976

##### Member
Here is what i got

#### Attachments

• 800.7 KB Views: 4
• 1.2 MB Views: 4
• 955.9 KB Views: 4
• 937.4 KB Views: 3
• 977.8 KB Views: 3
• 995.7 KB Views: 3

#### Pommie

##### Well-Known Member
If you unplug the board does the serial port disappear? It may be that the driver for the CH340 chip isn't installed.

Mike.

#### Raymond3231976

##### Member
Yes when I unplug it the serial port disappears. How would i go about installing the driver

Last edited:

#### Pommie

##### Well-Known Member
Sorry, I've always avoided apple due to them not playing nice with others, so I've no idea how to do anything. Maybe google "Getting stated with Arduino on a mac".

Mike.

#### Raymond3231976

##### Member
I googled it so I’m trying what it says about the driver now

#### Raymond3231976

##### Member
If i cant get it working on my macbook then ill try it on my windows laptop or tablet

##### Well-Known Member
The most common cause of errors like you see is the software is not seeing the hardware. Here is what I suggest. Using the cable provided connect your Arduino to your PC USB port. Assuming Windows open your Device Manager. In the device manager window look at Ports (COM & LPT) you should see your connected Arduino along with a COM ? where ? is the port number.

Now open your Arduino IDE and click Tools and select your Genuino Uno board.

Try what we have so far and when you copy and past the code sample make sure you clear whet is there when you click file new to paste the whole code sample.

My bad on some of this, I see you were using a MAC so I can't be of any help with that.
Ron

ok thanks

#### Raymond3231976

##### Member
Finally got the uno working and I got the H board in the mail today..

##### Well-Known Member
Yay, moving right along.

Little by little this project is moving along.

Ron

#### Raymond3231976

##### Member
The only thing left to get is Resistor 1/4 W Tolerance ±1% 10K ohm 10Kohm .
I should be getting this by the 24 of this month .

#### Pommie

##### Well-Known Member
If you have wired up the potentiometer then you can try reading it and printing it on the serial terminal.

Mike.

#### Raymond3231976

##### Member
I’ll hook it up to in the morning and try that I haven’t assembled anything yet but I’ll hook it all up in the morning and see what it says on the terminal I’m getting the aluminum case for it Sunday

##### Well-Known Member
I just thought about something in the code sample I provided earlier for the motor speed. I have two delays in the code which make things easier to see when the code runs in the serial monitor. Those delays will likely also delay what happens when you adjust the motor speed making the response a little sluggish. Once everything is where you want it I would remove those two delays by preceding each line with //.

Something else you can change is the code is written:
{
// Read the PWM value of the input potentiometer.
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(pwmOutPin, outputValue);

What is happening in the above snippet is we are mapping the input and output. An analog input is mapped to a Digital PWM of 0 to 255 where 0 is no PWM and 255 is 100% PWM. You may wish to change the 0 to 255 to something like 50 to 255 or 100 to 255 just depends on your motor. I am sure you will get the idea. Also note from the code which Arduino pins I used.

Ron

#### Raymond3231976

##### Member
The output on my potentiometer goes from 0 to 1023 on the serial monitor using the sample code analog read serial.

#### Raymond3231976

##### Member
With the code you last gave me i got this error

Arduino: 1.8.9 (Windows 10), Board: "Arduino/Genuino Uno"

sketch_jun13b:1:1: error: expected unqualified-id before '{' token

{

^

exit status 1
expected unqualified-id before '{' token

"Show verbose output during compilation"
option enabled in File -> Preferences.

#### Pommie

##### Well-Known Member
You need a closing brace "}".

Mike.

#### Pommie

##### Well-Known Member
Ron's code needs to be placed in the main function,
Code:
#define analogInPin A0
#define pwmOutPin 2

uint16_t sensorValue,outputValue,percentValue;
pinMode(pwmOutPin,OUTPUT);
void setup() {

}

void loop(){
// Read the PWM value of the input potentiometer.
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);
// map pump speed percent of full scale
percentValue = map (outputValue, 0, 255, 0, 100);
// change the analog out value:
analogWrite(pwmOutPin, outputValue);
}
Note the above code expects a pot on A0 and the output will be on pin 2.

Mike.
Edit added setting the pin modes.