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 is water and food, watching out for predators… When, in addition, you want to be able to go away for several days without depending on a neighbor or a caretaker, it starts to make a lot of sense to consider a complete automation solution for 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 using Raspberry Pi, ESP32-S3, and Java and C++ software.

What is SmartCoop and what is its philosophy?

SmartCoop is essentially a comprehensive controller for chicken coops, built around a Raspberry Pi and an ESP32-S3 module mounted on a custom-designed SMD PCB. It's not a commercial product, nor is it intended 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 modern PCB design with SMD components, USB-C power, and multiple sensor and actuator interfaces.

SmartCoop's approach is far removed from the typical automatic door openers you can buy online. Here, the goal is almost complete automation of the chicken coop: doors, water, feed, data logging, remote monitoring, and even RFID tagging of the hens . The system is designed for a semi-rural environment with a moderate number of birds and real challenges from 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 provide some of their pre-populated PCBs, charging only the manufacturing cost and offering assistance with technical questions as needed.

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 care of 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 basic 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 ESP32-S3 module from Unexpected Maker, which offered greater power, lower consumption, a strong development community, and abundant open-source C++ libraries.

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 the 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, resulting in a more professional assembly with lower power consumption and convenient USB-C power.

One curious detail learned the hard way concerns the external cabling: 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 protection, and very practical installation solutions.

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 system offers a comprehensive set 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 a combination of a light sensor and 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 inside 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 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 don't invade the porch looking for 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, or powering the Raspberry Pi if desired, should you wish 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. Simultaneously, the electronics incorporate a programmed on/off logic for the Raspberry Pi to reduce nighttime power consumption and prevent the need for oversized batteries and solar panels.

The system is completed with an open-source relational database (H2), which records sensor data, configuration values, historical events, time information, and other parameters. In addition, 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 internet access fails 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 henhouse, capable of operating 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 hens wear an inexpensive RFID tag (easily obtained on platforms like AliExpress), the system can count how many have already entered the coop. 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 the weather or any other unforeseen circumstance—something invaluable in contexts where predators quickly become "experts" in the coop's routines.

With 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 working and that they are currently integrating this data with the Java application running on the Raspberry Pi and with the H2 database.

Another interesting use for 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 breeders working with heritage breeds or specific breeding programs.

The experience with the 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 by the gate a few minutes before it opened. To break this routine, an improvement was developed that incorporates a random component into the opening time.

Now, the software downloads a table from its own website showing sunrise and sunset times for the specific farm location, 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 anticipate the exact opening time and exploit this 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 frequent emptying, cleaning, and refilling. 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 as needed. 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 aren't needed at night and the Raspberry Pi screen isn't used, the system is programmed to partially shut down to save energy. Balancing the available power from the solar panels, battery capacity, and the electronics' requirements was a serious problem during Canberra's cloudy winters, and the chosen strategy was to manage the system's on/off cycles 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 considered 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 into 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 aims for these dispensers to hold at least a couple of weeks' worth of food, so the owner and their partner can be away for a few days without having to ask anyone for help.

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

Energy consumption, nighttime shutdown, and mobile variants

One of the initial challenges was ensuring the system could be powered by 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 committing to buying a much larger panel and battery, the author decided to implement intelligent power 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 SMD boards 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 approach demonstrates a strong focus on energy optimization, centered on real-world use and the limitations of the 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 components, SmartCoop integrates a sophisticated software layer. Leveraging the author's experience with Java, an application was developed that runs on the Raspberry Pi and includes a lightweight web server based on Javalin to provide a control and monitoring interface . This interface allows users 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 to Java and Javalin the task of serving simple pages with control buttons and real-time status updates.

Each day, the system sends emails that include the public IP address of the router providing internet access. This allows the owner to connect to the web panel from outside the home and act as if they were standing right in front of the chicken coop. In the future, the developer 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 water levels, and validate alarms from anywhere 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.

A 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 close a manual door or if an actuator malfunctioned, it can be detected just before parts of the system are deactivated for nighttime low-power mode , allowing for timely correction.

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 to keep the secondary door leading to the yard closed to prevent the chickens from dispersing throughout the house and, incidentally, covering 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 use of 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 weekly cleaning chores that no one wants to do.

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 dynamically adjusting to environmental conditions and the actual needs of the flock.

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.

Overall, SmartCoop demonstrates how the combination of embedded electronics, Java and C++ programming, various sensors, MQTT communication, and custom hardware design allows you to transform an amateur chicken coop into a highly automated, predator-proof, energy-efficient, and much easier-to-manage facility , all while maintaining the open and non-commercial spirit that gave birth to it.


Add as preferred source in Google