Forum / Guestbook




Luberth Thu 28 Feb 2019 at 7:51:51
Arduino Controlled Chicken Coop

-
Arduino Controlled Chicken Coop Door Chicken Flap
HobbyBob Automatisch KippenLuikje
kippenluikje automatisch
kippenhok sluiter zelf maken
chickenguard arduino
nightwatch hokopener
drzwi automatyczne omlet do kurnika
Automatyczna klapa drzwi do kurnika
Automatyczne drzwi do kurnika
Drzwi Automatyczne Omlet do kurnika
Automatyczne otwieranie i zamykanie kurnika

Automatische Hühnerklappe / Hühnertür mit dämmerungssensor Selbst bauen, Automatischer Türöffner

WHY would you buy a Eaton klockner moeller Easy or siemens logo! or Crouzet Millenium
With stupid 50 euro or higher priced special programming cables
And pay lots for software editors/programmers
And get utterly frustrated by how limited above HobbyBob PLC's are
So, are you done Mister Dykman
When you can do so much more with ease and fun with an arduino for 1/100 of the price of above

Sorry, Dutch is my Mothers Language



2x16 i2c LCD
what you see on LCD is
actual state of up switch
actual state of bottom switch
actual state of max up overtravel switch
actual analog input value of light sensitive LDR = 153 (0 to 1023)
close setting = 10
open setting = 100
And the i am alive spinner -/|\
ToDo
  i want 4x20 i2c LCD for more text
  i want to add an rotary encoder push button menu
  for changing the open/close value, motorspeed PWM setting and write it to eeprom for powerdown safe-save
  i want to add i2c temperature/barometer Chicken weather station ;-)
  Hall effect encoder gearmotor with only 1 home (Hall effect) switch for startup/powerup homing
  add a ds3231 i2c real time clock with timed close setting for long summer evening light
    https://www.hobbyelectronica.nl/product/ds3231-iic-real-time-clock


Arduino uno Chinese clone 2.65---2.73 Euro incl shipping
https://www.banggood.com/UNO-R3-ATmega328P-Development-Board-For-Arduino-No-Cable-p-964163.html?rmmds=search&cur_warehouse=CN

More then 20 years ago (1997) i played with MicroChip PIC16C84 (R.I.P.) 36 bytes RAM, 64 bytes Data EEPROM 13 I/O in MPLab, MPASM assembler = understandable but not like c
Have been hiding under a rock since then
This Arduino is Now NEW to me (march 2019)
Amazed how easy to use, so much examples and info available on the web, and cheap parts shields and sensor relays PCB Und so Weiter

The open-source Arduino Software (IDE) makes it easy to write code and upload it to the board.
It runs on Windows, Mac OS X, and Linux.
Download the FREE Arduino IDE (editor/compiler/programmer) https://www.arduino.cc/en/Main/Software
Arduino Programming Language Reference




An geeckcreit Arduino atmel 328 uno clone PrintedCircuitBoard
you can buy for something like 2.73Euro gearbest aliexpress banggood including shipping
arduino mini and nano and ... even sell for less then 2 euro
and you can save space to

impressed ammazed how easy to edit and program with arduino ide
and lots of c program examples availeble
also arduino ide editor/compiler/programmer has a serial monitor
Serial.begin(9600); // Other baud rates can be used..
Serial.println("Motor starts here to close");
nice feedback for debugging



3d print arduino bumper
https://www.thingiverse.com/thing:26237

https://www.thingiverse.com/thing:26237




Today 3 march 2019 i recieved 2 arduino nano clone from china think i payed something like 1.75 Euro a piece
just as easy to use/program with arduino ide, but u need a mini-usb cable is a little bit bigger connector as telephone micro-usb cable
Geekcreit® ATmega328P Nano V3
Specification:
Microcontroller ATmega328
Operating Voltage (logic level): 5V
Input Voltage (recommended): 7V ~ 12V
Input Voltage (limits): 6V ~ 20 V
Digital I/O Pins: 14 (of which 6 provide PWM output)
Analog Input Pins: 8
DC Current per I/O Pin: 40mA
Flash Memory: 32KB (ATmega328) (of which 2 KB used by bootloader)
SRAM: 2KB (ATmega328)
EEPROM: 1KB (ATmega328)
Clock Speed: 16MHz

analog input results in a 10bit value so a value from 0 to 1023 (10 bit = 1+2+4+8+16+32+64+128+256+512 = 1023)

like this arduino nano screw shield for finished projects

like this arduino nano screw shield for finale projects
why they choose green screw terminals i do not like that it Curses, black or blue please?
Not a women who designed this?


i have looked at some chicken coop example code on the internet
what i miss in most examples
max runtime limit for motor
if a limit end switch fails or wire is broken or whatever
there is no limit on motor run time

i would like to say
if endswitch==true or runtime => maxruntime then stopmotor
if runtime => maxruntime then stopmotor and errormessage


and maybe also minimum runtime check
if runtime is much shorter as expected runtime to switch then error



Geekcreit® L298N Dual H Bridge Stepper Motor Driver Board For Arduino 2,57€.

maybe its nicer to use an l298 print with current sensing connected to arduino analog input
an give an error when current l298+motor is above certain point
on above l298 print => current sense is not used




if i would buy it again i would prefer one with a hall encoder(not seen 12rpm with encoder yet)

Reversible High torque Turbo Worm Gear Motor JGY370 DC 12V 12RPM 6mm D-shape axis
if i would buy it again i would prefer one with a hall encoder(not seen 12rpm with encoder yet)

gearmotor aliexpress
Oh thats tiny, but it is powerful
12vdc 12rpm 30kg/cm 6mm D-shape axis
if i would buy it again i would prefer one with a hall encoder(not seen 12rpm with encoder yet)
i think it does 30kg/cm so if my wireshaft is 12mm it should do more then 30Kg lift
Well my Trespa / HPL High Pressure Laminate chickendoor slide is less then a half a Kilo i think
want to use aluminium chair like a h profile for the trespa hpl slide


i have seen others who use this dc gearmotor XD-37GB520
12v 15rpm 40kg/cm 6mm D-shape axis

i have seen others who use this dc gearmotor XD-37GB520
12v 15rpm 40kg/cm 6mm D-shape axis

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-------------------------------------------------------
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
jgb37-520 encoder gear motor with hall encoder
12vdc 12 rpm 30kg/cm 6mm D-shape axis

jgb37-520 encoder gear motor with hall encoder
12vdc 12 rpm 30kg/cm 6mm D-shape axis


kilo 1 centimeter explained
so above motors should do Theoretically max. 30 kilogram lift on a 20mm diameter or 10mm radius axis




www.google.com/search?q=github+arduino+chicken+coop
www.google.com/search?q=github+chicken+coop

https://www.youtube.com/results?search_query=arduino+chicken+coop

  A GREAT Father, Son, GrandPa D.I.Y. Project
  Some do extend the project
And if you can build it yourself , you can fix, repair it yourself
    Timed Chicken lights
    Chicken water level sensing. filling
    Chicken feed control
    Predator PIR detection alarm
    Chicken water heat when freeze
    Chicken fan
    Chicken door control=This
    Chicken audio video entertainment system to keep the Girls happy ;-)





my first playing with arduino uno and l298 PWM motor forward and backward rampup rampdown loop
/* Arduino uno DC Motor L298N Module H-bridge DC Motor
 pwm on enAble
 */

//Define all the connections maps to the L298N
int enA = 10;   //make sure it is a pwm anabled output
int in1 = 9;
int in2 = 8;
int led = 13;   //onboard led
int t;


void setup() {
  // Setup pin mode
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(led, OUTPUT);  // onboard led
}




void loop() {
  //Drive Motor Forward
  analogWrite(enA, 10);
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  rampup();
  delay(5000);
  rampdown();

  //Drive Motor Backward
  analogWrite(enA, 10);                                                      
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  rampup();
  delay(5000);
  rampdown();



  digitalWrite(led, HIGH);   // turn the onboard LED on (HIGH is the voltage level)
  delay(250);               // wait for a while
  digitalWrite(led, LOW);    // turn the onboard LED off by making the voltage LOW
  delay(250); 
}



void rampup(){
  for (int t = 10; t <= 255; t++) {
    analogWrite(enA, t);
    delay(20);
  }
}




void rampdown(){
  for (int t = 255; t >= 0; t--) {
    analogWrite(enA, t);
    delay(20);
  }
}











a reed switch is a magnet sensitive switch that opens or closes when a magnet is held close to it
i do not know why but the chinese reed switches are a bit high priced in my opinion
i see them for 1.50 euro for a door set
i would expect something like 75 cents or less for a chinese reed switch doorset
Maybe Hall ic's switches are cheaper
plain 3 pin hall ic's are about 8cents a piece on aliexpress
and hall ic switches are not mechanical like a reed switch so less defect?
Hmmm, i have some 20 year old hall ic's wich i bought probably for much to much money
This arduino is so easy, so much fun ;-), nerd
text facing in mass out i used input pullup so no 10k resistor needed
TLE4905L TLE4935L
Tricky
unipolar non latching type => only reacts on one side of a magnet
bipolar latching type => reacts on a side and keeps that state until another side off magnet appears and keeps that state until ....
so unipolar non latching is easier but you have to face the right side of a magnet to it for detection

AH1815 omnipolar non latching thats better reacts on north and soutpole pulled low when magnet present
---but AH1815 is low sensetive i think i want high sensetive omnipolar hall sensor
maybe CMOS Omnipolar High Sensitivity Hall Switch ES245 is what i want
http://www.innosensor.com/Admin_Z/UploadFile/20140213154943ES245V2.0.3.131021_EN.pdf
Features ES245 that sounds good
 Solid-State Reliability much better than reed switch
 Omnipolar, output switches with absolute value of North or South pole from magnet
 Operation from 3.5V to 24V
 High sensitivity for direct reed switch replacement applications

ok what has aliexpress to offer me
---OH49E SS49E Hall Effect Sensor i more analog no magnet middle output, north lower output, south higher output
---3503 TO-92UA Hall Effect Sensor same as above ratiometric?
---TLE4905L TLE4905 P-SSO-3-2 IC TO-92 Bipolar Hall Integrated Switch this one i have from conrad 20 years ago
---3144A i think unipolar non latching, datasheet is like Siemens devices/Descriptions
------A3209E A3210E A3212E should be omnipolar
--Omnipolar Micropower Hall sensor Hall element 4913 HAL4913 4913B OH4913B
----The 2SS52M Series Digital Magnetoresistive Sensors are omnipolar
------- 2SS52M think i like this one but this is expensive euro's a piece

i give up for now, cannot find what i think i want
A3144E Sensitive Hall Effect switch unipolar non latching (ONLY NORTH POLE SENSITIVE)
____ https://www.elecrow.com/download/A3141-2-3-4-Datasheet.pdf
____ https://www.mpja.com/download/A3144EUl.pdf
____ 3d printers https://www.thingiverse.com/thing:35569
____ 3d printers https://www.thingiverse.com/thing:258910
i do not understand the 10k pullup resistor
i would think not needed if you use input pullup in arduino code then you connect pullup inside microcontroller

i do not understand the 10k pullup resistor
i would think not needed if you use input pullup in arduino code then you connect pullup inside microcontroller



also there are analog hall effect ic's
And there are advanced angle compass like Hall devices magnet encoder

Dutch Advanced GreenHouse Technology, GlassHouse is better it is by no meaning green
Wich Ridder Drive Systems Harderwijk used in REU=(ridder encoder unit) RPU=(ridder potmeter unit) potmeter replacement units and optic reflective encoder replacement tuinbouw techniek
Ridder Drive Systems Harderwijk uses it for lightblocking-energysaving-curtain position feedback in GreenHouses
Ridder Drive Systems Harderwijk uses it for airwindow position feedback in GreenHouses
The magnet encoders are more reliable versus potmeters and tiny optic reflector encoders they used in the past

and maybe even more types


arduino uno play with reed switch input monitor switch state on arduino ide serial monitor



/* Arduino uno 
 2 NormalyOpen reed switches from d2 and d3 to ground
 print switch state to serial monitor
 */

int openswitch = 2;           //d3 
int closeswitch = 3;          //d3

void setup() {
  // Setup pin mode
  pinMode(openswitch, INPUT_PULLUP);
  pinMode(closeswitch, INPUT_PULLUP);
  Serial.begin(9600); //sets serial port for communication  
}




void loop() {
  int openstate = digitalRead(openswitch);
  Serial.print(" open=");
  Serial.print(openstate);
  int closestate = digitalRead(closeswitch);
  Serial.print(" close=");
  Serial.println(closestate);
  delay(25); 
}













ldr light dependant resistor
resistange changes with the amount of light it recieves
twilight night dusk switch


arduino uno play with ldr analog input and display ldr value on arduino ide serial monitor


arduino uno play with ldr analog input and display ldr value on arduino ide serial monitor

/*
arduino uno 
 ldr connected to 5v to a0 and 5kresistor to ground
 write ldr a0 analog value to arduino ide serial terminal
 turn onboard led on or off depending off ldr value
 */

int led=13; // onboard led
int sensorPin = A0; // select the input pin for LDR
boolean x = true;
int sensorValue = 0; // variable to store the value coming from the sensor



// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT); 
  Serial.begin(9600); //sets serial port for communication  
}

// the loop routine runs over and over again forever:
void loop() {
  int sensorval = analogRead(A0);
  Serial.println(sensorval);
  
  delay(50);
  
  if ( sensorval < 300 && x == true){
    digitalWrite(13,HIGH);
    x = false;
    delay(50);

  }
  else if ( sensorval >300 && x == false){
    x = true;
    digitalWrite(13,LOW);
    delay(50);
  }


}





some code wich i found at
http://davenaves.com/blog/interests-projects/chickens/chicken-coop/arduino-chicken-door/

it opens and closes the chicken slide door based on exterior light on ldr
uses l298 ldr and no reed switches


i think it would be better for it to have motor runtime checking error
now if something is wrong
the motor will run forever
overheat, fried chicken

if the door is closing and there is something between it
the bottom switch wil not be made and the motor will not stop
big failure // design flaw
or there should be a normally closed emergency switch at maximum open
when touched it should kill motor power
i would prefer a closed contact because when there is a problem with wiring or contact then its detected directly

i used NO normally open reed switches because they are easier to find
when there is no magnet contact is open when there is a magnet nearby contact is closed

this code also can run perfect on a tiny arduino nano clone for 1.75euro




i think it would be better for it to have motor runtime checking error
now if something is wrong
the motor will run forever
overheat, fried chicken
if the door is closing and there is something between it
the bottom switch wil not be made and the motor will not stop
big failure // design flaw

or there should be a normally closed emergency switch at maximum open
when touched it should kill motor power

like this motor is stopped after maxmotorruntime=15sec en put in error reporting loop


