IoT Chicken Shed (Arduino, Wifi)



  • 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


  • Arduino Uno
  • Adafruit Motorshield v2
  • 12v 1A power supply for the Adafruit Motorshield
  • Huzzah ESP8266 breakout for wifi
  • FTDI cable (Serial TTL-232 USB Cable) for uploading LUA apps to the ESP8266 chip. The Huzzah ESP8266 breakout’s RX and VCC pins handle 5v, so the FTDI cable cable voltage does not matter (3.6 and 5v will work).
  • Magnetic Relay for sensing door closed
  • 5V single channel relay to control power supply to the motor shield, as the motor accumulates tremendous heat if not released. While the Arduino app calls the release function, it also cuts power as a fail-safe.
  • LED for indicating door closed, plus two transistors to split the voltage supplied to it (an Arduino output pin was enough to blow the previous LED)
  • Stepper Motor – Mercury Motor SM-42BYG011-25 1812010 (12v 0.33A)
  • Threaded Rod (8mm) – to be driven by the step motor. As it rotates it screws itself onto a nut attached to the door. The rod is in a fixed position so this forces the door to open or close.
  • Flex Shaft Coupler (5mm to 8mm) – to connect the stepper motor’s 5mm output rod to an 8mm threaded rod
  • Load Cell (10kg max) – to measure how much water is left
  • SparkFun Load Cell Amplifier HX711 – used to get measurable data out from a load cell and strain gauge (as the load cell’s analog signal is weak)


Referenced libraries

Full solution code

  • Available on gitbub – all code for the arduino, esp8266 chip, powershell script, and referenced libraries

 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 motorshield 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 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)

Setup guide (software)

  • Calibrate the weight sensor by connecting it to Arduino according to the wire 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 ESPlorer 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 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. In my case this is how it was connected:

PIN   FTDI Wire   Target pin on Huzzah ESP8266       Voltmeter test
RTS   yellow      0 (flow control not used by chip)  V+
RX    white       TX
TX    green       RX                                 V+
VCC   red         V+                                 V+
CTS   blue        4 (flow control not used by chip)
CND   black       GND
  • 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 extemely 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 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)


Advanced Search Web Part – using drop down lists instead of plain text boxes

I’ve wanted to use dropdown lists in the advanced search property restrictions for a long time, so i created a web part to allow it (SearchExtension web part). It can be found on codeplex:

How it works:

  • On page load the web part locates the advanced search box and passes its client ID to the client-side in javascript
  • On the DOM ready event, javascript uses the clientID to find the proprety restriction dropdown lists, and adds events to them
  • The events are triggered when the selected property changes, and cause the plain text box to be hidden, and a drop down list created and displayed in its place. The dropdowns created will pass their selected value to the orginal (hidden) text box which used to be there
  • Dropdown list values are populated using callbacks from SharePoint lists or can be defined static (defined in the configuration XML of the SearchExtension web part)
  • Two properties can be linked as parent/child – eg for “Category” / “Sub-category” scenarios
  • The javascript is cross-browser (IE6+ & recent versions of other browsers: FireFox, Chrome, Safari – earlier versions untested)

Please see the codeplex site for more information.