Hey, I exactly need to control the speed of the motor based on hand movement. Please tell me how to code it for a stepper as well as geared dc motor
Controlling a geared DC motor is pretty simple. Set the direction pin HIGH or LOW, based on the direction you want to go. Set the PWM pin's value to the speed you want the motor to run.
Controlling a stepper motor is similar. If you are using the Stepper library, set the direction, the speed, and the number of steps.
Of course, none of this is practical, since you have not defined what the speed should be based on the POSITION of the hand, and an accelerometer won't give you position, anyway, without a lot of effort.
If it is the VELOCITY of the hand at any given time that should define the speed of the motor, you still have a long ways to go before an accelerometer will give you VELOCITY.
If it is the ACCELERATION of the hand at any given time that should define the speed of the motor, then your job is just about done.
Although using acceleration (a non-linear attribute) to control speed does not make a lot of sense.
So, we are back to the original question. How exactly should the output of the accelerometer (acceleration at a given point in time) be used to control the motor - speed? direction? amount to turn?