nice if you have used a pwm output pin for enable on l298
then you can reduce the motorspeed
analogWrite(enableCoopDoorMotorB, 128); // 0to255 to set the motorspeed maybe handyer to make it a variable
int motorspeed = 128;
analogWrite(enableCoopDoorMotorB, motorspeed);

//* Copyright 2015, David Naves (http://daveworks.net, http://davenaves.com)
//* http://davenaves.com/blog/interests-projects/chickens/chicken-coop/arduino-chicken-door/



If the pin is configured as an INPUT, digitalWrite() will enable (HIGH) or disable (LOW) the internal pullup on the input pin.
It is recommended to set the pinMode() to INPUT_PULLUP to enable the internal pull-up resistor.

part that confused me a bit in daves code
enabling internal pullup resistors in atmel microchip
....const int topSwitchPin = 3;
....pinMode(topSwitchPin, INPUT);
....digitalWrite(topSwitchPin, HIGH);
seems to be the same as
....pinMode(3, INPUT_PULLUP);
or ....const int topSwitchPin = 3;
....pinMode(topSwitchPin, INPUT_PULLUP);
last one is preferred use


bought 2 meter alluminium chair like h profile 6.80 euro
https://www.groenhart.nl/zoekresultaten?search=stoeltjesprofiel+aluminium+brute+-+26X+8X15X1.5MM+2M
www.GroenHart.NL heeft een goede Prijs / service / kwaliteit maar heeft alleen winkels in Noord Holland
pitty i can not find h profile at hornbach.nl
Gamma Praxis Karwei enz. zijn zoals te verwachten minimaal 25% duurder ;-)FU
Of je moet wachten op een achterlijke ik betaal altijd 25% teveel maar niet op die speciale zaterdagen Actie

maybe the 4 mm trespa is a bit small for the 8mm groove
but i can dril a hole in the trespa on each corner
and 3d print or turn on lathe a punaises like slide nail to reduce the space

THE 4MM SPACE/PLAY BETWEEN TRESPA HPL SLIDE DOOR AND RAILS IS NO PROBLEM FOR REED SWITCHES

The alluminium chair like h profile is easy to screw on the wall or in this case a piece off plywood
i used trespa compact hpl but you could also use 4mm plexiglass
or maybe MDF 4a5mm thick and paint it or hardwood-multiplex/plywood 4a5mm thick and paint it for a couple of euro you can buy a square meter
or you could use a sheet of alluminium or steel, but looks to me like a guillotine
this is why its called chair like h stoeltjes profiel => its like a chair ;-)




Simple test setup
10 screw quick test setup in living room for program testing
10mm axis, wire taped with electric tape to axis, works ok
10mm axis x pi 3.14 8 12rpm = +/- 377 mm travel per minute (cord diameter not included!)
to fast? adjust PWM value on enable of l298

DO NOT like, if bottom switch fails or slide travel is hindered by an object
then in go4smoke self destruction mode (when u use David Naves code example)

after i saw on youtube how easy it is to use an AB encoder with arduino interupt pins 2,3
i ordered an shaft coupling 10mm/6mm and 5to24vdc 600puls AB Encoder and wil add encoder to the right side off the wire spool axis, both +/-10 Euro aliexpres.com
wil put a reed switch on maximum open for setup home position / and emergency stop during loop program
and wil count from there open and close position
also ooredered some 50 cent rotary encoder pushbutton knobs (normally used for display menu control) but they are optical 20 or 40 pulse rev. so i think they also could work less resolution but no problem
normally what goes up must come down
but with the stringaxis what goes down can go up again if it doesnt stop on the bottom switch





//https://github.com/jumejume1/Arduino/blob/master/ROTARY_ENCODER/ROTARY_ENCODER.ino
//Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : 
//https://www.paypal.me/MakerTutor
//arduino code

volatile unsigned int temp, counter = 0; //This variable will increase or decrease depending on the rotation of encoder
    
void setup() {
  Serial.begin (9600);

  pinMode(2, INPUT_PULLUP); // internal pullup input pin 2 
  
  pinMode(3, INPUT_PULLUP); // internalเป็น pullup input pin 3
//Setting up interrupt
  //A rising pulse from encodenren activated ai0(). AttachInterrupt 0 is DigitalPin nr 2 on moust Arduino.
  attachInterrupt(0, ai0, RISING);
   
  //B rising pulse from encodenren activated ai1(). AttachInterrupt 1 is DigitalPin nr 3 on moust Arduino.
  attachInterrupt(1, ai1, RISING);
  }
   
  void loop() {
  // Send the value of counter
  if( counter != temp ){
  Serial.println (counter);
  temp = counter;
  }
  }
   
  void ai0() {
  // ai0 is activated if DigitalPin nr 2 is going from LOW to HIGH
  // Check pin 3 to determine the direction
  if(digitalRead(3)==LOW) {
  counter++;
  }else{
  counter--;
  }
  }
   
  void ai1() {
  // ai0 is activated if DigitalPin nr 3 is going from LOW to HIGH
  // Check with pin 2 to determine the direction
  if(digitalRead(2)==LOW) {
  counter--;
  }else{
  counter++;
  }
  }
  
  
  //https://github.com/jumejume1/Arduino/blob/master/ROTARY_ENCODER/ROTARY_ENCODER.ino
  //Please Donate To Help Me Afford New Equipment And Software To Make My Videos More : 
  //https://www.paypal.me/MakerTutor
  
  









my version of David Naves code so far

Main changes i made to David Naves code
if a up or down movement is started
it contineus to do that move until switch is made
if motion to switch takes longer then 35 seconds maxmotorruntime
then turns off motor and comes in a serial error reporting loop
SAFETY FIRST ;-)!!!
actual motor runtime millis can be read/seen in arduino serial terminal
serial output is better readable


