• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Controlling a 12v 80 watt dc motor with an Arduino

Pommie

Well-Known Member
Most Helpful 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?
 

Pommie

Well-Known Member
Most Helpful 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.
 

Pommie

Well-Known Member
Most Helpful 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.
 

Reloadron

Well-Known Member
Most Helpful 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.

118799

Next setup your Com Port.
118800

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
 

Reloadron

Well-Known Member
Most Helpful Member
Yay, moving right along. :)

Little by little this project is moving along.

Ron
 

Pommie

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

Mike.
 
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
 

Reloadron

Well-Known Member
Most Helpful 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.
sensorValue = analogRead(analogInPin);
// 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
 
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

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
 

Pommie

Well-Known Member
Most Helpful 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);
    pinMode(analogInPin,INPUT);
void setup() {

}

void loop(){
  // Read the PWM value of the input potentiometer.
  sensorValue = analogRead(analogInPin);
  // 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.
 

Latest threads

EE World Online Articles

Loading

 
Top