IoT Chicken Shed (Arduino, Wifi)

Updated 02 August 2018

If you have chickens and find you're not always available to close the gate at night or check the water levels each day, then why not use an ESP8266 to automate your chicken door and receive alerts door status and low water level, as well as allow you to remotely control the door from anywhere over the internet. 

Features

  • Control the door and check how much water is left through a basic website hosted on the chip itself (HTML, and RESTful)
  • Prevent over-closing or over-opening
  • Can recover from power cut outs
  • Can recover from wifi chip reboots or network disruption
  • Flash LED every few seconds to indicate that the door is closed
  • Fox proof: Can’t be pushed open while closed
  • Automatically operated by a script (open/close times are calculated based on sunrise / sunset times for your location)
  • Email alerts for open/closes, failures, water low and water empty
  • Accessible over the internet via VPN

Parts you'll need

Software  

Referenced libraries

Full project code

  • Available on GitHub – all code for the Arduino, esp8266 chip, PowerShell script, and reference libraries

Wiring diagram

 iot-chicken-house-wiring-diagram

How it works / key points

  • Arduino and the ESP8266 have separate processors. They talk to each other through SoftwareSerial. The ESP8266 is running nodeMCU, and scripts sent to it through serial are executed on the chip.
  • The ESP8266 runs a RESTful web server written in LUA (nodeMCU). “/GetStatus” returns an HTML page with links to operate the door. The links point to “/OpenDoor”, “/CloseDoor”. The chip passes these commands on to Arduino through SoftwareSerial.
  • Arduino listens for commands through hardware serial (PC, debugging), or Software Serial (from the ESP8266 wifi chip)
  • Arduino movies the door by enabling power to the motor shield and then moves the stepper motor a pre-determined amount of steps to open or close the door or until the magnetic sensor is tripped (door closed)
  • The stepper motor is moved in chunks of 10 steps so that Arduino can check if a stop command has been received, and also keep the wifi chip updated on the status.
  • When Arduino starts up (e.g. after the power cut) it checks the magnetic relay switch to see if the door is closed. If it is not closed it is assumed to be 100% open
  • Arduino keeps the wifi chip up to date on the status every few seconds using TimerObjects to send a line of LUA script to the wifi chip

Setup guide (hardware)

    • First, connect the Adafruit Motor Shield to the Arduino, and solder on all pins.
    • Connect the hardware as shown in the wiring diagram
    • If you have purchased the identical step motor, then the wire colours shown in the wiring diagram will be correct
    • Use the flex shaft coupler to connect the threaded rod to the step motor
    • To connect the threaded rod to the gate, drill a hole in two very small squares of wood, and glue the nut in between the two pieces, then this can be attached to the door with wire, so that when the motor operates the door will slide up or down as the threaded rot rotates.
    • See the photos below:

iot-chicken-house-stepper-mount-hardware

iot-chicken-house-lead-screw-attached-hardware

iot-chicken-house-hardware-3

iot-chicken-house-hardware-4

iot-chicken-house-all-electronics-connected

iot-chicken-house-all-electronics-connected-in-housing

iot-chicken-house-lead-screw-attached-in-housing

iot-chicken-house-project-mounted

iot-chicken-house-lead-screw-attached-hardware-in-house

iot-chicken-house-side-view-of-stepper-motor-and-coupler-mounted

iot-chicken-house-mounted-project

iot-chicken-house-with-happy-chickens

Setup guide (software)

  • Calibrate the weight sensor by connecting it to Arduino according to the wiring diagram above (through the load cell amplifier) and use the SparkFun HX711 code samples for calibration. This gives you the calibration_factor and zero_factor values which you can hard-code into the Arduino code.
  • Connect the Arduino to USB and upload the Arduino code
  • Connect the ESP8266 to the PC with the FTDI Serial cable and use explorer to upload the LUA application files (upload each file one by one).

NOTE: The wire colours and positions on the FTDI cable didn’t match the pins on the ESP8266 chip in my case, and needed to be switched position. To check this take apart the plastic housing on the USB connector to see the pin labels. The wires need to be connected as below. In my case, the wire colours were as below.

iot-chicken-house-ftdi-table

  • The Huzzah ESP8266 (unlike the plain ESP8266) can deal with the 5v inputs coming from Arduino. If you use an ordinary ESP8266 they need to be dropped to 3.5v.
  • I used a PowerShell script (running on an always-on laptop) to automatically open and close the door at set times, and send water low or empty notifications by email. The script also attaches photos collected from a spare android phone mounted in the shed (IP Camera).

Other comments

  • In extremely hot (e.g. 40ºC) or wet weather, the magnetic relay (door closed) wire picks up so much interference that it can trip (pull the pin to a low). This is probably because the wire is over 1m long. To deal with this, the Arduino code samples it 10 times per second and needs 10 consecutive readings the same before it assumes that the state has changed. This solved the problem.
  • After about 2 months of continuous operation, Arduino can stop responding (probably memory leaks). A regular reboot is enough to deal with it (you could just use a cheap timed power socket that cuts power off briefly once per day)
  • The wifi chip does not have a far-reaching range. If the chip is on the edge of reception it is susceptible to constant crashing. You could extend the range by replacing one of your router's antenna with a "Yagi Cantena" or "Yagi antenna"

    Have a question? Ask the Author of this guide today!

    Please enter minimum 20 characters

    Your comment will be posted (automatically) on our Support Forum which is publicly accessible. Don't enter private information, such as your phone number.

    Expect a quick reply during business hours, many of us check-in over the weekend as well.

    Comments


    Loading...
    Feedback

    Please continue if you would like to leave feedback for any of these topics:

    • Website features/issues
    • Content errors/improvements
    • Missing products/categories
    • Product assignments to categories
    • Search results relevance

    For all other inquiries (orders status, stock levels, etc), please contact our support team for quick assistance.

    Note: click continue and a draft email will be opened to edit. If you don't have an email client on your device, then send a message via the chat icon on the bottom left of our website.

    Makers love reviews as much as you do, please follow this link to review the products you have purchased.