Problem in DC motor to Servo using TA7291P Driver and a potentiometer

I want to control DC motor with a TA7291P Driver. I had connected DC motor and Potentiometer such that one complete rotation of DC motor shaft will rotate potentiometer shaft by one complete rotation.

I have written the code so that whatever position the dc shaft will be in it will it should come back to zero position. But I am making some mistake. I am posting my code alongwith. Kindly, suggest me where I am going wrong.

Any help will be appreciated.

Best regards

The code:

const int numReadings = 20;

//pot Variable
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
int inputPin = A0;
const int pot_signal = 0;

//servo Variable
const int motor_Pin1 = 7;
const int motor_Pin2 = 8;
int angle_turned;
int data,j=0;

void setup()
{
Serial.begin(9600);
// initialize all pot the readings to 0:
memset(readings, 0, sizeof(int)*numReadings);

//to bring dc shaft to 0 position
initialise();

pinMode(motor_Pin1, OUTPUT);
pinMode(motor_Pin2, OUTPUT);

}

void loop()
{

}

int pot_read(){

for (readIndex = 0; readIndex < numReadings; readIndex++) {
total = total - readings[readIndex]; // subtract the last reading:
readings[readIndex] = analogRead(inputPin); // read from the sensor:
total = total + readings[readIndex]; // add the reading to the total:
}

average = total / numReadings;
Serial.println(average);
return(average);
}

void initialise(){
int pot_val= pot_read();
Serial.println(pot_val,DEC);
while (pot_val =<1023 || pot_val>=1){ //check position of POT
if (pot_val>512){
cw();
}
else
{
ccw();
}
pot_val= pot_read();
}

Brake();
}

void cw() //rotate clockwise
{
digitalWrite(motor_Pin1, HIGH);
digitalWrite(motor_Pin2, LOW);
Serial.println("motor turns left now");
}
void ccw() //rotate counter clockwise
{
digitalWrite(motor_Pin1, LOW);
digitalWrite(motor_Pin2, HIGH);
Serial.println("motor turns right now");
}
void Brake() //Stop turning
{
digitalWrite(motor_Pin1, LOW);
digitalWrite(motor_Pin2, LOW);
Serial.println("motor stopped turning");
}

You have to call your 'initialize()' function from setup() or loop() if you want it to do anything.

What happens when you run the program ?

How is the motor powered and how much current does it take ?

@johnwasser

Sir, I called initialize() function in setup(), because i want to run it one time.

@UKHeliBob
Sir, When i run the code it detects that the pot is not in zero position and it calls cw() function. This I am sure because it prints "motor turns left now", but the dc motor do not rotate.

The Dc Motor draws 0.4 A of current and the it is connected to the TA7291P motor output. Arduino is used to operate the signals to the TA7291P chip.

but the dc motor do not rotate.

Forget all about the more complicated stuff and concentrate on getting the motor working when controlled from the Arduino. Write a small program to make the motor run continuously in one direction.

The Dc Motor draws 0.4 A

Is the power for the motor supplied by the Arduino or from another source ?

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?

Can you please post a picture of your project?
So we can see how you have layout your components.

Thanks.. Tom.... :slight_smile:

@UKHeliBob

Sir, I have tried simple codes and was successful in controlling DC motor direction of rotation.

The DC motor power is provided by external power supply. Only the chip is controlled by Arduino.

@TomGeorge

Thank You Sir, for the suggestion. Surely from next time onward, I will follow the instructions.

I have attached the setup's image file and circuit diagram.

The circuit Diagram image is saved from Internet and I can control the direction of dc motor.

My air is to control position of DC motor for feedback I have attached a potentio-meter.

Best regards

In the Fritzing image the GND of the Arduino seems to be connected to the external battery negative and the 5V output of the Arduino may be connected to the positive of the external battery.

Am I interpreting the diagram correctly ?
What external voltage are you using ? It seems to be about 3V

@UKHeliBob

Dear Sir,

GND is connected to negative terminal of battery and the 5V output of arduino is connected to 7th Pin of chip whereas the positive terminal of battery is connected to the 8th pin of the chip.

The external voltage is 12 V.

best regards

Thank You all,

For helping me through out. I have solved the problem.

Best regards
Nayan Jyoti Baishya

Hi,

Can you tell us how it has been solved, anyone looking for a solution to a similar situation in the future would be grateful.

Thanks.. Tom.... :slight_smile: