Case study · Pig farm · M-Duino 19R+
Climate, air, food and washing. One PLC per barn room.
Set values, exact rations and clean pens, from one controller.
Meat demand grows. Quality and safety rules get stricter, and feed, labour and energy cost more.
So the barn runs on set values, and every kilo of food is counted.
This case describes a generic design by Industrial Shields for a pig farm. It does not name a farm or a customer, and it does not publish results. The case says it is a base you can expand with more parameters. The set values, rations, times and quantities in the panels are examples. This page covers the whole barn: climate, air, food and water, washing. For a feeding line with a load cell in each feeder, see the animal feeding case.
The challenge
Animal welfare depends on the air, the food and a clean pen.
The goal is environmental control for animal welfare, and data that moves along the process chain. The system controls the climate of the room, weighs the food and the water for each pen, keeps the air free of harmful gases and washes each pen on a schedule. A Panel PC collects the information, stores it on a server and analyses it.
A climate on set values
A temperature sensor and a humidity sensor read the room. From the set values, the PLC switches on the air conditioner and the dehumidifier.
CO2 and ammonia out
Both gases are harmful for the animals and for the people. Extractors with filters keep the air clean inside and do not send the gases outside.
Exact food and water
The food is weighed before it drops into the pen, and a water meter lets the exact amount pass. The program adds up every pen: the inventory is always ready.
Washing without stress
Two high-pressure pipes in the drain wash the pen on a schedule. First the door opens, so the animal goes to the common area and does not suffer.
One panel for every program
A Panel PC shows the menu of programs. From there, people set all the parameters and the schedules. The case connects the panel to Wi-Fi, to store the data on a server and analyse it.
How it works
Three loops: climate and air, food and water, washing.
Each panel shows one loop of the barn. Press the buttons and move the controls. The panels are illustrative simulations: the set values, rations, times and quantities are examples, not data from a farm.
Set values for the room, and air without harmful gases.
A temperature sensor and a humidity sensor read the room. Depending on the pre-selected values, the PLC switches on the air conditioner and the dehumidifier. Extractors with filters take CO2 and ammonia out of the room and keep them from going outside. Pick a scenario and move the set values. To run a full day of climate control in a closed room, with fresh air for CO2 and drying, open the greenhouse climate simulator and its mushroom room (it runs on ESP32 PLCs; the logic is the same).
- Temperature and humidity against set values
- Air conditioner and dehumidifier on relays
- Extractors with filters for CO2 and ammonia
Climate events (example)
Illustrative simulation. Example values, not data from a farm. Example set values and room response, faster than real time. The case switches the air conditioner and the dehumidifier from set values. A typical way to do it: a small band around each set value, so a load does not switch on and off every second; the extractor runs a minimum cycle and longer when the room is hot or wet; and a fault in the extractor raises an alarm on the panel.
Weigh each ration. Count each litre.
A solenoid valve opens a gate and the food falls into a scale. When the scale reaches the ration, the valve closes. A second door drops the food for the animal. For water, a water meter lets the exact amount pass. The program adds the quantities of each pen and keeps the rest of the total: the inventory is done. Pick a pen, set a ration and press Dose.
- A scale and a solenoid gate for each ration
- A water meter for the exact litres
- Totals per pen and food left in the silo
Inventory log (example)
Illustrative simulation. Example values, not data from a farm. Example rations and silo size. As in the case: the solenoid gate fills the scale up to the ration, closes, and a second door drops the food to the pen. The water meter lets the set litres pass. Each dose is added to the total of its pen and taken from the silo, so the inventory is always up to date. With more pens, each pen adds its own drop door and water valve.
Wash the pen only when the door is open.
On a schedule, two high-pressure pipes in the drain wash the pen. They work only while the pen door is open, through an electrovalve, so the animal goes out to the common area and does not suffer. Start the washing, then try it with an animal that stays inside.
- Scheduled washing from the panel
- Pen door on an electrovalve
- No water while the animal is inside
Washing sequence (example)
Illustrative simulation. Example values, not data from a farm. Example times. As in the case: the pipes wash the pen only while the door is open, so the animal can go to the common area. A typical way to do it: a wait time or a presence sensor confirms that the pen is empty before the water starts, and the washing stops if the door closes. See safety interlocks on a PLC (the example runs on a Raspberry PLC; the pattern is the same).
System architecture
How do you automate a pig farm with a PLC?
An M-Duino 19R+ reads two climate sensors, the load cell of the scale, the water meter and a fault contact of the extractors. Its eight relays switch the air conditioner, the dehumidifier, the extractors, the food gate and door, the water valve, the washing pipes and the pen door. A typical way to do it: the PLC talks to the Panel PC over Ethernet, and the Panel PC reaches the server over the farm Wi-Fi, as in the case. This count is for one room with one pen; more pens need more outputs.
| Signal | Between | Type | Purpose |
|---|---|---|---|
| Room temperature | BetweenTemperature sensor → M-Duino 19R+ | TypeAnalog in, 0-10 V | PurposeCompared with the set value: air conditioner on or off |
| Room humidity | BetweenHumidity sensor → M-Duino 19R+ | TypeAnalog in, 0-10 V | PurposeCompared with the limit: dehumidifier on or off |
| Food weight | BetweenLoad cell of the scale → transmitter → M-Duino 19R+ | TypeAnalog in, 0-10 V | PurposeRation for each pen. The case does not publish the load cell interface |
| Water volume | BetweenWater meter → M-Duino 19R+ | TypeDigital in with interrupt, pulses | PurposeExact litres for each pen, and the water total |
| Extractor fault / airflow | BetweenThermal relay contact or airflow switch → M-Duino 19R+ | TypeDigital in, 24 Vdc | PurposeAlarm on the panel if the ventilation fails |
| Air conditioner | BetweenM-Duino 19R+ → contactor → air conditioner | TypeRelay out | PurposeCooling above the set value |
| Dehumidifier | BetweenM-Duino 19R+ → dehumidifier | TypeRelay out | PurposeDrying above the humidity limit |
| Extractors with filters | BetweenM-Duino 19R+ → contactor → extractors | TypeRelay out | PurposeCO2 and ammonia out of the room, through filters |
| Food gate | BetweenM-Duino 19R+ → solenoid valve | TypeRelay out | PurposeFills the scale up to the ration |
| Drop door | BetweenM-Duino 19R+ → door actuator | TypeRelay out | PurposeDrops the weighed food to the pen |
| Water valve | BetweenM-Duino 19R+ → valve on the water line | TypeRelay out | PurposeCloses when the meter reaches the set litres |
| Washing pipes | BetweenM-Duino 19R+ → high-pressure valve | TypeRelay out | PurposeWashes the pen through the drain, only with the door open |
| Pen door | BetweenM-Duino 19R+ → electrovalve | TypeRelay out | PurposeOpens the pen so the animal goes to the common area |
| Programs and data | BetweenM-Duino 19R+ ↔ TouchBerry Pi 10.1" | TypeEthernet | PurposeSet values, rations, schedules, inventory |
| Storage and analysis | BetweenTouchBerry Pi 10.1" → server | TypeWi-Fi | PurposeStore the data and analyse it |
Why this design
Set values, counted kilos, and an empty pen before the water.
Set values, not guesswork
The air conditioner and the dehumidifier follow the values that people set on the panel. The PLC keeps them all day and all night, and it logs what it did.
Every kilo counted
The scale weighs each ration before it drops, and the water meter counts each litre. The program adds them per pen and keeps the rest of the silo: the inventory comes for free. See CSV logging with a live table on a TouchBerry Pi.
Water only in an empty pen
The washing pipes work only with the pen door open, so the animal is in the common area. The rule lives in the PLC program, not in the memory of a person.
Relays for the barn loads
The M-Duino 19R+ has 8 relays, up to 4 A at 230 Vac or 2 A at 24 Vdc with a resistive load. For the air conditioner and the extractor motors, a relay drives a contactor coil, with an RC snubber.
One panel for every program
People set the parameters and the schedules on the TouchBerry Pi panel. The panel stores the data and sends it to the server for analysis.
Code that you own
The PLC is programmed with the Arduino IDE and open source libraries. You get the code, so you can add a sensor, a pen or a room later, as the case expects.
Hardware
One PLC per room. One panel for the programs.
M-DUINO ETHERNET PLC ARDUINO 19R
An industrial PLC built around an original Arduino Mega 2560, with 6 inputs and 11 outputs, 8 of them relays, Ethernet and RS-485, for DIN rail. In the barn it reads the climate sensors, the scale and the water meter, and switches all the loads of one room.
- Role
- Climate, air, food and water dosing, washing, data to the panel
- Inputs
- 6: 4 analog/digital (0-10 V, 10-bit), 2 digital optoisolated with interrupt (5 to 24 Vdc)
- Outputs
- 11: 8 relays, 3 analog/digital/PWM (0-10 V)
- Relays
- Up to 4 A at 230 Vac or 2 A at 24 Vdc, resistive load
- Comms
- Ethernet (W5500), RS-485, RS-232, TTL serial, I2C, SPI
- Built in
- Real-time clock, microSD slot
- Power and mounting
- 12 to 24 Vdc, DIN rail TS35, IP20, inside a cabinet
The original case names the M-Duino 19R and shows its picture. It is this product, reference IS.MDuino.19R+. For one room it uses 5 of the 6 inputs and the 8 relays. For more pens or rooms, add a second M-Duino on the same Ethernet network or choose a model of the family with more outputs (see the family datasheet).
TouchBerry Pi Panel PC 10.1" CORE
The control point of the farm: a Raspberry Pi 4 behind a 10.1" capacitive touchscreen, on Ethernet to the PLC. It shows the menu of programs, where people set the parameters and the schedules, and it stores the data.
- Role
- Programs, set values, schedules, inventory, data to the server
- Screen
- 10.1" IPS, 1280 x 800, capacitive, 900 nits
- Software
- Linux preinstalled; HMI in Node-RED, Python or a browser
- Comms
- Gigabit Ethernet, 4 x USB, one serial port (RS-485, RS-232 or TTL); Wi-Fi and Bluetooth on request
- Power
- 12 to 24 Vdc, UPS for safe shutdown
- Environment
- 0 to 45 °C, 10 to 90 % RH without condensation, IP20 front
The original case links to the TouchBerry Pi 10.1". Today it is the TouchBerry Pi Panel PC 10.1" CORE. The case text also names a TinkerTouch panel, which is no longer sold. The case connects the panel to Wi-Fi. Wi-Fi and Bluetooth are not included by default: talk to us before you order (see the family datasheet). For a panel inside the barn, with dust and splashes, the FLEX version offers an IP65 front.
Questions about this case
How do you control the climate of a pig barn with a PLC?
A temperature sensor and a humidity sensor go to analog inputs of the PLC. The PLC compares them with the set values from the panel and switches the air conditioner and the dehumidifier through relays. Extractors with filters take CO2 and ammonia out. A typical way to do it: a small band around each set value, so the loads do not switch on and off all the time.
Does a mechanically ventilated pig barn need an alarm?
In the EU, yes. Council Directive 98/58/EC (Annex, point 13) asks for a backup system that keeps enough fresh air if the ventilation fails, and an alarm that warns of the breakdown. The alarm must be tested regularly, and automated equipment must be inspected at least once a day. A fault contact of the extractor on a digital input lets the PLC detect the failure, raise the alarm on the panel and send it on, for example by email alerts from a monitoring server. Check the national rules for your farm too.
How does the system weigh the food for each pen?
With a scale between the silo and the pen. A solenoid valve opens a gate, the food falls into the scale, and the gate closes at the ration. A second door then drops the food for the animal. The load cell of the scale reaches a 0-10 V analog input through a transmitter. For a load cell in each feeder, see the animal feeding case.
How does the PLC measure the water for each pen?
With a water meter that gives pulses. The pulses go to a digital input with interrupt, the PLC counts them as litres, and it closes the water valve at the set amount. Each total goes to the inventory of the pen. See pulse flow meter reading on a PLC (the example runs on an ESP32 PLC; the pattern is the same).
How can the pens be washed without stressing the animals?
As the case does: the pen door opens first, through an electrovalve, and the animal goes out to the common area. The two high-pressure pipes in the drain only work while the door is open. A typical way to do it: a wait time or a presence sensor confirms the pen is empty, and the washing stops if the door closes.
Does the system measure CO2 and ammonia?
In the EU, Council Directive 98/58/EC (Annex, point 10) asks to keep air circulation, dust, temperature, humidity and gas concentrations within limits that are not harmful to the animals. The case does not measure the gases: it uses extractors with filters. A typical way to do it is to add a CO2 or ammonia sensor on a free analog input, so the extractor runs on the real value. The analog inputs read 0-10 V; for a 4-20 mA sensor, a 500 Ω precision resistor turns 20 mA into 10 V. Ammonia and washing water attack electronics, so keep the PLC in a closed cabinet or in a technical room.
Download the case study
4-page PDF with the challenge, the logic, the architecture and the hardware. No form required.
Automating a livestock barn?
Tell us about your barn. An engineer will answer.
Tell us how many rooms and pens you have, the climate loads, how you feed and give water, and how you wash. We will propose the inputs and outputs, the controller and the panel.
- You get an answer from our technical team
- Climate, dosing and washing for your barn
- Arduino, ESP32 or Raspberry Pi based PLCs