Scratching my head. Motor controller

I'm using a H-bridge motor controller to control a linear actuator with potentiometer position feedback.

Here is the code:

int actpos; //actuator position off blue wire
const int motA = 10; //motor A trigger
const int motB = 12; //motor B trigger

void setup() {
// initialize serial communications:

pinMode(motA, OUTPUT);
pinMode(motB, OUTPUT);


void loop() {

digitalWrite(motA, HIGH);
digitalWrite(motB, LOW);


actpos = analogRead (A3);


digitalWrite(motA, LOW);
digitalWrite(motB, HIGH);



actpos = analogRead (A3);


But when I run it, it doesn't do anything like I expected. First it pulls the actuator all the way in and waits two seconds Then it moves it out slightly waits a tiny bit, moves it OUT again slightly, waits a tiny bit, moves OUT slightly again, over and over until fully extended. Then retracts and waits two seconds. How is this possible with the above code? I'm completely flummoxed.

The purpose of the program was to try to brake the actuator. Right now, it turns on the motor, but when the pins go high high, the motor coasts to a stop. I need it to brake. But it keeps going! I'm lost.

Hi, what do you expect this program to do?
You only have one input which is the feedback, you need another analog input which you use to tell the actuator where to stop.

What your actuator is doing at the moment is almost what you have programmed.
You are not using the feedback at all. Also you only need to read it once in the loop.
Can you post a picture of your project and a pic or CAD of your circuit please.

Hope to help....Tom.... :slight_smile:

You seem to have started a second thread on the same topic - not helpful, best
to keep everything together: