Wiring a Baumer Laser Sensor to the Siemens S7-300 SM334

David Krause13 min read
S7-300SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Problem Overview

Connecting a Baumer laser distance sensor with a 4-20 mA current output to a Siemens S7-300 SM334 analog input module (part number 6ES7 334-0CE01-0AA0) requires careful attention to the wiring topology because the sensor uses an external 24 VDC supply that shares its 0 V return with the analog signal. The most common field failures on this combination are misread raw values, saturated counts, and an apparent dead input. This guide resolves those symptoms by selecting the correct input mode (current versus voltage), wiring the sensor as a 4-wire current source, configuring the channel in STEP 7 (or TIA Portal), scaling the process value to engineering units (millimeters), and exposing the result to a WinCC HMI on a Siemens OP 370 12" panel.

Symptomatically, the operator-typical failure looks like this: the AI raw word (PIW 272 in the reported installation) reads 32767 with the sensor connected, or it reads 0 regardless of target distance. Both readings are configuration-or-wiring artifacts, not a defective module. Each is fixed by a single change to either HW Config or the front-connector wiring, and either is detectable from STEP 7's online monitor without touching the sensor.

Prerequisites

  • S7-300 CPU 31x (any standard variant from the catalog) with free signal slot for the SM334.
  • STEP 7 V5.5 SP1 or higher, or TIA Portal V13 / V14 / V15 with S7-300 support package installed.
  • SM334-0CE01-0AA0 (4 AI / 2 AO, 8-bit) or SM334-0KE00-0AB0 (4 AI / 2 AO, 12-bit) installed in a signal slot.
  • Baumer laser distance sensor with 4-20 mA analog output (OADM, OHDM, or similar series). Verify by checking the sensor nameplate or the sensor data sheet.
  • 24 VDC supply sized for sensor load plus loop drop (typical sensor draw 80-150 mA). A separate, regulated 24 VDC for the sensor is strongly recommended.
  • 4-wire M12 cable with shield, or shielded 4-conductor tray cable for cable gland entry.
  • WinCC Flexible 2008 SP3 or TIA WinCC Comfort/Advanced for the OP 370 panel.

SM334 Hardware Reference

The 6ES7 334-0CE01-0AA0 is one of three AI4/AO2 SM334 variants. Verify the ordering label on the front panel before configuring the channel; mixing up the variants is a common reason for an apparent "dead" input. Refer to the SM334 Analog Module Manual for the official specification.

Parameter 6ES7 334-0CE01-0AA0 6ES7 334-0KE00-0AB0
Analog inputs / outputs 4 AI / 2 AO 4 AI / 2 AO
AI resolution 8 bit (256 counts) 12 bit (4096 counts)
AO resolution 8 bit 12 bit
Voltage ranges 0-10 V, ±10 V 0-10 V, ±10 V, 1-5 V
Current ranges 0-20 mA, 4-20 mA 0-20 mA, 4-20 mA, ±20 mA
Channel isolation None (common ground) None (common ground)
Update time ≤ 1 ms ≤ 1 ms
1 LSB at 100 mm sensor span ≈ 0.39 mm ≈ 0.024 mm
Wire-break diagnostics Limited Limited
Resolution warning: The 8-bit AI on the -0CE01 module gives only 256 counts across the analog range. For a sensor with a 100 mm span this is approximately 0.39 mm per LSB - acceptable for visual feedback but too coarse for closed-loop positioning. Specify the -0KE00-0AB0 (12-bit, 4096 counts) when sub-millimeter repeatability is required. The 8-bit ceiling will show up as a stepwise jump of about 100 mm in the HMI as the target moves.

For a CPU 31x without an expansion rack, the slot-to-address map is:

Slot Address range (bytes) PIW (Channel 0 input word)
3 0-31 PIW 256
4 32-63 PIW 288
5 64-95 PIW 320
6 96-127 PIW 352
7 128-159 PIW 384
8 160-191 PIW 416

If the application is monitoring PIW 272, the SM334 sits in a slot whose address range starts at byte 128. With an IM 360/361 expansion, the rack-0 slots begin at byte 0 and rack-1 slots begin at byte 256, so PIW 272 is consistent with the module being the first signal slot on rack 1 (slot 4 of the expansion rack). Each AI consumes 2 bytes; the four AI channels therefore occupy PIW 272 through PIW 278. See the S7-300 System Manual for full addressing rules.

Baumer Laser Sensor Signal Characteristics

Baumer OADM and OHDM laser distance sensors are typically supplied with a 4-pin M12 connector. The most common pinout for a unit with a 4-20 mA current output is:

M12 pin Wire color Function
1 Brown (BN) +Vs (12-28 VDC supply)
2 White (WH) Digital output / not used
3 Blue (BU) 0 V (supply return)
4 Black (BK) Analog output (4-20 mA or 0-10 V, model-dependent)

Because the analog loop is fed from the same 0 V terminal that returns the supply current, the loop is fundamentally a 4-wire transmitter: the sensor internally generates its own loop excitation and drives the 4-20 mA signal back along the BK conductor with reference to BU. This drives the wiring topology on the SM334 and is the most-frequent source of an open-loop fault.

4-Wire Current Loop Wiring Procedure

The SM334-0CE01 accepts both 2-wire and 4-wire current. The 2-wire mode is intended for loop-powered transmitters that draw their operating current from the loop itself. Since the Baumer sensor is locally powered, you must use the 4-wire current mode and tie the sensor's BU (0 V) to the module's ManA analog-ground reference.

  1. Open the SM334 front door and identify the front connector. Loosen the connector screws and remove the connector from the module.
  2. Wire the supply side: connect the BN conductor (M12 pin 1) to a fused 24 VDC source. Connect the BU conductor (M12 pin 3) to the same 24 VDC source's 0 V terminal.
  3. At the SM334 front connector, identify the analog-input terminals for Channel 0. For the SM334-0CE01-0AA0, the channel 0 current positive is terminal 2 (with terminal 3 as the dedicated current-input terminal routed internally). Connect the BK wire (M12 pin 4) to terminal 2.
  4. Bond the sensor 0 V (BU) to the SM334's ManA reference at terminal 4 of the front connector. This is the step most often missed. The loop must have a return path to the analog ground of the SM334, even though the supply 0 V is already tied elsewhere.
  5. Re-insert the connector and torque the screws to 0.6 Nm.
  6. Power cycle the SM334 and the sensor supply.
Why the 0 V bond matters: The SM334 measures current by dropping it across an internal shunt to its own analog ground (ManA). If the sensor's 4-20 mA return has no connection back to that analog ground, the SM334 sees an open loop and returns 7FFFH (32767) regardless of actual sensor current. This is the single most frequent fault on first install.

STEP 7 Hardware Configuration

  1. Open the S7 project in STEP 7 V5.5 and launch HW Config.
  2. Locate the SM334 in the hardware catalog under SIMATIC 300 > SM-300 > AI/AO-300. Drag it to the slot matching the wiring.
  3. Double-click the module instance in the rack to open Properties. Record the start address of the AI - this must match the PIW monitored in OB1.
  4. Select the "Inputs" tab and click "Edit..." to open the channel-level configuration dialog.
  5. Set Channel 0 to "4-wire current" with the range "4..20 mA". Enable "Group diagnostics" if available on the variant.
  6. OK twice and save/compile the hardware configuration. Download to the CPU.

After compilation, the PIW address (PIW 272 in this case) returns raw counts as follows. See the SM334 Analog Module Manual for the exact representation table.

  • 4 mA = 0 decimal = 0000H
  • 20 mA = 27648 decimal = 6C00H
  • Open circuit / overflow = 32767 decimal = 7FFFH
  • Underflow / out-of-range negative = -32768 decimal = 8000H

STEP 7 Scaling to Engineering Units (FC105)

The Siemens standard block FC105 "SCALE" converts the raw INT value at the AI input word into a floating-point engineering value. Wire it as follows:

FC105 input Source Example for 50-150 mm sensor
IN PIW (INT) PIW 272
HI_LIM Engineering value at 20 mA 150.0
LO_LIM Engineering value at 4 mA 50.0
BIPOLAR 0 = unipolar 0
OUT REAL result MD 100 (or DB100.DBD0)

The conversion performed by FC105 is:

OUT = ((FLOAT(IN) - 0) / (27648 - 0)) × (HI_LIM - LO_LIM) + LO_LIM

For unipolar 4-20 mA, FC105 treats raw 0 as 0 mA, not 4 mA. To produce a true 4-20 mA scaled output where 4 mA = 50 mm and 20 mA = 150 mm, write the linear transfer function explicitly in OB1. The standard reference for FC105 and the related FC106 is in the Standard PID Control blocks documentation.

// STL excerpt for 4-20 mA scaling to millimeters
L   PIW 272              // raw input
ITD                      // convert INT to DINT
DTR                      // convert DINT to REAL
L   2.764800e+04         // 27648.0
/R                       // fraction of span
L   1.600000e+01         // 16.0 mA span
*R                       // mA above 4 mA zero
L   4.000000e+00         // 4 mA zero
+R                       // current in mA
L   6.250000e+00         // (150-50)/16 = 6.25 mm/mA
*R                       // distance above 50 mm
L   5.000000e+01         // 50 mm offset
+R                       // distance in mm
T   MD 100               // store as REAL

Place this in OB1 (or a cyclic interrupt OB30) on the same scan cycle that reads the input. MD 100 is the source for the HMI tag. For a more robust implementation, also clamp the result between LO_LIM and HI_LIM and substitute the overflow/underflow sentinel values (32767 / -32768) with the last good reading to avoid jumps on intermittent open loops.

HMI Display on WinCC Flexible / TIA WinCC

  1. Open the WinCC Flexible (or TIA WinCC Comfort/Advanced) project that targets the OP 370 12" panel.
  2. In the connection editor, verify the HMI connection points to the S7-300 CPU on the same MPI/PROFIBUS address used by STEP 7.
  3. Create a new tag, name it Distance_mm, type Real, and address it to MD 100 (or your DB).
  4. On a screen, drop an I/O field. Bind its Process value to Distance_mm. Set the display format to 999.9 to retain millimeter resolution even on the 8-bit module.
  5. Add a bar view (or trend view) bound to the same tag for a graphical indication.
  6. Compile the project and transfer it to the panel. Confirm the tag value updates when the target moves.

If the OP 370 panel uses a serial MPI cable, the transfer speed tops out at 187.5 kbit/s; long update cycles (>1 s) on a single tag are typically a connection or address problem, not a sampling issue. Confirm in WinCC Flexible's online diagnostics that the connection status is green.

Diagnostics and Troubleshooting Matrix

Observed symptom Likely cause Corrective action
Raw value stuck at 0 (PIW 272 = 0) Channel configured for voltage; sensor is in current mode Change HW Config channel to 4-wire current, recompile, download to CPU
Raw value at 32767 Open current loop (BU not bonded to ManA) Connect sensor BU to SM334 ManA terminal; verify screw torque
Raw value at 27648 regardless of distance Sensor output saturating at 20 mA; wrong measurement range, or reflective target too close Verify sensor model vs. measuring range; clean lens; check target distance against the sensor's blind zone spec
Raw value drifts ±50 counts Shared 24 V supply noise; long unshielded cable Use a separate 24 VDC for the sensor; route M12 cable in a grounded metal conduit; add 100 µF electrolytic across the supply at the sensor
HMI shows --- or red box Tag address mismatch between STEP 7 and WinCC Recheck MD 100 / DB100.DBD0 against the HMI tag address; confirm connection is online
Reading jumps in 100 mm steps 8-bit resolution of -0CE01 module Replace with -0KE00-0AB0 (12-bit) if sub-mm precision is required
SF LED on SM334 lit Module fault - configuration error, missing sensor supply, or wire break Open the CPU's diagnostic buffer (PLC > Module Information) for the exact fault code; resolve and clear
Reading wrong polarity (decreases as target approaches) Scaling formula or LO_LIM/HI_LIM reversed Swap LO_LIM and HI_LIM or invert the linear equation

Verification Checklist

  • SF LED on SM334 is off; BF LED is off (if PROFIBUS).
  • PIW 272 changes by at least one LSB when the target moves through the sensor's working range.
  • At the minimum measurement distance, PIW 272 ≈ 0; at maximum distance, PIW 272 ≈ 27648.
  • MD 100 (or your scaled value) follows the linear transfer function with the configured offsets.
  • HMI I/O field updates live and matches MD 100 to within rounding error.
  • The 24 VDC supply to the sensor shows less than 50 mVpp ripple under load.
  • ManA is bonded to PE at exactly one point (typically the cabinet PE bar).
  • Cable shield bonded to PE at the cabinet end only; sensor end of shield left floating.

Field-Proven Notes

  • The SM334-0CE01-0AA0 does not source loop excitation. The sensor must be locally powered and the loop must return to the module's ManA reference. There is no 2-wire sensor compatibility for the current ranges on this variant.
  • Bonding ManA to PE at the cabinet is the Siemens-recommended layout to keep analog-common noise low. Do not bond ManA to PE at more than one point, or ground loops will dominate the reading.
  • Long M12 cable runs (>15 m) should use shielded cable with the shield bonded to PE on the cabinet side only. The shield does not replace the 0 V bonding of BU - both connections are required.
  • If the application needs better than 0.5 mm repeatability, choose the SM334-0KE00-0AB0 (12-bit) or move the AI off the S7-300 entirely to an ET 200SP with a 16-bit AI module.
  • On the -0CE01 module, the AI channels share a common ground. Mixing a current input and a voltage input on the same module is allowed but cross-channel noise may rise; if precise simultaneous readings are needed, separate the noisy input onto its own module.
  • If you observe the SF LED after downloading HW Config, the most common cause is a mismatch between the configured measurement type (4-wire vs 2-wire) and the actual front-connector wiring. Resolve by aligning both.
  • For the OP 370 panel, the runtime does not poll the HMI tag faster than the configured update cycle (default 1 s for OP 370). Sub-second update of a slowly moving target is fine; high-speed oscillation will alias.

FAQ

How do I convert the raw PIW 272 value into millimeters?

Use FC105 with HI_LIM and LO_LIM set to your sensor's 20 mA and 4 mA engineering values, or compute the linear transfer function in OB1: (raw / 27648) × 16 mA span + 4 mA zero, then multiply by mm/mA and add the offset. Store the result in a REAL tag (MD or DB) for the HMI.

Why does PIW 272 read 32767 even though the sensor is powered?

32767 is the open-loop / overflow code from the SM334. The most likely cause is that the sensor's BU (0 V) conductor is not bonded back to the SM334's ManA terminal - the 4-20 mA return path is open. Check terminal 4 of the SM334 connector and confirm the jumper between ManA and the sensor 0 V.

Can I connect the Baumer sensor in 2-wire mode instead?

No, not with the SM334-0CE01-0AA0. That module does not source loop excitation - the sensor must be locally powered and the loop must return to the module's ManA reference. Use the 4-wire wiring described in this guide.

What is the difference between SM334-0CE01 and SM334-0KE00?

Both are 4 AI / 2 AO modules with the same voltage and current ranges, but the -0CE01 is 8-bit while the -0KE00 is 12-bit. For a laser sensor with a 100 mm span this is the difference between about 0.39 mm and 0.024 mm per LSB. Choose -0KE00 whenever the application needs sub-millimeter resolution.

How do I display the scaled distance on a Siemens OP 370 panel?

In WinCC Flexible (or TIA Portal WinCC) create a Real tag addressed to MD 100 or DB100.DBD0, place an I/O field on a screen bound to that tag, and transfer the project to the panel. Confirm the HMI-to-PLC connection is online and the address matches exactly.

Back to blog