What I'm looking to do is make a customised clock using some stepper motors which drive some clock hands (one stepper motor per hand, so it's not like a normal clock where one motor plus some gearing controls all the hands). There will be a real time clock module in the setup so in the event of power loss the time/date isn't lost but the motors will obviously stop working. When power is restored I then want the analog clock to then "catch up" to the time the RTC module says it is.
To make this work I need to determine what position the stepper motors are in so that I can then do some math to position them in line with the RTC time.
Is there anyway to do this or will I have to use servos instead?
I wanted to avoid servos just because my experience has always been that they are a bit noisy (even when idle) and are limited in terms of movement (unless you modify them to be continuous, but then you're moving them by milliseconds rather than to a specific position and I think you lose the ability to have a home position?) but that is the fall back position should stepper motors prove to be difficult to keep track of their position.
Another way I suppose I could do this is have the stepper motors return to their "home" positions on startup and then move it forward to the correct time. I've never used stepper motors, can you set a home position on them so when it is powered up they return to a specific position regardless of what position they were in at the time of the power cut?
Thanks a lot in advance to any help anyone can provide
Another way I suppose I could do this is have the stepper motors return to their "home" positions on startup and then move it forward to the correct time.
This is the way to do it.
May be have your home position at 12, i.e. one limit switch per hand.
It might look good if the home position was determined by hands passing an optical sensor and, in the homing routine they fly round at high speed until the home position is detected. Deliberately very un-clock-like.
I do like the idea of it resetting and then finding the "real" time afterwards when there's been a power interruption. Like Robin2 says, very un-clock-like
I'll take a look into optical sensors and limiting switches. I've never really used these before (nor stepper motors) so it's going to be a learning experience for me. Appreciate the quick replies!
If anyone else has any other suggestions I would love to hear them.
Would an optical sensor like this work do you think (or does anyone have any other recommendations)?
I've never really used things like this so my assumption is that when I'm trying to reset the stepper to the home position I begin checking this sensor. I run a loop which checks if the sensor is covered up by the clock hand and if not steps forward a little. It then keeps looping until the sensor is covered indicating the home position has been reached (so the hand is pointing at "12").
Another way I suppose I could do this is have the stepper motors return to their "home" positions on startup and then move it forward to the correct time.
This is the way to do it.
May be have your home position at 12, i.e. one limit switch per hand.
You could have several 'home' positions, as long as you have sufficient spare pins on your Arduino. If you had them at 3, 6, 9 and 12 your hand would only have to turn through (max) 90o before its position is detected.
If there is sufficient space on your hands to fix a small magnet, you could use Hall sensors as home switches.
Having multiple sensors to detect where the hands are in relation to the "12" home position sounds good as (like you say) you can detect the position of the hands earlier, but I don't think I'll have enough pins available. Never heard of "hall sensors" until now but they look pretty interesting.
I've bought some cheap 28BYj-48 motors which use another cheap ULN2003 drivers. Each driver needs 4 pins (so 16 in total as I'll need 4 steppers), then I have an I2C real time clock module to connect. So before I've even addressed the sensors I've probably run too low on pins. I guess I'll need to take a look into seeing if there are cheap I2C drivers I can get or a more heavy duty driver that lets me drive multiple steppers. At the end I would want to permanently add the ATmega328 chip to the final circuit (rather than using the Arduino board itself so it's not going to waste), so I want avoid any "shields" if possible.
I'll also have a search on the forums to see how you can increase the number of pins you can control (the only idea I have is having two ATMega328 chips connected via I2C so you can spread the components/jobs)
uln has enableinput so you could only need 4 plus 4 outputs.
however this is only possible when motors are not turning when power is lost (not complete trhu (i will explain)
when enable is off the uln will be off so the current is off.
however you can multiplex motors the same as a display is done.
when moving put it on 25% each and when not moving you could go back to 10% this way thwe current is low, and the motors will not overheat.
power down situation:
when you detect, put the position in the RTC memory, when power back get position in again and move, this works only when motors do not move when power is down.
otherwise you have to use a sensor.
hi i am very new but one idea from me is to put an optical wheel like those in old mouses to the shaft and count the steps as you work normally from the optical sensor to the arduino than if power is lost to the motors you have the correct position in one or more arduino variables from the last time the motor worked. this assumes that arduino has a backup battery to function in case of power issues to the motors. and if the optical sensor is tied to the power of the motor than use a routine to check if the stepper is alive and check the sensor for activity if they dont add up conclude the stepper is either dead or without power but need to have 2 wires going along with the stepper :P.
I reckon a single detector would be more fun - watching the hands fly around the full face - as well as being much simpler. One optical sensor might be able to deal with all the hands (assuming each hand has a separate motor).
As "shooter" observes, stepper motors generally hold their position when de-powered, so it is merely a matter of remembering the last position to which they were set, which you do by storing it in the battery-backed memory of the RTC.
I haven't studied RTCs and it had never occurred to me they had memory the Arduino can write to. Is it SRAM that can withstand writing to it every step of the motor?