Hello Guys,
It's my first day here and I am glad to be part of this community.
I have a project need to be done very soon, it should be a lift using dc motor with one push button. Basically when I press one push, the motor should spin for 5 second and going up and stops at level 1, then with the same push button I should press again and it goes down for 5 seconds and stops at G level.
Currently I have Arduino uno and L293 and DC motor 4.8V
You need a variable to keep track of the state of your system - perhaps called liftPosition and with 4 possible values 'U' (going up); 'T' (at the top); 'D' (going down) and 'B' (at the bottom).
Rather than time your motor it would be more reliable (as in real lift practice) to use a micro-switch at the top and bottom to identify when the move is complete.
Your single push button would cause the value of liftPosition to change from (say) 'T' to 'D' and your motorOperate() function would use the value of the variable to decide if the motor should operate. Then the bottom switch would cause the value to change from 'D' to 'B'
Thanks a lot Robin2, you are completely right, but I should strictly do the way it should be for this project.
I will be thankful if you know how to code it.