// DANGER *** DANGER *** DANGER
// STILL NEEDS A MAX OPEN SAFETY EMERGENCY KILL SWITCH
// DO NOT use this code unattended
// Although it is safer then David Naves because motor only runs for 35 seconds maximum
// DANGER *** DANGER *** DANGER


  
/*
http://84.106.2.21:8888/forum/index.php?action=view&id=255
KippenGek Dirk Luberth Dijkman Bangert 30 Andijk The Netherlands
http://paypal.me/pools/c/8amUN5rgb9
main changes i made
if a up or down movement is started
   it contineus to do that move until switch is made
if motion to switch takes longer then 35 seconds maxmotorruntime
   then turns off motor and comes in a serial error reporting loop

http://84.106.2.21:8888/forum/index.php?action=view&id=255

//i used code from
 * Copyright 2015, David Naves (http://daveworks.net, http://davenaves.com)
 *
//but changed a lot
// main changes i made to David Naves code
if a up or down movement is started
it contineus to do that move until switch is made
if motion to switch takes longer then 35 seconds maxmotorruntime
then turns off motor and comes in a serial error reporting loop
safety first ;-)!!!
actual motor runtime millis can be read/seen in arduino serial terminal // serial output is better readable // * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA * 02110-1301, USA. */ /* * I'm hoping that if you use/modify this code, you will share your * coop project with me and the world (pictures, whatever) * I'm big on sharing. * Cheers, * //D */ //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended //DANGER DANGER DANGER //STILL NEEDS A MAX OPEN SAFETY SWITCH // do not use this code unattended // Although it is safer then David Naves because motor only runs for 35 seconds maximum // print debug messages or not to serial const boolean SerialDisplay = true; // pins assignments // temperature chip i/o const int photocellPin = A0; // photocell connected to analog 0 const int enableCoopDoorMotorB = 10; // enable motor b const int directionCloseCoopDoorMotorB = 8; // direction close motor b const int directionOpenCoopDoorMotorB = 9; // direction open motor b const int bottomSwitchPin = 2; // bottom switch is connected const int topSwitchPin = 3; // top switch is connected const int coopDoorOpenLed = 13; // led set to digital const int coopDoorClosedLed = 13; // led set to digital // variables // photocell int photocellReading; // analog reading of the photocel int photocellReadingLevel; // photocel reading levels (dark, light) // reed switches top and bottom of coop door // top switch int topSwitchPinVal; // top switch var for reading the pin status // bottom switch int bottomSwitchPinVal; // bottom switch var for reading the pin status // photocell reading delay unsigned long lastPhotocellReadingTime = 0; unsigned long photocellReadingDelay = 1000; // 1 second //kill motor if runtime is to long do not burn the chickenhouse down unsigned long maxmotorruntime = 35000; //35 seconds adjust to your runtime // ************************************** the setup ************************************** void setup(void) { Serial.begin(9600); // initialize serial port hardware // welcome message if (SerialDisplay) { Serial.println(" Hello World, Hello Chickens, Ladies and Gentlemen Processes running:"); Serial.println(" Timer doReadPhotoCell every ?? - light levels: open or close door"); } // coop door // coop door motor pinMode (enableCoopDoorMotorB, OUTPUT); // enable motor pin = output pinMode (directionCloseCoopDoorMotorB, OUTPUT); // motor close direction pin = output pinMode (directionOpenCoopDoorMotorB, OUTPUT); // motor open direction pin = output // coop door leds pinMode (coopDoorOpenLed, OUTPUT); // enable coopDoorOpenLed = output pinMode (coopDoorClosedLed, OUTPUT); // enable coopDoorClosedLed = output digitalWrite(coopDoorClosedLed, LOW); // coop door switches // bottom switch pinMode(bottomSwitchPin, INPUT_PULLUP); // set bottom switch pin as input // activate bottom switch resistor // top switch pinMode(topSwitchPin, INPUT_PULLUP); // set top switch pin as input // activate top switch resistor } // ************************************** functions ************************************** // operate the coop door // photocel to read levels of exterior light void doReadPhotoCell() { // function to be called repeatedly - per coopPhotoCellTimer set in setup photocellReading = analogRead(photocellPin); if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) { lastPhotocellReadingTime = millis(); // set photocel threshholds if (photocellReading <= 100) { photocellReadingLevel = 'Dark'; // do some output action play music Fear off the Dark if (SerialDisplay) Serial.println(" Photocel Reading Level: - Dark"); } if (photocellReading >= 600 ) { photocellReadingLevel = 'Light'; // do some output action hoerree a new day // ok roosters do your thing if (SerialDisplay) Serial.println(" Photocel Reading Level: - Light"); } if (SerialDisplay) { Serial.print(" Photocel Analog Reading = "); Serial.println(photocellReading); } } } // stop the coop door motor void stopCoopDoorMotorB() { digitalWrite (directionCloseCoopDoorMotorB, LOW); // turn off motor close direction digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn on motor open direction analogWrite (enableCoopDoorMotorB, 0); // enable motor, 0 speed Serial.println(" Door motor stop:"); } // close the coop door motor (motor dir close = clockwise) void closeCoopDoorMotorB() { digitalWrite (directionCloseCoopDoorMotorB, HIGH); // turn on motor close direction digitalWrite (directionOpenCoopDoorMotorB, LOW); // turn off motor open direction analogWrite (enableCoopDoorMotorB, 255); // enable motor, full speed unsigned long currentMillis = millis(); while (digitalRead(bottomSwitchPin) != 0){ Serial.print(" Door moving down to bottomswitch "); //wait for switch loop Serial.println(millis()-currentMillis); //print runtime if(millis()-currentMillis>=maxmotorruntime){ //motor takes to long to reach switch while(1==1){ //error reporting loop stopCoopDoorMotorB(); //stop motor Serial.println(" error motor time to long to reach switch - danger!"); Serial.println(" Danger! check whats wrong and press reset button on arduino"); delay(1000); } } } if (digitalRead(bottomSwitchPin) == 0) { // if bottom reed switch circuit is closed stopCoopDoorMotorB(); if (SerialDisplay) { Serial.print(" Door is Closed, topswitchpin = "); Serial.print(digitalRead(topSwitchPin)); Serial.print(" bottomswitchpin = "); Serial.println(digitalRead(bottomSwitchPin)); delay(1000); // do some output action here blink a car horn } } } // open the coop door (motor dir open = counter-clockwise) void openCoopDoorMotorB() { digitalWrite(directionCloseCoopDoorMotorB, LOW); // turn off motor close direction digitalWrite(directionOpenCoopDoorMotorB, HIGH); // turn on motor open direction analogWrite(enableCoopDoorMotorB, 255); // enable motor, full speed unsigned long currentMillis = millis(); while (digitalRead(topSwitchPin) != 0){ Serial.print(" Door moving up to topswitch "); //wait for switch loop Serial.println(millis()-currentMillis); //print runtime if(millis()-currentMillis>=maxmotorruntime){ //motor takes to long to reach switch while(1==1){ //error reporting loop stopCoopDoorMotorB(); //stop motor Serial.println(" error motor time to long to reach switch - danger!"); Serial.println(" Danger! check whats wrong and press reset button on arduino"); delay(1000); // do some output action here blink a car horn } } } if (digitalRead(topSwitchPin) == 0) { // if top reed switch circuit is closed stopCoopDoorMotorB(); if (SerialDisplay) { Serial.print(" Door is open, topswitchpin = "); Serial.print(digitalRead(topSwitchPin)); Serial.print(" bottomswitchpin = "); Serial.println(digitalRead(bottomSwitchPin)); delay(1000); } } } // do the coop door void doCoopDoor() { if (photocellReadingLevel == 'Dark') { closeCoopDoorMotorB(); // close the door } else if (photocellReadingLevel == 'Light') { openCoopDoorMotorB(); // Open the door } } // ************************************** the loop ************************************** //http://84.106.2.21:8888/forum/index.php?action=view&id=255 //KippenGek Dirk Luberth Dijkman Bangert 30 Andijk The Netherlands //http://paypal.me/pools/c/8amUN5rgb9 void loop() { doReadPhotoCell(); doCoopDoor(); }





this is what you see as feedback on arduino ide terminal
value is motor runtime in milliseconds
you can see something like 32205 and 33222 => safety maxmotorruntime is set to 35 seconds
if no endswitch detected in maxmotorruntime=35 seconds then shutdown motor and go into error reporting loop





think this is my version for maximum safety
maximum motorruntime protection
and an extra safety switch NC normally closed switch at maximum door up for overtravel protection
i think this will be safe to use

/*
//i used code from
 * Copyright 2015, David Naves (http://daveworks.net, http://davenaves.com)
 *
 //but changed a lot
//http://84.106.2.21:8888/forum/index.php?action=view&id=255
//KippenGek Dirk Luberth Dijkman Bangert 30 Andijk The Netherlands
//http://paypal.me/pools/c/8amUN5rgb9
 //
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not,  write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 
 * 02110-1301, USA. 
 
 */

/*
* I'm hoping that if you use/modify this code, you will share your
 * coop project with me and the world (pictures, whatever)
 * I'm big on sharing.
 * Cheers,
 * //D
 */



// print debug messages or not to serial
const boolean SerialDisplay = true;




// pins assignments

