Control DC Motor with one push button

i would like to ask question, can i use the push button to control the DC motor like when i press the button it will clockwise and stop a specific point and stay for how many minutes or seconds, and when i press it again it will counter-clockwise then stop until it reach the starting point.

Can i use the L239D as the driver of the DC motor? because i think that L239D can drive the DC motor counter-clockwise.

Have you thought about how to get the position? There are some option here:

  • Use a limit switch that is activated by whatever your motor is driving
  • Use a encoder
  • Use dead reckoning, that is run the motor for a certain amount of time. But this will give you VERY poor precision.

The best way to make a program like this is to design a state machine like the one in the attached diagram.
You can use a L293D as long as i matches the specs for the motor you are using

one btn state diagram.png

nilton61: Have you thought about how to get the position?

yes sir i already set it about 90 - 120 degree.

nilton61: Use dead reckoning, that is run the motor for a certain amount of time. But this will give you VERY poor precision.

sir what do you mean with this. sorry i am newbie with electronics.

sir L293D can handle a more current because i think if the DC motor stop in a specific point it will store a current inside in the L293D.

A dc motor will NEVER have the same speed on two consecutive runs depending on a myriad of factors like voltage, load, temperature, which mood it is in, etc. That means that if you run the motor two times an exact identical amount of time the motor will rotate a different distance. And it also means that the more times you run it the more the position will differ from the desired one. Running a motor a specified amount of time is fine for a cement mixer, not for reaching a specified position. if you want to achieve a position you will have to provide some means for feedback like encoders or limit switches.

Another option would be using a rc servo which can be easily controlled from the arduino using the servo library. You are saying that you need to rotate 90-120 degrees so this might be the solution for you. In that case you do not need any additional hardware since the servo can be controlled directly from the arduino. You just select and buy a servo that provides you with the amount of torque and speed needed.

A third option would be using a stepper motor with an appropriate driver. This thread will give you some info.

The way you are expressing yourself makes me wonder if you have achieved the necessary amount of knowledge and understanding:

sir L293D can handle a more current because i think if the DC motor stop in a specific point it will store a current inside in the L293D.

This is as wrong as it can be. A IC like a L293 can NEVER store electrical energy as current. The only component capable of that is an inductor. If you exceed the current rating by selection error and/or overloading/stalling the motor you will damage the IC and possibly the motor as well. Not that i want to discourage you but be prepared to encounter problems and be prepared to do quite an amount of learning to overcome them

it mean sir much better to use a servo motor. so sir if i use servo motor it more easy to determine what specific point i want.

sir for example i press the button and reach 120 degrees, can servo stay that position about 10 - 20 mins before i press again the button and back in the original position.

i am using Arduino Uno R3

The Rc servo will hold its position as long as you want it to (and of course, power and signal are applied). It will even revert to that position if you force it to another one once you remove the force.

another question can i directly tap the positive and negative of the arduino in 12v power supply or i need to use a regulator for the arduino, when it is directly in PC the output voltage of the USB port is 3.3v to 5v if i'm not mistaken.

The servo needs more power than the usb port can provide. Normally a servo need 6V supply voltage, most work fine with 5V but with diminished torque and speed. There are also so called high voltage types taht work with voltages of 7,4 or even 12V. But the important thing is to power the servo from a voltage source that ca provide enough current to drive the servo. This can be the same source as you use for powering the arduino board or a separate one.

so sir i can use 12v 3.2A or 12v 5A power supply for my project, because i add 12v LED Strip i think this will be works fine. Thanks sir +1 :D

That would mean that your servo has to tolerate 12V or you use an additional regulator to lower the voltage to the servo

i use the regulator depends on the input voltage of the servo, then i can use the 12v as the power source of arduino,

Yes

ok sir thanks :D