SmartCoop: Automate and control your chicken coop with Java

  • SmartCoop combines Raspberry Pi, ESP32-S3 and a proprietary SMD PCB to automate doors, water, food and monitoring of a domestic chicken coop.
  • The system uses Java, H2 database, Javalin web server and MQTT for remote control, graphics and detailed logging of sensors and events.
  • It integrates UHF RFID, weather forecasting, GPS, and energy-saving strategies to improve predator safety and autonomy.
  • It is an open source project aimed at advanced hobbyists, with no commercial purpose, the result of more than ten years of iterations and real improvements.

SmartCoop control chickens with Java

Managing a small chicken coop day after day can become quite a chore: opening and closing doors, checking that there's water and food, watching out for predators… When you also want to be able to get away for several days without depending on a neighbor or caretaker, it starts to make a lot of sense to consider a solution of Complete automation of the chicken coop with technology and programming.

This is how SmartCoop was born, a project by an enthusiast with extensive experience in electronics and embedded development that has evolved over more than a decade into a highly sophisticated system. Its creator lives on a small farm in New South Wales, near Canberra, Australia, and keeps a flock of about 30 chickens. His goal was to minimize routine tasks, improve security against clever foxes, and, incidentally, indulge his passion for designing hardware and writing code. leveraging Raspberry Pi, ESP32-S3 and Java and C++ software.

What is SmartCoop and what is its philosophy?

SmartCoop is basically a comprehensive controller for chicken coops, built around a Raspberry Pi and an ESP32-S3 module mounted on an SMD PCB Custom-designed. It's not a commercial product, nor does it intend to be: its creator maintains it as a personal, open-source project, with no intention of turning it into a business because he already has a demanding job in the Australian defense industry.

The solution is now in its fourth generation (GEN4.x), designed after many years of testing, failures, and iterative improvements. Throughout this time, the system has addressed very specific problems, from winter energy consumption to the cunning of foxes, as well as sensor limitations and the inconvenience of soldering through-hole components. All of this has resulted in a current PCB design with SMD components, USB-C power supply and multiple sensor and actuator interfaces.

SmartCoop's approach is far from the typical automatic door openers you can buy online. Here, the focus is on... Almost total automation of the chicken coop: doors, water, food, data recording, remote monitoring and even RFID reading of the chickensThe system is designed for a semi-rural environment with a moderate number of birds and with real problems of predators and weather.

Furthermore, the author shares both the code and hardware schematics under an open-source license. Anyone interested can download the files from the Bitbucket repository, fabricate their own boards, and even attempt to replicate the assembly. Occasionally, the creator may even provide some of their pre-populated PCBs. charging only the manufacturing cost and helping as much as possible with technical questions.

Hardware architecture: Raspberry Pi, ESP32-S3 and SMD PCB

The heart of the system is a combination of a Raspberry Pi Compute Module (fifth generation) and an ESP32-S3 integrated onto a custom board. The Raspberry Pi handles high-level logic, the web interface, the database, and integration with external services. The ESP32-S3, on the other hand, takes over real-time tasks, interrupt management, direct control of motors and sensors, and low-power functions.

Early versions of the board used through-hole components and a very simple microcontroller (PICAXE-14M2) that barely handled the Raspberry Pi's nightly power on and off. With the move to the fourth generation and SMD assembly, a significant step was taken: replacing that microcontroller with an Unexpected Maker ESP32-S3 module, with Higher power, low consumption, a good development community, and abundant open libraries in C++.

The switch to SMD had several positive effects. On the one hand, the boards are more compact and economical; on the other, the availability and price of surface-mount components are better than their through-hole equivalents. Furthermore, by outsourcing assembly to a manufacturer like PCBWay, the author was able to receive several fully populated PCBs for a similar cost to what he previously paid for blank boards alone, achieving a More professional assembly, with lower power consumption and conveniently powered by USB-C.

One curious detail learned the hard way concerns the external cabling: the local cockatoos pecked at and destroyed the cable bundle, so now the entire field assembly is protected inside corrugated tubing or similar conduit. These kinds of real-world problems have shaped the project's design and explain why the current version includes robust connectors, physical protections and very practical installation decisions.

