Pages: [1]   Go Down
Author Topic: 1st Project for newb  (Read 273 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


Code:
#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


* CDoorCircuit.JPG (50.78 KB, 885x444 - viewed 19 times.)

* cDoorlayout.JPG (62.22 KB, 590x612 - viewed 17 times.)
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 151
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Pages: [1]   Go Up
Jump to: