l298 dc motor control
yOUR CODE CANNOT DO THE JOB AT ALL !!
It relies only on a time ON to position the ARM
The final position will be depending on the power supply,
the outside temperature, the dirt on the system the lubrication of the system, the time the button is pushed ...
As I explained in the first part,if the motor is a free running DC motor You must have TWO switches sensing the position of the arm against the end of travel,one Close to the end slowing down the motor the other one at the end.
That implies a speed control with PWM or other way.
To use only one switch to sense the arrival at the end one possible way of "braking"is by shorting the armature or using a windscreen motor that locks itself as soon as it is stopped.
Symbolic code:
OPENING
If pushbutton_open then//open
direction_open =1//relay forward
If stop_open then
direction_open=0
//the motor stops dead as it is a wind screen wiper motor
CLOSING
If pushbutton_close then //close
direction_close=1//relay reverse
if stop_closed=1 then
DIRECTION_CLOSE=0
tHIS IS THE SIMPLEST WAY WITH A DC MOTOR
The really good way is using a stepper motor
COUNTING THE NUMBER OF STEPS FORWARD OR REVERSE