Go Down

Topic: 1st Project for newb (Read 991 times) previous topic - next topic



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 http://www.youtube.com/watch?v=1Q0ZwpycbzY

Code: [Select]

#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);

   digitalWrite (IN2, LOW);

void loop() //Main Loop
  CurrentLight = analogRead(LDRPin); //Read in current light level
  Serial.print("Current light level is: ");
  //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");

PrevLight = CurrentLight; //set previous light with current
  Serial.print("Previous Light level now set to: "); //debug
  delay(10000); //wait 10 seconds before re check




Battery operation - I'd suggest looking into a few things (minor if you have solar backup):
- Regulator - switching regulators waste less power.
- Sleep mode - the application really should only drive that door twice a day, so the chip can go into low power mode ('sleep') for a majority of the time (let's not get into whether the duino is needed).
The application really just calls for two executions (morning and night). If it gets dark all of a sudden (rain, shadowing).. you don't want that door cycling down preventing entry.

Circuit protection wise,
over current on the motor doesn't seem to be protected (i.e. motor jammed stall current exceeds driver chip or cable ratings).
fuse the battery supply to the duino to the max expected during motor operation.
freewheel diode not present across the motor (when it turns after you turn off, high voltage is generated, so L298N could be subject to V > allowed.
check spec on datasheet and motor for current requirement.

Of them all the fuse is fairly important - overcurrent or a short (chickens can be fairly docile) will produce heat and may start a fire.

Go Up