// temperature chip i/o
const int photocellPin = A0;                  // photocell connected to analog 0
const int enableCoopDoorMotorB = 10;          // enable motor b 
const int directionCloseCoopDoorMotorB = 8;   // direction close motor b 
const int directionOpenCoopDoorMotorB = 9;    // direction open motor b 
const int bottomSwitchPin = 2;                // bottom switch is connected 
const int topSwitchPin = 3;                   // top switch is connected 

const int overtravelSwitchPin = 4;           // NC normally closed safety kill switch on maximum up

const int coopDoorOpenLed = 13;              // led set to digital 
const int coopDoorClosedLed = 13;            // led set to digital 

// variables

// photocell
int photocellReading;                            // analog reading of the photocel
int photocellReadingLevel;                       // photocel reading levels (dark, light)

// reed switches top and bottom of coop door
// top switch
int topSwitchPinVal;                   // top switch var for reading the pin status
// bottom switch
int bottomSwitchPinVal;                // bottom switch var for reading the pin status

// photocell reading delay
unsigned long lastPhotocellReadingTime = 0;
unsigned long photocellReadingDelay = 5000;   // 10 minutes

//kill motor if runtime is to long do not burn the chickenhouse down
unsigned long maxmotorruntime=35000;       //35 seconds adjust to your runtime




// ************************************** the setup **************************************

void setup(void) {

  Serial.begin(9600); // initialize serial port hardware


  // welcome message
  if (SerialDisplay) {
    Serial.println(" Processes running:");
    Serial.println(" Timer doReadPhotoCell every ??? minutes - light levels: open or close door");
  }


  // coop door

  // coop door motor
  pinMode (enableCoopDoorMotorB, OUTPUT);           // enable motor pin = output
  pinMode (directionCloseCoopDoorMotorB, OUTPUT);   // motor close direction pin = output
  pinMode (directionOpenCoopDoorMotorB, OUTPUT);    // motor open direction pin = output

  // coop door leds
  pinMode (coopDoorOpenLed, OUTPUT);                // enable coopDoorOpenLed = output
  pinMode (coopDoorClosedLed, OUTPUT);              // enable coopDoorClosedLed = output
  digitalWrite(coopDoorClosedLed, LOW);

  // coop door switches
  // bottom switch
  pinMode(bottomSwitchPin,  INPUT_PULLUP);         // set bottom switch pin as input
  // activate bottom switch resistor

  // top switch
  pinMode(topSwitchPin, INPUT_PULLUP);             // set top switch pin as input
  // activate top switch resistor

  pinMode(overtravelSwitchPin, INPUT_PULLUP);       // safety kill switch on maximum up

}

// ************************************** functions **************************************



// operate the coop door

// photocel to read levels of exterior light

void doReadPhotoCell() { // function to be called repeatedly - per coopPhotoCellTimer set in setup

  photocellReading = analogRead(photocellPin);

  if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) {
    lastPhotocellReadingTime = millis();

    //  set photocel threshholds
    if (photocellReading <= 4) {
      photocellReadingLevel = 'Dark';
      // do some output action play music Fear off the Dark
      if (SerialDisplay) Serial.println(" Photocel Reading Level: - Dark");

      closeCoopDoorMotorB();
    }
    if (photocellReading  >= 20) {
      photocellReadingLevel = 'Light';
      // do some output action hoerree a new day
      // ok roosters do your thing
      if (SerialDisplay) Serial.println(" Photocel Reading Level: - Light");

      openCoopDoorMotorB();
    }
    if (SerialDisplay) {
      Serial.print(" Photocel Analog Reading = ");
      Serial.println(photocellReading);
      Serial.print(" overtravelSwitchPin = ");
      Serial.println(digitalRead(overtravelSwitchPin));
    }
  }
}




// stop the coop door motor
void stopCoopDoorMotorB() {
  digitalWrite (directionCloseCoopDoorMotorB, LOW);      // turn off motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn on motor open direction
  analogWrite (enableCoopDoorMotorB, 0);                 // enable motor, 0 speed
  Serial.println(" Door motor stop:");
}








// stop the coop door motor overtravel maximum up switch detected
void overtravel() {
  digitalWrite (directionCloseCoopDoorMotorB, LOW);      // turn off motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn on motor open direction
  analogWrite (enableCoopDoorMotorB, 0);                 // enable motor, 0 speed
  Serial.println(" Door motor stop: overtravel maximum up position danger");
  while(1==1){                                             //error reporting loop                                  
    Serial.println(" Door motor stop: overtravel maximum up position danger");
    Serial.println(" program halted // endless loop 1==1");    
    Serial.println(" check what is the problem and press reset button on arduino board");
    delay(1000);
    // do some output action here blink a car horn
  }    
}








// close the coop door motor (motor dir close = clockwise)
void closeCoopDoorMotorB() {


  digitalWrite (directionCloseCoopDoorMotorB, HIGH);     // turn on motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn off motor open direction
  analogWrite (enableCoopDoorMotorB, 255);               // enable motor, full speed

  unsigned long currentMillis = millis();

  while (digitalRead(bottomSwitchPin) != 0){
    if (digitalRead(overtravelSwitchPin) != 0) overtravel();   // door is way to high emergency top switch
    Serial.print(" Door moving down to bottomswitch ");        //wait for switch loop
    Serial.println(millis()-currentMillis);                    //print runtime               
    if(millis()-currentMillis>=maxmotorruntime){               //motor takes to long to reach switch
      while(1==1){                                             //error reporting loop
        stopCoopDoorMotorB();                                  //stop motor
        Serial.println(" error motor time to long to reach switch - danger!");
        Serial.println(" Danger! check whats wrong and press reset button on arduino");
        delay(1000);
      }     
    }
  }

  if (digitalRead(bottomSwitchPin) == 0) {                         // if bottom reed switch circuit is closed
    stopCoopDoorMotorB();
    if (SerialDisplay) {
      Serial.print(" Door is Closed, topswitchpin = ");
      Serial.print(digitalRead(topSwitchPin));
      Serial.print(" bottomswitchpin = ");
      Serial.println(digitalRead(bottomSwitchPin));
      delay(1000);
      // do some output action here blink a car horn
    }
  }
}






// open the coop door (motor dir open = counter-clockwise)
void openCoopDoorMotorB() {
  digitalWrite(directionCloseCoopDoorMotorB, LOW);       // turn off motor close direction
  digitalWrite(directionOpenCoopDoorMotorB, HIGH);       // turn on motor open direction
  analogWrite(enableCoopDoorMotorB, 255);                // enable motor, full speed

  unsigned long currentMillis = millis();

  while (digitalRead(topSwitchPin) != 0){
    if (digitalRead(overtravelSwitchPin) != 0) overtravel();    // door is way to high emergency top switch
    Serial.print(" Door moving up to topswitch ");              //wait for switch loop
    Serial.println(millis()-currentMillis);                     //print runtime 
    if(millis()-currentMillis>=maxmotorruntime){                //motor takes to long to reach switch
      while(1==1){                                              //error reporting loop
        stopCoopDoorMotorB();                                   //stop motor
        Serial.println(" error motor time to long to reach switch - danger!");
        Serial.println(" Danger! check whats wrong and press reset button on arduino");
        delay(1000);
        // do some output action here blink a car horn
      }     
    }
  }

  if (digitalRead(topSwitchPin) == 0) {                            // if top reed switch circuit is closed
    stopCoopDoorMotorB();
    if (SerialDisplay) {
      Serial.print(" Door is open, topswitchpin = ");
      Serial.print(digitalRead(topSwitchPin));
      Serial.print(" bottomswitchpin = ");
      Serial.println(digitalRead(bottomSwitchPin));
      delay(1000);
    }
  }
}





