Hi,
my first post on here - this forum has already helped me out a great deal.
My first project is going to be an auto chicken door opener, essentially this is just a motor, with a pulley, which detects dawn / dusk and moves the door up and down.
I'm hoping to hook this up to a 12v battery eventually (from small off-grid solar setup in the shed next to the chicken coop - all in the future!)
I'm using an L298N motor controller with my Uno, I'm also wanting to power completely from the one power source so I've got a regulator in there to power the Uno.
I'm just after peoples advice on 'protecting' the circuit i.e. resistors or diodes etc (like with a relay for example) - it all works fine so far but I don't want it to burn out etc or blow the UNO... this is all new to me so go easy - also on the online circuit builder I was using I couldn't find a motor so put a bulb in for now....
Code is here also (don't suppose it matters) - also this started out life from here L298 Motor Control | Arduino Tutorial - YouTube
#include <LiquidCrystal.h>
int ENA = 9; //PWM pin for motor 'speed'
int IN1 = 11; //Motor Direction Pin
int IN2 = 10; //Motor Direction Pin2
int LDRPin = 0; //Analog Pin from LDR
int CurrentLight =0; //Read in every loop
int PrevLight=0; //Read in during setup and then kept updated every loop
void setup ()
{
pinMode (LDRPin, INPUT);
pinMode (ENA, OUTPUT);
pinMode (IN1, OUTPUT);
pinMode (IN2, OUTPUT);
PrevLight = analogRead(LDRPin); //Read in the initial light reading
Serial.begin (9600);
}
void Motor_Clockwise ()
{
Serial.println ("Clockwise"); //For Debugging purposes
for (int i = 0; i < 10; i++) //Repeats for 10 seconds (1000 delay) - will eventually be till limit switch reached
{
digitalWrite (IN1, HIGH); //sets direction of motor
digitalWrite (IN2, LOW);
analogWrite (ENA, 255); //full power on motor (only 15RPM motor!)
delay (1000);
Serial.println(i); //debug
}
digitalWrite (IN1, LOW); //Stops motor
}
void Motor_AntiClock ()
{
Serial.println ("AntiClock");
for (int i = 0; i < 10; i++)
{
digitalWrite (IN1, LOW);
digitalWrite (IN2, HIGH);
analogWrite (ENA, 255);
delay (1000);
Serial.println(i);
}
digitalWrite (IN2, LOW);
}
void loop() //Main Loop
{
CurrentLight = analogRead(LDRPin); //Read in current light level
Serial.print("Current light level is: ");
Serial.println(CurrentLight);
//Replace code here to compare light with the previous half hour etc - need to look this up
if (PrevLight - CurrentLight > 20) //reduced light significantly - close door
{
Serial.println("Closing the door now as light reduced");
Motor_Clockwise(); //Will close the door
}
else if (PrevLight - CurrentLight < -20) //increased light significantly - open door
{
Serial.println("Opening the door as light increased");
Motor_AntiClock();
}
PrevLight = CurrentLight; //set previous light with current
Serial.print("Previous Light level now set to: "); //debug
Serial.println(PrevLight);
delay(10000); //wait 10 seconds before re check
}
Thanks
Chris

