Ceci est une ancienne révision du document !
This month I begin creating a project that may well come in useful, and practical! My dad has just bought some chickens and wants an automatic way to open and close a coop (sliding) door when it gets light or dark. Enter the Arduino!
Rather than dismantle my precious laser trip wire, I’m using one of several Arduino Nano’s that I bought from China via eBay. They were only a couple of pounds each, and do the exact same job as the Arduino Uno, except they need to be mounted on breadboard or veroboard as they have no sockets for wires, only bare pins.
So, basically what I need is to pull a wire (to open the sliding door) when it gets daylight and release the wire (to close the door) when it gets dark. That means I definitely need a servo, a 100uF capacitor, a light dependent resistor (LDR with a 10k ohm pull-down resistor), and I’ll probably use a couple of LED’s (one red, and one green with a 220 ohm pull-down resistor each) to signal the door status.
My main problems thus far are:
• the servo is always on when the door is open. I need to find a way to hold the wire but stop the servo from whirring as it will inevitably burn out the servo.
• the day/night settings are hardwired into the code. It’d be nice if there was maybe a pot to adjust the settings
The code (at: http://pastebin.com/wNMaXNkC) isn’t too complex. Pre-setup(), I’m initialising the servo, my settings for sun-up and sun-down (for the LDR), the servo angle for the door open/closed, and the pins for the LEDs.
The setup() is assigning the servo pin number and setting it to zero, gives the pin modes for the LEDs (and what to initially set them at), and then uses the serial port so that I can get the LDR values.
My loop() is to read the LDR, then check to see IF the light is near the sun-up value, and, if it is, to open the door, turn the red LED on, the green LED off, and delay for two seconds. Same idea, but in reverse, for sun-down.
I’ll keep you updated as to whether I can fix the servo problem, or if I move onto a new project next month.