Go Down

Topic: Arduino 12VDC motor controller with limits (Read 474 times) previous topic - next topic

Vernon333

Hi all,

I am planning on making a controller board for a small goods lift. The motor is a standard 12VDC +/- 60W geared motor (windshield wiper motor). I had a look at a youtube video on how to make a low cost H-bridge that can handle up to 10A which would be sufficient for this application.

LINK TO H-BRIDGE VIDEO: https://www.youtube.com/watch?v=zwvw9JhtReg

My knowledge on coding is close to zero, but I have fairly good mechanical knowledge to make the mechanism and my electronics experience is on a level that I think I could put the right components on a piece of vero board to make it work. So I need someone generous to help me write code to make this work.

I would like to have it work as follow:

The system should be activated with 1 push button. 1 press makes the motor turn (for argument sake clockwise) another press of the button will stop the motor and if you press again the motor will reverse direction (counter clockwise in this example)

There should also be 2 limit switch inputs, so lets say the top limit is reached, the the motor should stop and if the button is pressed, the the system should go the opposite direction/down and vice versa. Am I explaining the operation right?  :)

Then a nice to have would be to have another two inputs for another 2 limit switches or even hall effect sensors placed just before the limit to have the motor slow down before it stops on the limit and when it starts, it starts slowly and ramps up to full speed when it passes the "slow down" sensor. This would just make the operation look smoother.

If I can get this right, phase two would be to make a shield pcb professionally for the uno with the h-bridge and all termination blocks on it for easy wiring.

Hope someone can help me with this.

Thanks

MarkT

I'd suggest separating the task into parts.

One part is figuring out the program logic for starting, stopping, reverseing, etc - use LEDs and push
buttons to start with.

Another is driving an H-bridge, which is somewhat hardware specific (some H-bridges are 2 input, some 4,
and they vary about how to use PWM.

That motor is 60W nominal, beware the maximum (stall) current rating - its likely to be considerably
higher than 10A and the H-bridge has to survive this.  You will need a suitably rated H-bridge module
or motor controller - I'd suggest looking at the range at pololu.com for an idea of what kind of thing
is available.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Robin2

The system should be activated with 1 push button. 1 press makes the motor turn (for argument sake clockwise) another press of the button will stop the motor and if you press again the motor will reverse direction (counter clockwise in this example)
It is certainly possible to write a program to make that happen. However I reckon it will be a bit of a nightmare for the user who may inadvertently press it the wrong number of times. I would suggest using 2 buttons - one for up and one for down, or using a 3 position centre-off toggle or slide switch.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Vernon333

#3
May 03, 2018, 07:12 pm Last Edit: May 03, 2018, 08:53 pm by Vernon333
Ok,

Thanks for all the advice.

I made it a 2 button system and got myself a few leds, resistors and a breadboard.

Got a bit of code sort of working, but need some help.

The buttons work, but it does not keep the trigger until the limit is reached, as soon as I release the button, the led goes of.

I would like it to be pressed once, motor switches on and turns in direction of what button I pressed until the limit is reached then stops and cant go further, only in the other direction.

Here is the current code:

Code: [Select]
const int pwm = 9 ;
const int in_1 = 2 ;
const int in_2 = 3 ;
const int UpButton = 10 ;
const int DownButton = 11 ;
const int Upper = 12 ;
const int Lower = 13 ;

int UpButtonState = 0 ;
int DownButtonState = 0 ;
int UpperState = 0 ;
int LowerState = 0 ;

void setup() {

 pinMode(pwm, OUTPUT) ;
 pinMode(in_1, OUTPUT) ;
 pinMode(in_2, OUTPUT) ;
 pinMode(UpButton, INPUT_PULLUP) ;
 pinMode(DownButton, INPUT_PULLUP) ;
 pinMode(Upper, INPUT_PULLUP) ;
 pinMode(Lower, INPUT_PULLUP) ;

}

void loop() {

 UpButtonState = digitalRead(UpButton) ;
 UpperState = digitalRead(Upper) ;
 DownButtonState = digitalRead(DownButton) ;
 LowerState = digitalRead(Lower) ;

 if (UpButtonState == LOW && UpperState == HIGH)  {
   MoveUp();
 }
 else if (DownButtonState == LOW && LowerState == HIGH)  {
   MoveDown();
 }
 else {
   digitalWrite(in_1, LOW) ;
   digitalWrite(in_2, LOW) ;
   analogWrite(pwm, 0) ;
 }
}

void MoveUp() {

 digitalWrite(in_1, HIGH) ;
 digitalWrite(in_2, LOW) ;
 analogWrite(pwm, 255) ;
}


void MoveDown() {

 digitalWrite(in_1, LOW) ;
 digitalWrite(in_2, HIGH) ;
 analogWrite(pwm, 255) ;
}

Robin2

To make it easy for people to help you please modify your post and use the code button </>
Code: [Select]
so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Rather than this style
Code: [Select]
if (UpButtonState == LOW && UpperState == HIGH)  {
you need to use the button press to set a variable for upward movement which only gets reset when it actually gets to the top. Something like
Code: [Select]
if (UpButtonState == LOW) {
   moveUp = true;
}
if (moveUp == true) {
   if (UpperState == HIGH) {
      // code to move up
   }
   else {
      moveUp = false;
   }
}

 
...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Vernon333

Sorry about that, very new to this.

I found this code on the net, what I know is very very limited. Please excuse me, but where would I add the piece of code you just sent?

Apologies, but this is really a spoon feeding exercise when it comes to coding.

Could you please help me with the complete code so I can upload and test it? 

Robin2

I found this code on the net, what I know is very very limited. Please excuse me, but where would I add the piece of code you just sent?
You have a go at figuring that out and if you can't get it to work then post your best attempt and I will try to help.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Vernon333

Think I will just have to pay someone professional who knows this stuff. I am useless with coding.

Thank you guys for trying though, I have learnt a bit about these things.

Go Up