Stepper motor on sliding door run once in either direction w/light

Hey guys, I am making a chicken coup project with an automated door. I have a stepper motor with a door operated by a lead screw. I have gotten it to respond back and forth based on the LDR, but it continuously (incrementally) to spin in whatever direction the photoresistor is telling it to. It spin say 5 revolutions, stops, and then continues repeatedly.

I want it to run once (Open) and stop, until it gets dark again and then in reverse once (Close) and remain there until morning. I also have a temp sensor that is running a relay for a heater, but that is working properly so I apologize for the discombobulation.

I know there are other setups with guys running reed switches, but I prefer not to do that if I can help it. Here is the code.

#include <Stepper.h>
#define STEPS 1
const int stepsPerRevolution = 3200; // change this to fit the number of steps per revolution

// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 6, 8, 7, 9); // Pins activating the motor coils

int trigger=0;
const int ledpin=11;
int lightlevel, high=0, low=1023;
const int temperaturepin=0;
void setup() {
// set the speed at 20 rpm:
myStepper.setSpeed(200);// speed of the motor
// initialize the serial port:
Serial.begin(9600);
pinMode(A1,INPUT);
pinMode(ledpin,OUTPUT);
}

void loop() {
float voltage, degreesf, degreesc;
voltage = getVoltage(temperaturepin);
degreesc=(voltage-0.5)100.0;
degreesf=degreesc
(9/5)+32;
Serial.println("deg C:");
Serial.println(degreesc);
Serial.println("deg F");
Serial.println(degreesf);
if ( degreesf >=35)
{
digitalWrite(ledpin, HIGH);
}
else
{
digitalWrite(ledpin,LOW);
}
trigger=analogRead(A1);
Serial.println(trigger);
// step one revolution in one direction:

if (trigger>400)
{

myStepper.step(42000);
}
delay(5000);

// // step one revolution in the other direction:
// Serial.println("counterclockwise");
if (trigger<400)
{
myStepper.step(-42000);
}
delay(5000);
}
float getVoltage(int pin)
{
return (analogRead(pin)*0.004882814);
}/td]

Hi,

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile: