Skip to content
EDWartens UK
Physical AIUpdated 21 October 20269 min read

Machine Vision and PLC Integration: A Practical Guide

A machine vision system pairs lighting, a camera, a processor and software, and reports a result to the PLC, most often a pass or fail. Smart cameras connect over PROFINET or EtherNet/IP; at 300 bottles per minute the line gives the system only 200 ms per item. This guide covers architecture, handshakes, timing and reject tracking.

Machine VisionPLC IntegrationQuality InspectionPROFINETSmart CamerasIndustrial AI
Machine Vision and PLC Integration: A Practical Guide

Key takeaways

  • A machine vision system is lighting, a camera, a processor, software and outputs; the PLC triggers it and acts on the result.
  • Cognex documents that S7-1200 and S7-1500 PLCs connect to In-Sight cameras over PROFINET in TIA Portal only, using a GSD file.
  • At 300 bottles per minute each bottle has 200 ms of line time, and a camera 0.5 m before the ejector at 0.5 m/s is 1.0 s upstream.
  • Track rejects by encoder position rather than a fixed delay, because conveyor speed changes.
  • OPC UA for machine vision (VDMA 40100) was first released in June 2018 as a vendor-neutral model.

Machine vision uses cameras and image processing to inspect, measure, read and guide automatically, and the PLC stays in charge of the machine. The usual arrangement is simple: the PLC triggers an inspection, the vision system returns a result (typically pass or fail, plus data), and the PLC acts on it. Wikipedia notes that the primary uses of machine vision are automatic inspection and industrial robot or process guidance, and that a common output is a pass/fail decision that can trigger a reject mechanism or an alarm.

What are the parts of a machine vision system?

A vision system comprises lighting, a camera or imager, a processor, software and output devices. Inspection systems "usually include lighting, a camera or other imager, a processor, software, and output devices", according to Wikipedia, and lighting is designed to give the contrast that later processing needs. The diagram below shows the typical layout on a conveyor: illumination and camera over the object, processing, and a mechanism that acts on the result.

Diagram of a machine vision system with illumination, camera and lens, image processing and a conveyor reject mechanism
Diagram of a machine vision system with illumination, camera and lens, image processing and a conveyor reject mechanismPhoto: European Editors, CC BY-SA 4.0, via Wikimedia Commons

Processing can run on a CPU, GPU, FPGA or a combination. When the imager and processor share one housing the product is called a smart camera or smart sensor. Separate cameras connect over a standardised digital interface such as Camera Link or CoaXPress, or over Ethernet.

Which vision architecture should you choose?

Use a smart camera for self-contained tasks, a PC-based system for several cameras or heavy processing, and deep learning where defects are hard to describe with rules. Each trades flexibility against simplicity.

ArchitectureBest forStrengthsTrade-offs
Smart camera or vision sensorSingle-station checks: presence, code reading, measurementCompact, built-in PLC communication, quick set-upLimited processing power and flexibility
PC-based visionMulti-camera, high-throughput or complex measurementFlexible software, high-speed interfaces such as GigE Vision or CoaXPressMore engineering, and an industrial PC to maintain
Deep-learning inspectionVariable surfaces and defects that are difficult to define as rulesLearns from labelled images during training and infers at run timeNeeds representative training images and ongoing validation

Wikipedia notes conventional machine vision relies on simple differentiation, such as dark defects on a light product, whereas deep learning learns from a large number of images in a training phase and then performs inference at run time. GigE Vision is an interface standard introduced in 2006 for high-performance industrial cameras over Ethernet, maintained by the Association for Advancing Automation (A3), with a description file based on the EMVA GenICam standard. Our computer vision in factories guide covers the AI side.

Why is lighting the first design decision?

Lighting determines whether the camera can see the feature at all, and it is far cheaper to fix before buying a camera. Choose the technique (backlight for silhouettes, coaxial for flat shiny surfaces, ring or dome for general and curved parts, dark-field to highlight surface scratches) and test it on real samples, including the worst ones, before committing. This Cognex video explains how lighting works in factory automation.

Lighting for Machine Vision in Factory Automation - How does it work?

How do you choose resolution and field of view?

Start from the smallest feature you must detect and the area you must cover. Pixel size on the part is the field of view divided by the number of pixels across it. For example, a 100 mm field of view on a sensor 2,000 pixels wide gives 0.05 mm per pixel. A defect must cover several pixels to be detected reliably, and manufacturers' guidance on how many varies with contrast and algorithm, so test with real samples. If the part moves, motion blur also limits what you can see, which is why short exposures and strong lighting go together.

How does a vision system talk to the PLC?

Mainly via an industrial Ethernet protocol, digital I/O or a simple polled protocol such as Modbus TCP, and increasingly through OPC UA. The choice depends on how much data you need back.

  1. PROFINET or EtherNet/IP: the camera appears as an IO device and its inputs and outputs map into PLC process memory, exchanged cyclically. Cognex's documentation for In-Sight describes PROFINET IO this way, and states that Siemens S7-1200 and S7-1500 controllers are supported only in TIA Portal, using the camera's GSD file.
  2. Discrete I/O: a trigger output from the PLC and pass and fail outputs from the camera. Simple and fast, but it carries no measurement data.
  3. Modbus TCP: the camera exposes a register map the PLC polls. Easy to implement, but not deterministic.
  4. OPC UA: the VDMA's OPC UA Companion Specification for machine vision (VDMA 40100) defines a generic model for systems from simple vision sensors to complex inspection systems, and handles recipes, configurations and results in a standardised way. It was first released in June 2018; check its current status before relying on it.

For the network side see the PROFINET guide and the OPC UA guide.

What does the PLC handshake look like?

Use a trigger, busy, done, result sequence with a timeout. A typical flow for one inspection:

  1. A part-present sensor sees the item. The PLC captures the conveyor position or encoder count.
  2. The PLC sets the camera trigger (or sends a trigger command over the network), optionally with a job or recipe number.
  3. The camera sets a busy flag, acquires the image and runs the inspection.
  4. The camera sets a done flag with a result bit, and optionally a measurement or ID.
  5. The PLC reads the result while done is set, then clears the trigger and waits for done to fall.
  6. If done never arrives within a timeout, the PLC raises a fault, because a silent vision failure must never let uninspected product through.

Keep the handshake in one function block with a clear interface (Trigger, Done, Pass, Value, Fault), so the same code works for every station.

Worked example: timing a reject on a filling line

Take a line running 300 bottles per minute. That is 5 bottles per second, so each bottle gets 200 ms of line time, and image capture, processing and communication must fit inside that window with margin. If the bottle pitch is 100 mm, the conveyor moves at 5 x 0.1 = 0.5 m/s. An ejector 0.5 m downstream of the camera is therefore reached 1.0 second later, five bottles after the inspected one.

A fixed delay of 1.0 s works only while the speed never changes. Real conveyors slow, stop and restart, so track by position: store each result in a shift register or queue indexed by the encoder count, and fire the ejector when the failed bottle reaches the reject position. Log rejects with a counter, and raise an alarm if several fail consecutively, which often points to an upstream filler or capper fault rather than a vision fault. These numbers are an illustrative calculation; measure your own pitch, speed and mechanical response times.

What commonly goes wrong?

  • Lighting treated as an afterthought. Solve it first, on real samples.
  • Vibration and mounting. A camera on a shaking bracket gives drifting measurements, so mount it rigidly.
  • No calibration plan. Cameras and lighting drift; build checks with a reference target into maintenance.
  • Over-fitted AI models. A model trained only on perfect samples misses real defects, so train and validate on representative production images.
  • Weak PLC integration. Without a timeout, tracking and a defined fail-safe state, a good camera still lets bad parts through.
  • Chasing the most expensive camera. Specify to the smallest feature you must detect and the cycle time, not to the vendor catalogue.

How EDWartens can help

The Professional Module is a five-day live online Siemens TIA Portal class covering S7 PLC programming, HMI and WinCC SCADA. It does not teach machine vision, and the course is online and Siemens-focused, but it builds the PLC skills used in the trigger, result and reject logic above, and the self-paced Basic Engineering includes industrial communication protocols and control systems. Practise handshake and counter logic in the free PLC simulator and the ladder logic simulator. See the Professional Module and sign up.

Start free

Learn machine vision free, then practise the job

Free job simulation

Computer Vision Engineer

Specify, label and evaluate an inspection model on a production line.

The first five days are free, no card needed.

Live UK jobs

Computer vision jobs in the UK

Updated daily, with licensed visa sponsors marked.

Browse all engineering jobs

Frequently asked questions

How does a PLC communicate with a machine vision camera?

Most smart cameras support PROFINET or EtherNet/IP, mapping the camera's inputs and outputs into PLC memory for a trigger, busy, done and result handshake. Simpler systems use digital I/O for pass or fail, Modbus TCP for polled data, or OPC UA where a standard information model is needed.

Can a Siemens S7-1500 work with a Cognex In-Sight camera?

Yes. Cognex's documentation says S7-1200 and S7-1500 controllers are supported over PROFINET in TIA Portal only, not Step 7 classic. You install the camera's GSD file, add the camera as a PROFINET device, and use its input and output data for trigger, job selection and result. Check the documentation for your firmware version.

Do I need deep learning for machine vision inspection?

Not always. Conventional rule-based tools handle presence, dimensions, codes and clear contrast defects well. Deep learning helps where defects vary or are hard to describe as rules, because it learns from training images and infers at run time. It needs representative images and continued validation to avoid missing real-world defects.

Why does lighting matter so much in machine vision?

Lighting creates the contrast the software needs to separate a defect or feature from its background. Without it, no camera or algorithm can recover the information. Choose the technique on real samples, including worst cases, before specifying the camera, because poor lighting is a common cause of unreliable inspection.

How do I reject the right item after a vision inspection?

Do not rely on a fixed timer, because conveyor speed changes. Record each inspection result against the conveyor's encoder position, for example in a shift register, and fire the ejector when that item reaches the reject point. Add a timeout and a defined fail-safe state if the camera does not return a result.

Sources

  1. Machine vision, Wikipedia
  2. GigE Vision, Wikipedia
  3. PROFINET Communications with an In-Sight Vision System, Cognex documentation
  4. VDMA releases OPC UA Companion Specifications for Robotics and Machine Vision, OPC Foundation

Share this article

About the author

EDWartens Team

EDWartens Instructional Team

The EDWartens instructional team brings together UK-based automation engineers, certified Siemens and Rockwell specialists, and industry practitioners with decades of combined experience in PLC programming, SCADA engineering, and industrial AI.

View all articles by EDWartens

Ready to become job-ready?

Start with a free course today, or train live in Siemens PLC, HMI and SCADA on the Professional Module.