28BYJ-48-5V stepper motor - driver sketch

Hi, I'm half way through building an auto closing/opening hatch door (to keep my chickens safe from predators/rats), where a LDR determines when to open and when to close the hatch, with the Atmega 328P chip spending most time asleep to conserve power. This is all working so far.

Now I need to introduce some code to drive the ULN2003 driver, which will be powered separately to the Atmega from 4 x AA batteries (6V), and will according to 'IF'/'ELSE' statements, either rotate the motor 14 revs C/W or CC/W, which will drive a small pulley - raising or lowering the hatch. The small pulley ensures that I will only need approx 150 gm/cm (50% of the quoted torque) to ensure smooth transit.

Because it's running from batteries, I want the motor to run as efficiently as possible (not necessarily the fastest!) and wondered if you could recommend any driver code, and suitable timings to maximize battery life.

Paul

Steppers consume approximately the same amount of power the whole time they are powered up
(I'm talking unipolar here of course). So running them as fast as you can will mean they can be
powered up for the least time. AccelStepper examples is probably the place to start.

http://www.airspayce.com/mikem/arduino/AccelStepper/

Make sure you use the disableOutputs function to turn the motor coils off when not moving.

If you haven't already done so, perhaps more efficiency can be attained by adding a counter-balance to the door. - Scotty

I've added the AccelStepper library, and worked through the various examples, but found it really difficult to do what should be simple functions;
I'm using 'IF'/ELSE' statements which determine one of two states; make 14 rotations c/w, or make 14 rotations cc/w.
So far I've only managed to move it c/w... (speaks volumes about my programming abilities...)

Chagrin - thanks for the advice, I can see why it's needed.

Scottyjr - yes, I had considered that, but am using a lightweight aluminium composite door (approx 200gm) and didn't want to over-complicate the linkages.

Paul

Once you get my code working turning 14x is one line of code. PM me your phone number maybe I can help.

Do you by chance go to Capitol College? This seems very familiar to a project someone I was in class with had an idea to do.