The PCB, in its most recent iterations, also incorporates additional serial interfaces to communicate with UHF RFID readers, connectors for weight sensors, inductive door sensor inputs, relays for motors, physical button contacts, and other connections necessary to manage the chicken coop with complete flexibility.

Key features of the fourth generation of SmartCoop

The SmartCoop GEN4 brings together a wide range of features designed to free the user from daily tasks and improve bird safety. The system includes a fully automatic main door, whose opening and closing are controlled by combining a light sensor with sunrise and sunset data Calculated based on GPS location. This allows it to adapt to both the time of year and specific lighting conditions.

In addition to the main door that provides access to the interior of the chicken coop, there is a second door (yard door) that controls access to a patio or outdoor area. In this case, the decision to open it or not is based on the official weather forecast from the Australian Bureau of Meteorology (BOM)If the forecast exceeds a certain threshold of rain probability configurable in the database, the system keeps that door closed during the day so that the chickens do not invade the porch of the house in search of shelter… and make a mess.

The controller is complemented by a comprehensive web interface that allows manual operation of the doors, adjustment of configuration parameters, review of sensor histories, and visualization of data in graphs. The board itself includes several physical buttons for opening or closing doors, filling the water tank, and other functions. Power the Raspberry Pi if you want to operate it without accessing the web interface..

Another important component is water management: the system monitors the level of a reservoir and controls its automatic filling. Combined with the tank and filter design devised by the author, this ensures a constant supply of clean water for the chickens, minimizing the need to empty and scrub muddy or algae-filled drinkers. In parallel, the electronics incorporate a programmed on/off logic for the Raspberry Pi to reduce the... nighttime consumption and avoid having to oversize the battery and solar panel.

The system is completed with an open-source relational database (H2), which records sensor data, configuration values, historical events, time information, and other parameters. Additionally, the system has a GPS interface that provides accurate time for synchronizing the real-time clock and latitude and longitude coordinates, useful for automatically calculating sunrise and sunset times even when the Internet access is down and external services cannot be accessed.

For advanced monitoring, SmartCoop publishes real-time information via an MQTT broker, allowing other external applications, panels, or dashboards to display consumption, status, and alerts. With all this, the system becomes a true nerve center for the entire operation, capable of to function virtually without human intervention for several days.

Automation and security against foxes and other predators

One of the recurring headaches on the project farm is foxes. Even though the door closed automatically at dusk, dangerous situations arose: afternoon storms that forced the hens inside the coop before the scheduled time, while the door remained open and the foxes had free rein to get in. This led to the idea of ​​using UHF RFID tags to individually identify each hen.

The logic is simple yet powerful: if all the chickens wear an inexpensive RFID tag (easily obtained on platforms like AliExpress), the system can count how many have already entered the shelter. When it detects that they are all inside, it can close the main door early, without waiting for the automatic closing time. This significantly reduces the window of opportunity a fox has to sneak in by taking advantage of a sudden change in weather or any other unforeseen circumstance—something invaluable in contexts where Predators quickly become "experts" in the patterns of the henhouse.

With the PCB4.4 versions, the design incorporates a UHF RFID reader with four antennas, connected to the Raspberry Pi Compute Module via an RS-232 link managed by the ESP32-S3. This architecture allows for continuous interrogation of the tags, providing real-time information on which animals are inside or outside the enclosure. The author notes that the tag query function is already functional and is currently undergoing further development. integrate this data with the Java application running on the Raspberry Pi and with the H2 database.

Another curious use of RFID reading is egg-laying monitoring. By placing antennas in the nest boxes, each egg can be associated with the hen that laid it, recording which animals lay eggs, how often, and in which box. Although the creator jokes that he doesn't intend to require service-level agreements from his hens or impose production targets, this information could be useful for small-scale farmers working with breeds of genetic heritage or specific selection programs.

The experience with foxes also led to a rethinking of the logic behind the morning opening of the main gate. For a time, the system always opened at the same time, allowing one of these predators to strategically position itself next to the gate a few minutes before it opened. To break this routine, an improvement was developed that incorporates a random component at opening time.

Now, the software downloads a table from its own website showing sunrise and sunset times for the specific location of the farm, taking into account all seasonal variations. Every morning, at approximately sunrise, the controller begins monitoring the light sensor until a defined light threshold is reached. If a maximum time (for example, 60 minutes) is exceeded without reaching the threshold, the gate opens anyway. The result is a dynamic schedule that combines seasonal changes, variations in ambient light, and a safety timeout, making it much more difficult for a fox to gain access. anticipate the exact moment of opening and abuse that fixed pattern.

Advanced water management: from a dirty pond to a near-autonomous system

In the original setup, the hens drank from a small pond or pool. The problem was obvious: depending on the time of year and the water level, the quality varied considerably, and the drinker became dirty quickly, requiring it to be emptied, cleaned, and refilled far too often. To avoid these repetitive tasks, the author designed a complete system with PVC tanks, sand filtration and automated filling.

The system starts with a large tank made from rainwater pipe, which incorporates a sand filter that significantly improves water quality. This main tank feeds a second, smaller tank, also made from 90 mm PVC pipe, which supplies water to the hens through small cups or automatic feeders, similar to those used in commercial farms.

The SmartCoop controller monitors the available water level and activates a pump or valve to refill the service tank when necessary. This virtually eliminates the need for the owner to empty, scrub, and refill the drinking troughs every few days, maintaining a more hygienic and consistent system. By combining this hydraulic component with electronics, the solution achieves a stable, clean water supply that requires almost no daily maintenance.

This improvement is combined with nighttime energy control: if pumps don't need to be run or the Raspberry Pi screen used at night, the system is programmed to partially shut down to save energy. Balancing the available power from the solar panels, battery capacity, and electronics requirements was a serious problem during Canberra's cloudy winters, and the chosen strategy was manage switching on and off intelligently instead of investing in more expensive panels and batteries.

Food control and dispensers with weight sensors

Another critical issue for anyone keeping chickens is feed. If you want to be able to travel for several days, simply filling a small feeder and hoping it will last isn't enough. The author wondered how to get the system to reliably "warn" when the feed was getting low and decided to integrate weight sensors based on the NAU7802 chip in the latest version of the PCB.

The idea is to use these converters and load cells to weigh the contents of the food dispensers. With this information, SmartCoop can estimate how many days' worth of food remain, detect abnormal consumption (for example, due to the presence of other species or rodents), and trigger precise alerts when a low threshold is reached. The design intends for these reservoirs to hold at least a couple of weeks' worth of food, so that The owner and his partner can be away for a few days without having to ask anyone for favors..

Furthermore, the system records consumption in the database, allowing for the review of medium-term patterns: how much the hens eat depending on the time of year, whether consumption changes when animals are added or removed, etc. This can be useful for adjusting rations, forecasting feed purchases, or even detecting health problems in the flock if unusual variations are observed. All this logic is designed so that the Feed management should no longer depend solely on quick glances at the feeder and begin to rely also on objective measures.

Energy consumption, nighttime shutdown, and mobile variants

One of the initial challenges was getting the system to run on a reasonable combination of solar panel and battery without running out of power every few days of bad weather. With a Raspberry Pi and a screen running 24/7, during Canberra winters, just a few cloudy days were enough to drain the battery. Before rushing out to buy a much larger panel and battery, the author decided introduce intelligent power on/off management.

In the initial iterations, a small PICAXE microcontroller was used to cut power to the Raspberry Pi and other components during specific time periods, leveraging information from a real-time clock (RTC). The logic was that while the chickens were sleeping, there was no need to have all the electronics powered on, the sensors running continuously, or the screen displaying information.

With the migration to the SMD board and the ESP32-S3, this responsibility was transferred to the new module, enabling more refined and flexible strategies. A mobile operating mode was even considered, designed for a portable "Chicken Tracker" that would move from one GPS point to another, remaining off during the day and activating at night to record positions or statuses. This way of working demonstrates a energy optimization mindset highly focused on actual usage and the limitations of available hardware.

