Pages: [1] 2   Go Down
Author Topic: DC Motor and Potentiometer positioning  (Read 1613 times)
0 Members and 1 Guest are viewing this topic.
Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey gays i want to make my dc motor to run with a Precision potentiometer. 10 gears left and right when the max or min position its achieved and from reading the serial the motor should position it self
have written some simple code but don't now how to do it further  (didn't make this yet) so heave some understanding and if your could help me further i did it appreciated
Code:
int Enable_A=13;
int Enable_B=8;
int Input_1=12;
int Input_2=11;
int Input_3=10;
int Input_4=9;
int Poti=A0;
int val;

void setup()
{
Serial.begin(115200);
Serial.println("REEDY");
pinMode(Enable_A,OUTPUT);
pinMode(Enable_B,OUTPUT);
pinMode(Input_1,OUTPUT);
pinMode(Input_2,OUTPUT);
pinMode(Input_3,OUTPUT);
pinMode(Input_4,OUTPUT);
}

void loop()
{
while(Serial.available() > 0)
{
char aChar = Serial.read();

if (aChar=='1')
{
Motor_ON();
Serial.print("Motor_ON and running 1_3 ");
Motor_1_3();
Motor_OFF();
}

if (aChar=='2')
{
Motor_ON();
Serial.print("Motor_ON and running 2_4 ");
Motor_2_4();
Motor_OFF();
}
if (aChar=='3')
{
Potie();
}
}
}

void Motor_ON()
{
digitalWrite(Enable_A,HIGH);
digitalWrite(Enable_B,HIGH);
}

void Motor_OFF()
{
delay(100);
digitalWrite(Enable_A,LOW);
digitalWrite(Enable_B,LOW);
Motor_Coast();
Serial.println("STOP");
}

void Motor_1_3()
{
digitalWrite(Input_1,HIGH);
digitalWrite(Input_2,LOW);
digitalWrite(Input_3,HIGH);
digitalWrite(Input_4,LOW);
}

void Motor_2_4()
{
digitalWrite(Input_1,LOW);
digitalWrite(Input_2,HIGH);
digitalWrite(Input_3,LOW);
digitalWrite(Input_4,HIGH);
}

void Motor_Coast()
{
digitalWrite(Input_1,LOW);
digitalWrite(Input_2,LOW);
digitalWrite(Input_3,LOW);
digitalWrite(Input_4,LOW);
Potie();
}

void Potie()
{
val=analogRead(Poti);
Serial.print("Poti = ");
Serial.println(val);
}
« Last Edit: March 08, 2013, 10:16:47 am by THX_RoG » Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25802
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i want to make my dc motor to run with a 10 gang poti links and right
I'm assuming "links" means "left", but "10 gang poti" has me stumped.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

heh ok edited sorry for that it should be Precision potentiometer. 10 gears
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 290
Posts: 25802
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No, sorry still not making a lot of sense (to me anyway).
Are you saying there's a 10:1 gear ratio there?
Or it is a ten turn potentiometer?

Are you saying you're trying to make a DC servo motor?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. yes it have 3600° turn so its 10 turn potentiometer
2. yes over a h-bridge controller
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which bit of the program do you need help with? I can understand your test program.

What is the next step? I think to ask the motor to turn until a specific value is reached on the potentiometer. Initially hardcode the targetvalue in the program, making it dynamic from the serial port (or other source) comes later.

To avoid damaging you potentiometer, you can manually turn the potentiometer and see the motor move or not. Mechanically couple the two together when everything works.

In loop(), when not doing serial (ie when available()==0) check the pot value. If it is less than targetvalue call motorturn one direction. If it is more than targetvalue call motor turn other way.

Check that when you manually turn the knob you can make the motor tun one or other way.

The targetvalue test has to include a dead band, ie the test should be less than magicvalue-5 or greater then targetvalue+5

Logged

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 u help a little now i need to write this code but basic it should look like this arduino read a value from serial.read and then motor turn left or right till my value is true
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
then motor turn left or right till my value is true
You need to be specific here. Which value? What makes the value "true"? (In C, anything that is not zero is "true" - but you mean something else here, I think)

In fact, the more specific and very clear you are, the easier it is to write the program. In fact that is how you write a program. You start of with a vauge idea. Then write a few sentences describing it in more detail. Then change each of those sentences into several with more excruciating detail. And again. And then suddenly you have written it in so small steps, that it is trivial to translate to C.
Logged

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

value its form 0 to 1023 and if the serial.read input its lets see 500 then this while by my true value if the potentiometer "say so"
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

Copenhagen, Denmark
Offline Offline
Edison Member
*
Karma: 32
Posts: 1204
Have you testrun your INO file today?
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That is what I suggested. But take it in small steps. First write a program that calls your motor left/right code if the analogRead() is above/below a fixed value.

Search this forum for "nnnC" - it is a small function I wrote to send decimal values and a command letter using Serial. Good for quick debugging code/prototypes.
Logged

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

One fairly inexpensive setup might be to take a standard servo, mechanically modify it for continous rotation, remove the internal pot and externally connect the 10 turn pot. Connect the pot to the gizmo being rotated and use the servo to rotate the gizmo. The below shows the general idea.

http://www.servocity.com/html/belt_drive_pan_systems.html
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

om trying to write some code but it dont work have no clue
Code:
void Motor()
{
val1=targetval1;
val2=targetval2;
if (targetval1!=targetval2)
{
Motor_ON();
{
if (targetval1<targetval2)
{
Motor_1_3();
}
if (targetval1>targetval2)
{
Motor_2_4();
}
}
}
if (targetval1=targetval2)
{
Motor_OFF();
}
}
im using now 2 potentiometer one its mechanically paired with dc motor and the other its for putting my values 
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you looked at the "knob" servo example in the arduino IDE?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Germany
Offline Offline
Jr. Member
**
Karma: 1
Posts: 80
Arduino in VS MODE
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes im trying to "modifying" this code for my purpose
Logged

UNO,MEGA2560,MEGA2560
Killed:UNO, MEGA2560, ... More to come

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The below code is for servos and different from your motor setup, but it includes a deadband setup that may eliminate position hunting by the motors. In your code you should add printing the generated values and such to the serial monitor so you can see if you are getting what you expect.

Code:
//zoomkat dual pot/servo test 12-29-12

#include <Servo.h>
Servo myservo1;
Servo myservo2;

int potpin1 = 0;  //my pot pin
int potpin2 = 1;

int newval1, oldval1;
int newval2, oldval2;

void setup()
{
  Serial.begin(9600); 
  myservo1.attach(2); 
  myservo2.attach(3);
  Serial.println("testing dual pot servo"); 
}

void loop()
{
  newval1 = analogRead(potpin1);           
  newval1 = map(newval1, 0, 1023, 0, 179);
  if (newval1 < (oldval1-2) || newval1 > (oldval1+2)){ 
    myservo1.write(newval1);
    Serial.print("1- ");
    Serial.println(newval1);
    oldval1=newval1;
  }

  newval2 = analogRead(potpin2);
  newval2 = map(newval2, 0, 1023, 0, 179);
  if (newval2 < (oldval2-2) || newval2 > (oldval2+2)){ 
    myservo2.write(newval2);
    Serial.print("2- ");   
    Serial.println(newval2);
    oldval2=newval2;
  }
  delay(50);
}

Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Pages: [1] 2   Go Up
Jump to: