Controlling a 12v 80 watt dc motor with an Arduino

Status
Not open for further replies.
Sounds Ok so far, the motor will only go one way as theres no software to control the direction so thats expected.
 
ok thanks

Ok so the code should look about something like this so far.
So what would the next step be to get it running or do i need to wait on the resistors first ill be getting the other one
this week on the 20th...

#define analogInPin A0
#define pwmOutPin 5

uint16_t sensorValue,outputValue,percentValue;

void setup() {
pinMode(pwmOutPin,OUTPUT);
pinMode(analogInPin,INPUT);
}

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);
}
 
You should be able to use the pot to control the motor speed. However, the diagrams and screenshots you keep posting are unreadable.

Mike.
Edit, also, whenever you post code use code tags and keep the indenting as it makes it much easier to read.
I.E.
Code:
#define analogInPin A0
#define pwmOutPin 5

uint16_t sensorValue,outputValue,percentValue;

void setup() {
    pinMode(pwmOutPin,OUTPUT);
    pinMode(analogInPin,INPUT);
}

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);
}
 
im still waiting on my other resistors to come in the mail the 20k ohm
Two 10K resistors in series equals one 20K resistor. Also, two 20K resistors in parallel equals one 10K resistor.
I was testing my 10k ohm resistors and they are saying there 10.12k ohm will these still work or did they send me the wrong ones im testing them with a ( 12864 Mega328 ESR Transistor Resistor Diode Capacitor Mosfet Tester )

Resistors have tolerances. A 10K one percent resistor could be anything from 9.99K to 10.1 K. So at 10.12K your resistor is slightly out of spec. You also need to take into consideration the accuracy of your ohmmeter. And, unless it's a $500 plus instrument grade device, I wouldn't trust it's accuracy.

I wouldn't worry about the resistor error in your case. It will just move the trip point a very little bit. If you want to compensate, adjust the threshold numbers in your code.
 
Ok so I just got it all hooked up but when i turn it on the potentiometer .. In the zero position make the motor spin clockwise half way turns off the motor and the other side of the potentiometer it spins counter clockwise the opposite direction.. I've wired it the same as shown in the photo so what do y'all think is going on here ..
 
As I have already said, I can't see what's connected to what in your photo. Can you list each connection on the H-Bridge and what it is connected to?

Mike.
 
here is a link to the photo for anyone who can't see it.
If anyone wants to download it and fix any errors or tell me what they are I would appreciate it..

 
Which bit of "I can't read your photo" didn't you understand?

Forget it.

Mike.
 
Can you also post the actual code you're using so we're not guessing.

Mike.
 
Throughout this project this is how i was told to wire this up

Arduino-UNO
PWM 5. H-BOARD PWM 1
PWM 3. H-BOARD. DIR 1

ANALOG IN
A0. potentiometer . PIN 2
A1. RESISTORS
5V. potentiometer PIN 3
5V H-BOARD
GND. potentiometer PIN 1
GND. H-BOARD.

H-BOARD IRF3205 DUAL MOTOR DRIVER 10A
GND. arduino GND
PWM2. arduino 5V
DIR2. arduino GND
PWM1 arduino. PWM 3
DIR1. arduino. PWM 5
5V arduino 5V

Power + BATTERY
Moter 2 + FAN
Moter 2 - FAN
Moter 1 - PUMP
Moter 1 + PUMP
GND - BATTERY
 
The only bit of code im using is the one you posted

Code:
#define analogInPin A0
#define pwmOutPin 5

uint16_t sensorValue,outputValue,percentValue;

void setup() {
    pinMode(pwmOutPin,OUTPUT);
    pinMode(analogInPin,INPUT);
}

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);
}
 
OK, try the following and see what happens,
Code:
#define analogInPin A0
#define PWM1 3
#define DIR1 5

uint16_t sensorValue,outputValue,percentValue;

void setup() {
    pinMode(PWM1,OUTPUT);
    pinMode(analogInPin,INPUT);
    pinMode(DIR1,OUTPUT);
    digitalWrite(DIR1,HIGH);    //change HIGH to LOW if motor goes wrong way
}

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(PWM1, outputValue);
}

Mike.
 
I'm just on my way out but if the above works then try this,
Code:
#define analogInPin A0
#define PWM1 3
#define DIR1 5
#define BATTERY A1

uint16_t sensorValue,outputValue,percentValue;
uint32_t batteryVoltage;    //32 bit to prevent overflow
uint32_t tick=0;

void setup() {
  Serial.begin(115200);
  Serial.println("\n\n\n\nHello");
  pinMode(PWM1,OUTPUT);       //set the PWM pin to output
  pinMode(analogInPin,INPUT); //set the potentiometer pin to input
  pinMode(BATTERY,INPUT);     //set the battery pin to input
  pinMode(DIR1,OUTPUT);       //set the dir pin to output
  digitalWrite(DIR1,HIGH);    //set it high - change HIGH to LOW if motor goes wrong way
}

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(PWM1, outputValue);
  batteryVoltage=analogRead(BATTERY);
  if((millis()-tick)>100){    //display 10 times per second
    tick=millis();
    Serial.print("Potentiometer Value = ");
    Serial.println(sensorValue,DEC);
    //convert battery reading to voltage (in milliVolts)
    batteryVoltage*=15000;  //*5000*3
    batteryVoltage/=1024;
    Serial.print("Battery Voltage = ");
    Serial.println(batteryVoltage,DEC);
  }
}

This is untested so may have typos etc.
To see the values open the serial monitor menu Tools->Serial monitor and set the baud rate to 115200.

Mike.
 
#56 is a good idea, its possible for the dir pin to 'float' which would mean the motor getting rapid forward & reverse voltages.
And it kinda sound slike from your description thats happening.
 
Change the HIGH on this line to a LOW, and reprogram the 'duino, the motor should go t'other way, then all the hardware functions are operational.

digitalWrite(DIR1,HIGH); //change HIGH to LOW if motor goes wrong way
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…