// ************************************** the loop **************************************
//http://84.106.2.21:8888/forum/index.php?action=view&id=255
//KippenGek Dirk Luberth Dijkman Bangert 30 Andijk The Netherlands
//http://paypal.me/pools/c/8amUN5rgb9

void loop() {

  doReadPhotoCell();

}













hmmmm i find input pullup ground to input confusing
a closed switch gives a zero an open switch gives 1

does input pulldown +5vdc to input make more sense for normal people
ok arduino has no pull down resistors inside chip
wel it makes sense when connected to ground = 0 when switch is open input is pulled high = 1






monitor your arduino in a linux terminal screen in my case a raspberry pi raspbian terminal
sudo apt-get install screen
screen
screen /dev/ttyUSB1 9600
how do you stop screen ctr+c is not working
well you can kill SCREEN in task manager
You can use “Ctrl+a” and then “k”. You should get a message if you want to kill the screen y/n
screen
Really kill this window [y/n]




maybe its better to add also a timed close
in summer it stays light verry long
chickens will go to sleep at 21:00 max?
so close door in summer at 21:30?
i saw that there is a sunrise sunset library with geoposition for arduino
so maybe add an lcd or oled display and add a rotary encoder pushbutton for menu timesetting?
then whe can make timed open close a possebility
https://create.arduino.cc/projecthub/sfrwmaker/sun-and-moon-times-cd1629







Can the Arduino Digital I/O Pins, Sink more current than it can Source?
>>>>>Sink and source capability are essentially the same. The datasheet for the Atmega 328 has all the details
i think max 20 MilliAmpere is safe 0.020 Ampere
Some info about sourcing and sinking a output pin
sink a digitalpin can be high when its pulled to ground
or
source a digitalpin can be high when its providing 3.3-5vdc



//  Sink and Source Blink Switching a LED on and off
//  This example is part of the Fritzing Creator Kit: www.fritzing.org/creator-kit.
 
#define LED_SOURCING 2             // name the pins
#define LED_SINKING 3
 
void setup() {                     // the setup() method is executed only once
  pinMode(LED_SOURCING, OUTPUT);   // the LED_SOURCING PIN is declared as digital output
  pinMode(LED_SINKING, OUTPUT);    // the LED_SINKING PIN is declared as digital output
}
 
void loop() {                      // the loop() method is repeated
  digitalWrite(LED_SOURCING, HIGH);// switching on the LED_SOURCING
  digitalWrite(LED_SINKING, HIGH); // switching off the LED_SINKING
  delay(1000);                     // stopping the program for 1000 milliseconds
  digitalWrite(LED_SOURCING, LOW); // switching off the LED_SOURCING
  digitalWrite(LED_SINKING, LOW);  // switching on the LED_SINKING
  delay(1000);                     // stopping the program for 1000 milliseconds
}







How to connect an I2C LCD Display to an Arduino NANO
I2C or IIC is a 2 wire interface TWI inter ic communication max. 1meter? invented by philips 1980
better if we can see ldr light value switchstate and alarms


http://www.arduinotutorialonline.com/2018/01/how-to-connect-i2c-lcd-display-to_12.html


Arduino connect 1 or more Dallas ds18b20 onewire digital temperature sensor 0.0625 °ree;C resolution
hmmm maybe i2c temperature sensor is easier since im allready plan to use an i2c lcd
https://www.aliexpress.com/premium/i2c-temperature.html?SearchText=i2c+temperature
then temp sensor can use the same/share 2 digital io as lcd i2c bus
and maybe later also an i2c i/o expander if we are short in io
https://www.aliexpress.com/premium/i2c-temperature.html?SearchText=i2c+io+expander


Arduino i2c iic twi temperature






Arduino ide File=>Examples=>LiquidCrystal=>SerialDisplay
https://www.arduino.cc/en/Tutorial/LiquidCrystalSerialDisplay An Arduino is sending via TX to another Arduino RX (and 5v and GND) wich is connected to an 16x2 LCD
more or less an terminal arduino displaying Serial.print(" test "); commands
Serial.println("test") displays some weird characters on the diplsay like test||
Treid it with some old LCD 16x2
but the example does not go to line 2 of LCD
if you make your first line 40 characters long (= 16 vissible 24 not visible)
then it goes to line 2
thought this example would be nice but i wait for the i2c displays
and i will use 20x4 display














my chickerdoor so far
with overtravel safety switch
with maxmotorruntime
with TwoWireInterface TWI iic i2c 16x2 LCD screen for information
Thank's Ben https://benselectronics.nl/i2c-module-1602-2004-lcd/
for the SuperFast delivery of i2c LCD backpack
i will switch to 20x4 later for more text



/* Arduino mega uno nano micro mini etc. D.I.Y. waste off time project
   Safe FoxProof Chicken Door with LDR open/close on lightlevel
   modified version luberth dijkman http://www.luberth.com 
   i do not say no to a cup off coffee http://paypal.me/pools/c/8amUN5rgb9
//i used code from
   Copyright 2015, David Naves (http://daveworks.net, http://davenaves.com)
//But changed A LOT...
//
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   as published by the Free Software Foundation; either version 3
   of the License, or (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not,  write to the Free Software
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   02110-1301, USA.

*/

/*
  I'm hoping that if you use/modify this code, you will share your
   coop project with me and the world (pictures, whatever)
   I'm big on sharing.
   Cheers,
   //D
*/
//http://84.106.2.21:8888/forum<wbr />/index.php?action=view&id=255
//http://www.luberth.com



#include <LiquidCrystal_I2C.h>
/*


   void clear();
  void home();
  void noDisplay();
  void display();
  void noBlink();
  void blink();
  void noCursor();
  void cursor();
  void scrollDisplayLeft();
  void scrollDisplayRight();
  void printLeft();
  void printRight();
  void leftToRight();
  void rightToLeft();
  void shiftIncrement();
  void shiftDecrement();
  void noBacklight();
  void backlight();
  void autoscroll();
  void noAutoscroll();
  void createChar(uint8_t, uint8_t[]);
  void createChar(uint8_t location, const char *charmap);


*/
LiquidCrystal_I2C lcd(0x27, 16, 2); // set the LCD address to 0x27 for a 16 chars and 2 line display

byte smiley[8] = {
  B00000,
  B10001,
  B00000,
  B00000,
  B10001,
  B01110,
  B00000,
};

byte bslash[8] = {
  B00000,
  B10000,
  B01000,
  B00100,
  B00010,
  B00001,
  B00000,
};

byte uparrow[8] = {
  B00100,
  B01110,
  B11111,
  B00100,
  B00100,
  B00100,
  B00100,
};


byte downarrow[8] = {
  B00100,
  B00100,
  B00100,
  B00100,
  B11111,
  B01110,
  B00100,
};

// print debug messages or not to serial
const boolean SerialDisplay = true;




// pins assignments

// I2C LCD temperature chip i/o
// SDA SCL to i2c LCD

const int photocellPin = A0;                  // photocell connected to analog 0
const int enableCoopDoorMotorB = 10;          // enable motor b - pin 7
const int directionCloseCoopDoorMotorB = 8;   // direction close motor b - pin 8
const int directionOpenCoopDoorMotorB = 9;    // direction open motor b - pin 9
const int bottomSwitchPin = 2;                // bottom switch is connected to pin 26
const int topSwitchPin = 3;                   // top switch is connected to pin 27

const int overtravelSwitchPin = 4;           // NC normally closed safety kill switch on maximum up
const int hall = 5;           // NC normally closed safety kill switch on maximum up
const int coopDoorOpenLed = 13;              // led set to digital pin 40
const int coopDoorClosedLed = 13;            // led set to digital pin 41

