Skip to Content

Case study · Food packaging · ESP32 PLC

Every pack, every batch, every case. Traced by ESP32 PLC.

A food packaging company needed automatic traceability on three lines that ran at full capacity. Weight sensors, a barcode scanner and ESP32 PLCs now record units, weight, batch and case for every product, and send the data to a central PostgreSQL database.

3packaging lines digitised
6data types recorded automatically
2packaging levels traced: pack and case
PostgreSQLcentral database for every record

Each pack gets a batch number. Each full case gets its own number.

The PLC links them while the line runs.

The customer is a food packaging company. We do not publish its name. The engineering firm that works with it regularly proposed a monitoring solution with ESP32 PLC, and Industrial Shields won the project against its main competitors. This page is about traceability: which product went into which batch and which case, on primary and secondary packaging. If your question is line efficiency, downtime or alarms, open the Machine Monitor simulator.

The challenge

Trace every pack to its batch and its case.

The three lines already ran at full capacity. What they could not do was collect their data in an automated way. Part of it was written by hand, and someone typed it into the ERP later. The end customer had one essential requirement: automated traceability of every product.

01

Data by hand

Full capacity, but part of the data was collected by hand. That costs competitiveness and opens the door to human error.

02

Two packaging levels

Each primary pack has a barcode and a batch number. Each case groups a required number of packs and needs its own number.

03

Many formats

Multiple products in various packaging formats. The data must be up to date, without waiting for someone to enter it.

04

Late data for the ERP

Before, the data was not available in real time. Manual entry into the ERP could add errors.

Automated traceability was not optional

It was the one essential requirement of the end customer: identify every product and every grouping, and save the production process, with no manual step.

How it works

Three loops: count, group, move.

Each loop shows one part of the pattern. Press the buttons and move the sliders. The panels are illustrative simulations: pack weights, case sizes, IDs, speeds and PWM values are examples, not data from the installation.

Loop 1 · Count and weigh

Weight sensors count the units and the packed weight.

Weight sensors on the line tell the PLC two things: how many units passed and how much product was packed. Each product also carries the batch number that the marking system sends to the PLC. The database uses these records to calculate the quantity packed in each batch. Nobody counts by hand.

  • Weight sensors: total units and total packed weight
  • Marking system: a unique batch number for each packed product, sent to the PLC
  • The database calculates the packs in each batch
MarkingsystemB-01ESP32 PLCPostgreSQLWeight sensor
Units0
Total weight0
Batch0

