control the position of dc motor with potentiometer feedback using ardunio uno

i have written the code below there are no errors shown but when connected to the motor there is no movement .Can you please tell me if the code will execute.


int pin1=7;
int pin2=6;
int enb=5;
int pot=A0;
int TurnDirection;
enum TurnDirection {right, left};
int M_Speed;
int traget;
int GoToAngle;

void setup() {
pinMode(pin1,OUTPUT);
pinMode (pin2,OUTPUT);
pinMode(enb,OUTPUT);
pinMode(pot,INPUT);
Serial.begin(9600);

}

void loop()
{

int val =600;
analogWrite(pot,val);

}
void SetTurnDirection(int dir)
{
TurnDirection=dir;
switch(TurnDirection)
{
case right:
digitalWrite(pin1,HIGH);
digitalWrite (pin2,LOW);
break;
case left:
digitalWrite(pin1,LOW);
digitalWrite (pin2,HIGH);
break;
}
}
void SetTurnSpeed(int s)
{
M_Speed=s;
}
void Turn()
{
analogWrite (enb,200);
}
void Stop()
{
analogWrite(enb,0);
}

void SetGoToAngle( )
{
int val;
int currentAngle = analogRead(A0);
if (currentAngle<val)
{
SetTurnDirection(right);
}
if(currentAngle>val)
{
SetTurnDirection(left);

}
Turn();

delay(100);
Stop();
}

Your loop() consists purely of setting a value then trying to do an analogWrite() of that value to an analog INPUT pin so the program is never going to do anything useful.

You have several other functions which seem to be trying to do something with a motor driver that you've told us nothing about but they are never called from anywhere so they do nothing at all.

Steve

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html . Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What hardware are you using?
What motor, encoder, motor controller?
How are you powering your project?

Thanks.. Tom... :slight_smile: