Description
The FB_LuxRegelung function block implements a simple proportional control for a light signal based on a lux sensor. It scales the sensor signal to 0–1000 lux, calculates the target-actual deviation multiplied by the gain factor Kp, and provides a proportional output value for a 0–10 V interface. The code is written in SCL and runs directly in the Siemens TIA Portal.
Note: All modules are designed exclusively as a learning and optimization basis and are not approved for live operation. System modules, in particular, must be finally tested and commissioned by qualified personnel before productive use.
Functionality (compact)
- Scaling: Raw value ActualValue → ActualLux by multiplying by 1000 and dividing by 27648
- Control start inactive: Percent = 0, LightOut = 0, StatusText = "Control inactive"
-
Regulation active:
- Difference = Target value – Actual Lux
- Percent = Difference × Kp, limited to 0–100%
- LightOut = percent × 276.48 (digital range 0–27648)
- StatusText = "Regulation in progress"
Technical details
- Inputs: ActualValue (INT), SetValue (REAL), Kp (REAL), ControlStart (BOOL)
- Variables/Outputs: ActualLux (REAL), Percent (REAL), LightOut (INT), StatusText (STRING)
-
Calculations:
- ActualLux = ActualValue × 1000 / 27648
- Percent = (Setpoint – ActualLux) × Kp (Clamping 0–100)
- LightOut = INT(Percent × 276.48)
- Flow control: simple IF structure, no timer, RETURN when inactive
Possible applications
Control of lighting in industrial halls, laboratories, daylight compensation in greenhouses and exhibition rooms as well as training and demonstration projects for PLC proportional control.
compatibility
Siemens S7-1200/S7-1500, TIA Portal ≥ V13 (V16+ recommended for HMI/PLCSIM).
Scope of delivery
.scl
file with declaration of all inputs/outputs, internal variables, parameter comments, and header comments (author, contact, customization instructions); download link after purchase.
Support
Adjustment of target value and Kp, integration of additional sensors or HMI layouts – individual advice via shop message or email.