SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By Robbyrat78
#198101
Hi there,
I'm learning how to work with Arduino and have started a project of creating a little robot that will adjust my rooms dimmer switch via remote. I have a set up using a 28BYJ stepper motor and an Arduino Uno. I will have a lead screw running vertically powered by the stepper motor that will spin, raising a nut on the screw that will be attached to the dimmer switch adjusting it on and off. So far I have all of the coding for moving the motor with the IR remote but I would like to spruce it up some. I am looking to have it where I can jog the lights by pressing the remotes left and right arrows, turn all the way on and all the way off by hitting the up and down arrows and move to a certain position based off of the number button I hit, for example, moving to half brightness if I hit button 5. I understand stepper motors move a certain amount of steps based off of the commands it is given and I have been able to assign each button a different distance to travel but how can I achieve the ability to say move to 50% brightness from 75% brightness? Right now I can only make the motor move a certain distance in one way or another based strictly off the commands in the code. I am looking for how to tell it to move to a certain position based off of what button is pressed regardless of its initial position. Any help is greatly appreciated.
By jremington
#198105
how can I achieve the ability to say move to 50% brightness from 75% brightness?
Your program has to "remember" how the motor shaft is positioned at all times, by summing up all movements from the starting position. Then, it calculates the new position (number of steps and direction to move) from the current position and the command received.

The problems with this approach are twofold. First, the Arduino does not know where the motor is when it is powered up, so upon startup, the program has to move to a home position and keep track from there. Second, if the stepper motor ever skips steps, which can happen in an underpowered or poorly designed setup, it becomes impossible to keep accurate track of position.

Some setups use a microswitch (a limit switch) to sense the home position, but that is not required. It does not hurt a stepper to simply stall it by running into an end stop.

A shaft encoder can also be used to keep track of position, but absolute shaft position encoders are expensive and incremental position encoders need to be homed on startup.
By Robbyrat78
#198106
Thanks for the help! I did some research on limit switches and have ordered some to add to the setup. Other than setting up the homing, do I need something else to have the Arduino "remember" it's position? Can I just write the code to have it do that or do I need another device?
Thanks again!