Vai al contenuto

Light Intensity Sensor Documentation

Overview

This is a fully waterproof digital ambient-light sensor with a measurement range from 0 to 200,000 lux (0–200 klux). It operates via a standard RS-485 interface using the Modbus-RTU protocol. The sensor supports a wide input supply voltage from DC 5 V to 32 V.

Sensor Type

  • Interface: Modbus RTU/TCP
  • Read Type: Holding Registers
  • Unit: Lux (lx)

Key Features

  • Measurement range: 0 – 200,000 lux;
  • Accuracy: ±5%.
  • Modbus-RTU: configurable baud rates, parity, device address.
  • Wide supply voltage: DC 5-32 V. Working current < 10 mA.
  • Operating temperature: −40 °C to +80 °C

Sample Implementation

Here's a complete example of a Modbus-Read node that polls periodically from the light-intensity sensor:

⚠️ Disclaimer  

The following example is taken from test flows and may require configuration adjustments to work in your environment. Make sure to configure the nodes according to your specific setup and requirements.

Displayed flow

LightIntensity

Flow Components

Modbus Read Node

  • Reads two registers starting from address 2 on Modbus Unit ID 1

  • Polling rate: every 10 seconds

  • Returns msg.payload = [HR3, HR4] containing high and low register values

Switch Node

  • Ensures that the payload is not empty before converting to lux

Function Node

Combines the two registers into a 32-bit value and converts to lux:


let rawLux = HR3 * 65536 + HR4;

let lux = rawLux / 1000;

Routes the lux value to one of three outputs depending on intensity:

Lux Range (lx) Output LED Meaning
400 – 600 1 Green Normal light
200 – 400 or 600 – 1000 2 Red Low or high light
<200 or >1000 3 Heartbeat Red Critical levels

Modbus Client

Configures communication with the sensor:

  • Serial port: /dev/ttyLP6

  • Baud rate: 9600, 8N1

  • Timeout: 1000ms

  • Automatic reconnection on failure

Flow Example

The following JSON can be imported directly into Node-RED:


[

  {

    "id": "5c41fb07c417f21e",

    "type": "tab",

    "label": "Light Intensity",

    "disabled": false,

    "info": "",

    "env": []

  },

  {

    "id": "d0ea11e15f673dff",

    "type": "LedControl",

    "z": "5c41fb07c417f21e",

    "name": "Heartbeat Red",

    "led": "Red",

    "heartbeat": true,

    "x": 1220,

    "y": 500,

    "wires": []

  },

  {

    "id": "6eb94ce50998beee",

    "type": "modbus-read",

    "z": "5c41fb07c417f21e",

    "name": "Light-intensity sensor",

    "unitid": "1",

    "dataType": "HoldingRegister",

    "adr": "2",

    "quantity": "2",

    "rate": "10",

    "rateUnit": "s",

    "server": "58adeeb67107b4f5",

    "x": 240,

    "y": 400,

    "wires": [["8ebce3e515997e06"], []]

  },

  {

    "id": "739cfbfa32595da5",

    "type": "function",

    "z": "5c41fb07c417f21e",

    "name": "Calculate Lux",

    "outputs": 3,

    "func": "let HR3 = msg.payload[0];\nlet HR4 = msg.payload[1];\nlet rawLux = HR3 * 65536 + HR4;\nlet lux = rawLux / 1000;\nlet outputs = [null,null,null];\nif(lux>=400 && lux<=600){outputs[0]={payload:lux};} else if((lux>=200 && lux<400)||(lux>600 && lux<=1000)){outputs[1]={payload:lux};} else{outputs[2]={payload:lux};}\nreturn outputs;",

    "x": 860,

    "y": 400,

    "wires": [

      ["3b47df4bcc81187c","3a88e428ae0f87d9"],

      ["0ff2abc76f7e6f0d","6ea78b7d7fdcaedb"],

      ["d0ea11e15f673dff","e311387b966a368f"]

    ]

  }

]