Thanks to this approach, the recurring battery discharge problems were solved without having to install oversized solar panels. The system now shuts down during periods of inactivity but continues to perform all its critical automation and safety functions at key times: opening and closing doors, nighttime checks, and significant status changes.

Java web interface, remote monitoring and notifications

Beyond the purely physical aspects, SmartCoop integrates a highly sophisticated software layer. Leveraging the author's experience with Java, an application was developed that runs on the Raspberry Pi and includes a lightweight Javalin-based web server to provide a control and monitoring interfaceThis interface allows you to open or close doors, force water filling, check sensor statuses, and review graphs generated with Google Charts.

This improvement arose after an incident in which the system detected a door failure (a timeout while attempting to close) and sent an email warning that the main door might not have closed completely. Until then, diagnosing such problems required being physically present at the local touchscreen and navigating through the system's screens. To reduce this dependency, a web interface accessible from anywhere with an internet connection was created, delegating the task of serving the interface to Java and Javalin. Simple pages with control buttons and real-time status updates.

Each day, the emails sent by the system include the public IP address of the router that provides internet access. This allows the owner to connect to the web panel from outside the home and act as if they were standing in front of the henhouse. In the future, the author plans to expand this interface to offer more detailed diagnostic functions and access to advanced settings, but even in its current state, the ability to open or close doors, check levels and validate alarms from anywhere This is key to going on vacation with peace of mind.

The Java application relies on the H2 database to persist long-term information and on the MQTT broker for distributing readings and events. This paves the way for integrating SmartCoop into other home automation platforms or generic dashboards, which can subscribe to MQTT topics and display the status of the chicken coop alongside other domestic or agricultural devices.

One particularly useful addition is the "final night check." This module scans the status of all doors, tanks, and sensors at a predetermined time and sends a summary via email to a configurable list of recipients. This way, if a teenager forgot to lock a manual door or if an actuator malfunctioned, it can be detected just before... disconnect parts of the system for nighttime low power mode and correct it while it's still in time.

Integration with weather forecasting and daily life with the chickens

SmartCoop also integrates with external data sources, particularly the Australian Bureau of Meteorology's weather forecast. Periodically, the application downloads a forecast XML file and analyzes whether the probability of rain for the area exceeds a certain threshold established in the database. If this occurs, the system decides Keep the secondary door that provides access to the patio closed.to prevent the chickens from spreading around the house area and, incidentally, filling the porch with droppings when it rains or is cold.

This system was developed after observing that, on inclement days, the chickens preferred to wander around the wooden deck, close to the house, rather than roam the meadow. This resulted in the constant need to use a pressure washer to keep the area clean. With the automatic decision-making system based on the rain forecast, the birds spend much more time inside the coop or in less problematic areas, reducing the need for a pressure washer. the cleaning chores that nobody wants to do every week.

In addition, the system collects all this meteorological and behavioral data in the H2 database, which allows for subsequent analysis of how the hens respond to different weather patterns or whether curious correlations are observed between rainfall, changes in schedule, feed consumption and laying frequency.

The combination of internal sensors, external data (such as weather or sunrise/sunset times), and decision-making capabilities in Java logic makes SmartCoop much more than a simple door automation system. In practice, it behaves like a small "domestic poultry farm manager," capable of to dynamically adjust to environmental conditions and the actual needs of the herd.

Living with such a system also requires a certain amount of digital discipline: checking emails regularly, ensuring the public IP address doesn't change without your knowledge, monitoring the health of the Raspberry Pi and the solar panel, and so on. But in return, you gain the ability to be away for up to a week without anyone having to come and open or close the door, refill the water, or check if the foxes are still prowling around.

Taken together, SmartCoop demonstrates how the combination of embedded electronics, Java and C++ programming, various sensors, MQTT communication, and custom hardware design enables Transforming an amateur chicken coop into a highly automated facility that is predator-proof, energy-efficient, and much easier to manageAll of this while maintaining the spirit of an open project without commercial pretensions that saw it born.