As you can see the power for the motor comes from arduino itself. This was not sufficient for the motor necessary to move the hen door.
As the arduino would fry if I tried to use it to handle mains power for the motor directly I needed to use relays. These allowed me to use full mains power to drive my motor without frying the arduino.
int sensorPin = A0; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor
int doorShut=0;
void setup()
{
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}
void loop()
{
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the screen
delay(100);
}
// change 100 to the read value of the ldr in the late evening when it is mostly dark
if (100 > sensorValue & doorShut == 0)
{
delay (1000); // change to 2 hours for actual circuit
digitalWrite (10, HIGH);
delay (1000); // length of time for motor to spin
digitalWrite (10, LOW);
doorShut = 1;
}
// change 700 to the read value of the ldr in the early morning
else if (800 < sensorValue & doorShut == 1)
{
delay (1000); // change to 5 hours for actual circuit
digitalWrite (11, HIGH);
delay (1000); // motor spin time
digitalWrite (11, LOW);
doorShut = 0;
}