// variables

// photocell
int photocellReading;                            // analog reading of the photocel
int photocellReadingLevel;                       // photocel reading levels (dark, light)

// reed switches top and bottom of coop door
// top switch
int topSwitchPinVal;                   // top switch var for reading the pin status
// bottom switch
int bottomSwitchPinVal;                // bottom switch var for reading the pin status

// photocell reading delay
unsigned long lastPhotocellReadingTime = 0;
unsigned long photocellReadingDelay = 500;   // 10 minutes

//kill motor if runtime is to long do not burn the chickenhouse down
  unsigned long maxmotorruntime = 36000;     //36 seconds adjust to your runtime
  int darksetting = 10;   //ldr closedoor setting
  int lightsetting = 100; //ldr open door setting



// ************************************** the setup **************************************
<wbr />
void setup(void) {
  
  Serial.begin(9600); // initialize serial port hardware

  lcd.init();                      // initialize the lcd
  // Print a message to the LCD.
  lcd.backlight();  
  lcd.createChar(0, smiley);
  lcd.createChar(1, bslash);
  lcd.createChar(2, uparrow); 
  lcd.createChar(3, downarrow);
  
  lcd.setCursor(8, 0); 
  lcd.write(byte(0));  //smiley
  delay(2000);
   
  lcd.setCursor(0, 0);
  lcd.print("<<Chicken Door>>");    
  lcd.setCursor(0, 1);
  lcd.print("Luberth.com 2019");
  lcd.blink();
  delay(5000);
  lcd.noBlink();
  // welcome message
  //if (SerialDisplay) {
  // Serial.println(" Processes running:");
  // Serial.println(" Timer doReadPhotoCell every ??? minutes - light levels: open or close door");
  // }


  // coop door

  // coop door motor
  pinMode (enableCoopDoorMotorB, OUTPUT);           // enable motor pin = output
  pinMode (directionCloseCoopDoorMotorB, OUTPUT);   // motor close direction pin = output
  pinMode (directionOpenCoopDoorMotorB, OUTPUT);    // motor open direction pin = output

  // coop door leds
  pinMode (coopDoorOpenLed, OUTPUT);                // enable coopDoorOpenLed = output
  pinMode (coopDoorClosedLed, OUTPUT);              // enable coopDoorClosedLed = output
  digitalWrite(coopDoorClosedLed, LOW);

  // coop door switches
  // bottom switch
  pinMode(bottomSwitchPin,  INPUT_PULLUP);         // set bottom switch pin as input
  // activate bottom switch resistor

  // top switch
  pinMode(topSwitchPin, INPUT_PULLUP);             // set top switch pin as input
  // activate top switch resistor

  pinMode(overtravelSwitchPin, INPUT_PULLUP);       // safety kill switch on maximum up
  pinMode(hall, INPUT_PULLUP);
}

// ************************************** functions **************************************
<wbr />


// operate the coop door

// photocel to read levels of exterior light

void doReadPhotoCell() { // function to be called repeatedly - per coopPhotoCellTimer set in setup

  photocellReading = analogRead(photocellPin);

  if ((unsigned long)(millis() - lastPhotocellReadingTime) >= photocellReadingDelay) {
    lastPhotocellReadingTime = millis();

    //  set photocel threshholds
    if (photocellReading <= darksetting) {
      photocellReadingLevel = 'Dark';
      // do some output action play music Fear off the Dark
      //if (SerialDisplay) Serial.println(" Photocel Reading Level: - Dark");

      closeCoopDoorMotorB();
    }
    if (photocellReading  >= lightsetting) {
      photocellReadingLevel = 'Light';
      // do some output action hoerree a new day
      // ok roosters do your thing
      // if (SerialDisplay) Serial.println(" Photocel Reading Level: - Light");

      openCoopDoorMotorB();
    }
    if (SerialDisplay) {

      Serial.print("Topswitch=");
      Serial.print(digitalRead(topSwitchPin));<wbr />
      Serial.print(" Bottomswitch=");
      Serial.print(digitalRead(bottomSwitchPin<wbr />));
      Serial.print(" overtravelswitch=");
      Serial.println(digitalRead(overtravelSwi<wbr />tchPin));
      Serial.print("LDR=");
      Serial.print(photocellReading);
      Serial.print(" close when ldr=");
      Serial.print(darksetting);
      Serial.print(" open when ldr=");
      Serial.println(lightsetting);
      //delay(500);

      //Serial.print(" hal = ");
      //Serial.println(digitalRead(hall));
    }
    lcd.clear();
    lcd.backlight();
    lcd.setCursor(0, 0);
    lcd.write(byte(2));  //uparrow
    lcd.print("=");
    lcd.print(digitalRead(topSwitchPin));
    lcd.print(" ");
    lcd.write(byte(3));  //downarrow
    lcd.print("=");
    lcd.print(digitalRead(bottomSwitchPin));<wbr />
    lcd.print(" Max");
    lcd.write(byte(2));  //uparrow
    lcd.print("=");
    lcd.print(digitalRead(overtravelSwitchPi<wbr />n));
    lcd.setCursor(0, 1);
    lcd.print("LDR=");
    lcd.print(photocellReading);
    lcd.setCursor(8, 1);
    lcd.write(byte(3));  //downarrow
    lcd.print(darksetting);
    lcd.write(byte(2));  //uparrow
    lcd.print(lightsetting);

// draw i am alive spinner
      lcd.setCursor(15, 1); 
      lcd.print("|"); 
      delay(150); 
      lcd.setCursor(15,1); 
      lcd.print("/"); 
      delay(150); 
      lcd.setCursor(15,1); 
      lcd.print("-"); 
      delay(150);
      lcd.setCursor(15,1);  
      lcd.write(byte(1));  // "/" is error "//" backslash is yen sign
      delay(140);
   
  }
}




// stop the coop door motor
void stopCoopDoorMotorB() {
  digitalWrite (directionCloseCoopDoorMotorB, LOW);      // turn off motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn on motor open direction
  analogWrite (enableCoopDoorMotorB, 0);                 // enable motor, 0 speed
  //Serial.println(" Door motor stop:");
}








// stop the coop door motor overtravel maximum up switch detected
void overtravel() {
  digitalWrite (directionCloseCoopDoorMotorB, LOW);      // turn off motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn on motor open direction
  analogWrite (enableCoopDoorMotorB, 0);                 // enable motor, 0 speed

  lcd.clear();
  while (1 == 1) {                                         //error reporting loop
    // write warning to serial
    Serial.println(" Door motor stop: overtravel maximum up position danger");
    Serial.println(" program halted // endless loop 1==1");
    Serial.println(" check what is the problem and press reset button on arduino board");

    // write warning to i2c lcd and blink backlight
    lcd.setCursor(0, 0);
    lcd.print("Stop OverTravel!");
    lcd.setCursor(0, 1);
    lcd.print("Danger to > Up");
    lcd.backlight();
    delay(1000);
    lcd.noBacklight();
    // do some output action here blink a car horn
  }
}