Rows sent to the database (example)

    Illustrative simulation. Example values, no data from the installation.

    Code example: production pulse counter on an ESP32 PLC

    Loop 2 · Batch to case

    A case gets its number only when it is complete.

    A counting system counts the packs that go into each case and compares the count with the required quantity per case. When the case is complete, it gets a unique case number. The PLC records it, together with the batch, and sends it to the central database. A barcode scanner connected to the PLC reads the barcode of each grouping.

    • Count per case against the required quantity
    • Unique case number, recorded in the PLC and the central database
    • Barcode scan of each grouping in a case
    Barcode scannerESP32 PLCPostgreSQL
    FILLINGFULLCASE NUMBERSCANNED
    12

    Case records (example)

      Illustrative simulation. Example values, no data from the installation.

      Loop 3 · Move the belt

      PWM drives the conveyor. An encoder confirms the speed.

      The conveyor belts are controlled by PWM and encoders. A typical way to do it: the PLC sets a PWM duty for the motor, reads the encoder pulses and corrects the duty until the belt runs at the set point. In the panel, change the format or add load to the belt, and the loop corrects itself.

      • PWM output to the conveyor motor (example duty values)
      • Encoder input to measure the belt speed
      • A set point per packaging format (example)
      ESP32 PLCPWMMotorEncoder
      20 %
      Set point0
      PWM duty0
      Encoder0
      Measured speed0

      Illustrative simulation. Example values, no data from the installation. Example: 1,000 encoder pulses per metre of belt.

      See OEE, alarms and energy in the Machine Monitor simulator

      System architecture

      How does an ESP32 PLC trace a packaging line?

      On each of the three lines, ESP32 PLCs read the weight sensors, the batch number from the marking system, the case count and the barcode scanner. They control the conveyor with PWM and an encoder, and they send every record to a central PostgreSQL database. A 10.1" TouchBerry touch screen shows the production status in real time. The case does not publish the protocol, the wiring or how many PLCs each line uses.

      Packaging line traceability with ESP32 PLCPackaging line× 3 linesWeight sensorsunits and weightMarking systembatch numberCounting systempacks per caseBarcode scannereach groupingMotor + encoderPWM, speedESP32 PLCper line: not publishedTouchBerry 10.1"real-time viewNetworkprotocol not publishedPostgreSQLcentral databaseERP and reportsexample useOne possible layout. The case does not publish the protocol, the wiring or the number of PLCs per line.Packaging line× 3 linesWeight sensorsunits and weightMarking systembatch numberCounting systempacks per caseBarcode scannereach groupingMotor + encoderPWM, speedESP32 PLCper line: not publishedTouchBerry 10.1"real-time viewNetworkprotocol not publishedPostgreSQLcentral databaseERP and reportsexample useOne possible layout. The case does not publishthe protocol, the wiring or the number of PLCsper line.
      Records to the databaseSignals from and to the lineExample elements, not published by the case
      Signals and data
      DataBetweenTypePurpose
      Units and weightWeight sensors → ESP32 PLCSensorCounts the units and the total packed weight
      Batch numberMarking system → ESP32 PLCDataA unique batch number for each packed product
      Case countCounting system → ESP32 PLCCountCompares the packs in a case with the required quantity
      Case barcodeBarcode scanner → ESP32 PLCReaderReads the barcode of each grouping in a case
      Belt speedESP32 PLC ↔ motor and encoderPWM + encoderControls the conveyor belts
      RecordsESP32 PLC → PostgreSQLNetworkUnits, weight, batches, cases and barcodes. Protocol not published
      Live viewTouchBerry 10.1" touch screenDisplayShows the production status in real time

      Why it works

      One pattern for any line that must prove what it packed.

      Data at the source

      The PLC records each batch and case number where it happens, on the line. The database gets the same record a moment later. No retyping.

      Ready for any format

      The company packs multiple products in various formats with the same system. Example: a set point and a case size per format.

      A database that scales

      PostgreSQL was chosen because it manages large amounts of data quickly. Other SQL databases, such as SQLite, also work.

      Open, with no licence fees

      One of the points that won the project. You program the ESP32 PLC in C++ with the Arduino IDE and the Industrial Shields boards package.

      Modular

      The system can grow later on the same platform: more I/O with expansion modules, and LoRa, LTE-M/NB-IoT or CAN expansion boards, on models with an expansion slot.

      Support before, during and after

      Our team was available before, during and after the installation, by phone, email or WhatsApp. Equipment designed and manufactured for industrial use.

      Hardware used

      ESP32 PLC to trace. TouchBerry to see.

      ESP32 PLC 21 FLEX, industrial controller based on ESP32

      ESP32 PLC

      Industrial controllers built on the dual core ESP32, with Ethernet, Wi-Fi and RS-485, for your DIN rail. On this line they read the sensors, the marking system and the scanner, drive the conveyor with PWM and send every record to the database.

      Role
      Counting, batch and case records, conveyor control
      Processor
      ESP32 dual core
      Network
      Ethernet 10/100, Wi-Fi 2.4 GHz, Bluetooth LE
      Serial
      RS-485, RS-232
      Programming
      C++ with the Arduino IDE
      Family
      ESP32 PLC 14, 19R, 21, 38AR, 38R, 42, 57R and 58

      The case does not publish the exact ESP32 PLC model or how many units each line uses. The installation scheme shows two ESP32 PLC units. The image shows the ESP32 PLC 21 FLEX.

      TouchBerry Pi Panel PC 10.1 inch with Raspberry Pi

      TouchBerry 10.1" touch screen

      A 10.1" TouchBerry touch screen appears in the installation scheme, next to the ESP32 PLC. It gives the production staff the live view of the line.

      Role
      Real-time view of the production status
      Display
      10.1", capacitive touch
      Computer
      Raspberry Pi, Linux

      The case does not publish the TouchBerry version. The image shows the TouchBerry Pi Panel PC 10.1" FLEX.

      Questions about this case

      How do you trace a product from its batch to its case with a PLC?

      In this case, the marking system gives each packed product a unique batch number and sends it to the PLC. A counting system counts the packs in each case. When the required quantity is reached, the case gets a unique case number, and the PLC records it with the batch, in its memory and in the central database. A barcode scanner reads each grouping. So every case points to its batch, and every product points to its barcode.

      Why PostgreSQL for packaging traceability?

      The project chose PostgreSQL because it manages large amounts of data quickly. A packaging line writes a record for every unit, batch and case, so the volume grows fast. Other SQL databases, such as SQLite, can also be used.

      Which ESP32 PLC model does the line use?

      The case does not publish the model or the number of units per line. The installation scheme shows two ESP32 PLC units. To choose yours, count your signals: inputs for weight sensors and encoders (check which inputs support interrupts), PWM outputs for the conveyor motors, and a serial or Ethernet port for each scanner.

      How does the barcode scanner connect to the PLC?

      The case says that the scanner is connected to the PLC and to the line, and does not publish the interface. Industrial scanners commonly use RS-232, RS-485 or Ethernet, and the ESP32 PLC family has all three. The scheme also mentions QR codes and RFID, which follow the same pattern: the reader gives the PLC an ID, and the PLC links it to a batch or a case.

      Is this the same as monitoring OEE on a production line?

      No. This case is about traceability: units, weight, batches, cases and barcodes, written to a database. OEE, downtime and alarms are a different question. You can try that pattern on a live packaging line in the Machine Monitor simulator, and read how a real production line was monitored in our production line case.

      Which parts of this case are facts, and which are examples?

      Facts: a food packaging company, three lines, weight sensors, batch numbers from the marking system, a count per case with a unique case number, a barcode scanner, PostgreSQL, a real-time view, conveyor control by PWM and encoders, and a 10.1" TouchBerry screen in the scheme. Examples: pack weights, case sizes, IDs, speeds, PWM values, encoder resolution, protocol, wiring and PLC models.

      Download the case study

      4-page PDF with the challenge, the logic, the architecture and the hardware. No form required.

      Similar line?

      Tell us your line and your codes. An engineer will answer.

      Tell us how many lines you have, which codes you read (barcode, QR or RFID), how you build batches and cases, and where the data must go: a database, an ERP or an MES. We will tell you which controller fits and how to connect it.

      • You get an answer from our technical team
      • I/O count and controller sizing for your line
      • Arduino, ESP32 or Raspberry Pi based PLCs