Skip to Content
All case studies

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.

2climate sensors, temperature and humidity, compared with set values
4jobs on one PLC: climate, air, food and water, pen washing
8relay outputs on the M-Duino 19R+ for one room and one pen
1Panel PC to set all the programs, values and schedules

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.

01

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.

02

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.

03

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.

04

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.

Loop 1 · Climate and air

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
Barn roomAir conDehumidifierExtractorFilter
21
70
Room temperature0
Room humidity0
Loads on0
Air state0
IN SET VALUESCOOLINGDRYINGEXTRACTOR ONALARM

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.

    Loop 2 · Food and water

    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
    SiloGateDrop doorValveMeterDrinker
    3
    8
    Scale0
    Water meter0
    Silo left0
    Food given today0

    READYGATE OPENDROP DOOR OPENWATER VALVE OPENDONE

    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.

      Loop 3 · Washing

      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
      PenCommon areaDoorDrain
      Pen door0
      Pen0
      High-pressure pipes0
      Washing time left0
      DOOR OPENPEN EMPTYWASHINGDRAININGDOOR CLOSED

      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.

        TouchBerry Pi 10.1"programs and schedulesServerstore and analyseWi-Fi (on request)EthernetM-Duino 19R+5 of 6 inputs, 8 relaysInputsTemperature sensoranalog in, 0-10 VHumidity sensoranalog in, 0-10 VScale load celltransmitter, 0-10 VWater meterpulses, interrupt inExtractor faultthermal or airflow contactRelay outputsAir conditionervia contactorDehumidifierrelayExtractors + filtersvia contactorFood gatesolenoid valveDrop doordoor actuatorWater valvewater lineWashing pipeshigh-pressure valvePen doorelectrovalveOne room and one pen. The case does not publish the wiring; signal types are a typical way to do it.Serverstore and analyseWi-Fi (on request)TouchBerry Pi 10.1"programs and schedulesEthernetM-Duino 19R+5 of 6 inputs, 8 relaysInputs · Relay outputsTemperature sensoranalog in, 0-10 VInputHumidity sensoranalog in, 0-10 VInputScale load celltransmitter, 0-10 VInputWater meterpulses, interrupt inInputExtractor faultthermal or airflow contactInputAir conditionervia contactorRelay outDehumidifierrelayRelay outExtractors + filtersvia contactorRelay outFood gatesolenoid valveRelay outDrop doordoor actuatorRelay outWater valvewater lineRelay outWashing pipeshigh-pressure valveRelay outPen doorelectrovalveRelay outOne room and one pen. The case does notpublish the wiring; signal types are atypical way to do it.
        Analog, pulse and digital inputsRelay outputsEthernetWi-Fi
        Signals and data for one room and one pen (example)
        SignalBetweenTypePurpose
        Room temperatureBetweenTemperature sensor → M-Duino 19R+TypeAnalog in, 0-10 VPurposeCompared with the set value: air conditioner on or off
        Room humidityBetweenHumidity sensor → M-Duino 19R+TypeAnalog in, 0-10 VPurposeCompared with the limit: dehumidifier on or off
        Food weightBetweenLoad cell of the scale → transmitter → M-Duino 19R+TypeAnalog in, 0-10 VPurposeRation for each pen. The case does not publish the load cell interface
        Water volumeBetweenWater meter → M-Duino 19R+TypeDigital in with interrupt, pulsesPurposeExact litres for each pen, and the water total
        Extractor fault / airflowBetweenThermal relay contact or airflow switch → M-Duino 19R+TypeDigital in, 24 VdcPurposeAlarm on the panel if the ventilation fails
        Air conditionerBetweenM-Duino 19R+ → contactor → air conditionerTypeRelay outPurposeCooling above the set value
        DehumidifierBetweenM-Duino 19R+ → dehumidifierTypeRelay outPurposeDrying above the humidity limit
        Extractors with filtersBetweenM-Duino 19R+ → contactor → extractorsTypeRelay outPurposeCO2 and ammonia out of the room, through filters
        Food gateBetweenM-Duino 19R+ → solenoid valveTypeRelay outPurposeFills the scale up to the ration
        Drop doorBetweenM-Duino 19R+ → door actuatorTypeRelay outPurposeDrops the weighed food to the pen
        Water valveBetweenM-Duino 19R+ → valve on the water lineTypeRelay outPurposeCloses when the meter reaches the set litres
        Washing pipesBetweenM-Duino 19R+ → high-pressure valveTypeRelay outPurposeWashes the pen through the drain, only with the door open
        Pen doorBetweenM-Duino 19R+ → electrovalveTypeRelay outPurposeOpens the pen so the animal goes to the common area
        Programs and dataBetweenM-Duino 19R+ ↔ TouchBerry Pi 10.1"TypeEthernetPurposeSet values, rations, schedules, inventory
        Storage and analysisBetweenTouchBerry Pi 10.1" → serverTypeWi-FiPurposeStore 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 19R+, industrial Arduino PLC with 8 relay outputs, analog inputs and Ethernet for DIN rail

        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 inch CORE, industrial touch panel with Raspberry Pi 4

        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