// close the coop door motor (motor dir close = clockwise)
void closeCoopDoorMotorB() {
  lcd.clear();
  digitalWrite (directionCloseCoopDoorMotorB, HIGH);     // turn on motor close direction
  digitalWrite (directionOpenCoopDoorMotorB, LOW);       // turn off motor open direction
  analogWrite (enableCoopDoorMotorB, 255);               // enable motor, full speed

  unsigned long currentMillis = millis();

  while (digitalRead(bottomSwitchPin) != 0) {
    if (digitalRead(overtravelSwitchPin) != 0) overtravel();   // door is way to high emergency top switch
    Serial.println("Move Down");        //wait for switch loop
    Serial.println(millis() - currentMillis);                  //print runtime
    lcd.setCursor(0, 0);
    lcd.print("DoorMove Down!");
    lcd.setCursor(0, 1);
    lcd.print(millis() - currentMillis);
    lcd.print(" Max=");
    lcd.print(maxmotorruntime);
    if (millis() - currentMillis >= maxmotorruntime) {         //motor takes to long to reach switch
      while (1 == 1) {                                         //error reporting loop
        stopCoopDoorMotorB();                                  //stop motor
        Serial.println("MaxMotorRunTime");
        Serial.println("Danger!");
        // write warning to i2c lcd and blink backlight
        lcd.setCursor(0, 0);
        lcd.print("Max MotorRunTime");
        lcd.setCursor(0, 1);
        lcd.print("Danger");
        lcd.backlight();
        delay(1000);
        lcd.noBacklight();
      }
    }
  }

  if (digitalRead(bottomSwitchPin) == 0) {                         // if bottom reed switch circuit is closed
    stopCoopDoorMotorB();
  }
}






// open the coop door (motor dir open = counter-clockwise)
void openCoopDoorMotorB() {
  lcd.clear();
  digitalWrite(directionCloseCoopDoorMotor<wbr />B, LOW);       // turn off motor close direction
  digitalWrite(directionOpenCoopDoorMotorB<wbr />, HIGH);       // turn on motor open direction
  analogWrite(enableCoopDoorMotorB, 255);                // enable motor, full speed

  unsigned long currentMillis = millis();

  while (digitalRead(topSwitchPin) != 0) {
    if (digitalRead(overtravelSwitchPin) != 0) overtravel();    // door is way to high emergency top switch
    Serial.println("Move up");              //wait for switch loop
    Serial.println(millis() - currentMillis);                   //print runtime
    lcd.setCursor(0, 0);
    lcd.print("DoorMove Up!");
    lcd.setCursor(0, 1);
    lcd.print(millis() - currentMillis);
    lcd.print(" Max=");
    lcd.print(maxmotorruntime);

    if (millis() - currentMillis >= maxmotorruntime) {          //motor takes to long to reach switch
      while (1 == 1) {                                          //error reporting loop
        stopCoopDoorMotorB();                                   //stop motor
        Serial.println("MaxMotorRunTime");
        Serial.println("Danger!");
        // write warning to i2c lcd and blink backlight
        lcd.setCursor(0, 0);
        lcd.print("Max MotorRunTime");
        lcd.setCursor(0, 1);
        lcd.print("Danger");
        lcd.backlight();
        delay(1000);
        lcd.noBacklight();
      }
    }
  }

  if (digitalRead(topSwitchPin) == 0) {                            // if top reed switch circuit is closed
    stopCoopDoorMotorB();
  }
}





// ************************************** the loop **************************************
<wbr />
void loop() {

  doReadPhotoCell();

}












FTDI to arduino pro mini
i use a pro mini now but i do not like the seperate usb pcb
i prefer the usb arduino ones
some say the arduino pro mini uses less energy better for battery operated devices










now 20x40 lcd display
and add an i2c temperature sensor
nice if you can see temperature ;-)


3d printers
https://www.thingiverse.com/search?q=16x2+lcd https://www.thingiverse.com/search?q=20x4+lcd
My design is over design because i had these materials
Thinking of putting something like this 3d print directly on the gearmotor shaft
Do usefull things with a 3d printer ;-)
and use a thinner string
Need a tight 6mm shafthole with D shape hole in it ->D<- 5.5mm
and a 1mm hole from side to middle for string mount winding
ANY 3D designers out there that like 3D drawing???!!!
https://www.thingiverse.com/thing:2494037


3D print test, not perfect yet but not bad

Look Mummy, i do something useful with my 3D printer, no more Puppets ;-)

i have no fancy fast 64bit computers that most 3d cad programs want
FreeCad runs but find all the workplaces, menus so hard to use
after strugling for 2 hours with web sketchup
https://app.sketchup.com/app?hl=en
nice it runs reasonable well, its to use on my raspberry pi desktop
i got myself a diabolo with D shaped hole and a string hole from side to middle

the circle are a bit segmented
should use more segments as default setting 24 circle segments
http://84.106.2.21:8888/forum/images/diabolo.skp
http://84.106.2.21:8888/forum/images/diabolo.stl
https://3dwarehouse.sketchup.com/model/e82636fa-4d7a-4786-91b3-0393a554366c/Gearmotor-wire-wound-diabolo

That is Nice! a Live 3D viewer


3D printer Creality Ender 3 Slic3r settings i used for fine print Diabolo
http://84.106.2.21:8888/forum/images/creality_ender_3_slic3r_.diabolo_settings.ini

This is Great, Now i can Design More:
a 3D printed Hall sensor mount
a 3D printed Neodymium magnet mount for the Hall Sensor

new simpeler design with sketchup designed, creality ender3 3d printed diabolo on gearmotor, works perfect
the diabolo wire wounding pulley is a bit OverKill, this is all the wire
diameter +/-15mm so every rotation 45mm doormove, 12x45mm per minut if you want slower PWM signal on L298 Enable you can do up to half the speed


Diabolo Slic3r generating layers for 3d printer gcode file


how i draw the diabolo
Sketchup videos http://84.106.2.21:8888/forum/index.php?action=view&id=264






https://www.thingiverse.com/search?q=rotary+encoder+knob










Recieved some items from my Cheap Chinese Friend Ali
Arduino Nano with Screw Shield and 20x4 i2c LCD
Connecting a i2c lcd (Using PCF8574 i2c LCD BackPack Board)
Do Not Be Afraid, it will not hurt, a Child / Blond Girl can do This

power comes from usb
screw connections
blue = GND
red = 5v
yellow SDA = A4
green SCL = A5
you may have to adjust the potentio-screw on i2c LCD BackPack board to adjust LCD Contrast
if you mix up SDA-SCL wires, No problem just correct it




5volt power For Nano and LCD from L298N board

12VDC connected to +12VDC and GND on L298N board
blue connected to GND on L298 board and Nano GND
red connected to L298N Board +5vdc and on Nano Vin




todo
connect LDR light resistor on Nano analog input and +5vdc and GND
motor connection on l298n
enable ClockWise CounterClockWise on L298N and Nano
DoorSwitch inputs on Nano
if MotorEncoder on Nano
Maybe rotary encoder pushbutton switch for lcd-menu
barometer thermometer i2c, why not
more time?



world map hits counter
map counter






Please Let me Sleep


End of Message, Thanks For Viewing! ☺
Tip: if your watching on your phone or tablet ⁝ add / save to homescreen and you get a nice icon its Free!
Tip: on your computer or laptop do not forget to bookmark this page its Free!
BookMark ShortCut Keys press ctrl+d on your keyboard




-

-

Reply to this Message


Name
Subject
Message

, <code> <b> <i> <u> .






POLL / VOTE
Did you like this Page id=255 ?

NO:         YES:




   


Design a Bit like ForumOne 4.0 WayBack 1999 ©
Always Read the Small print?!



http://forum.luberth.com - - http://www.luberth.com/forum/

NO COOKIES !?

thanks for your support
Thank You!




Co2 FootPrint WebServer



                         My Cheap Chinese Friend Ali     
Copyright Luberth Dijkman 2018 ... 2019