IRIV PiControl - Node-RED Modbus-RTU - Temperature and Humidity Sensor

IRIV PiControl - Node-RED Modbus-RTU - Temperature and Humidity Sensor

Hi and welcome back again to another tutorial on using IRIV PiControl with Node-RED. In this tutorial, we will see how we can monitor the temperature and humidity using Node-RED.

 

 

Hardware

 

Set unit ID for the sensor

 

Before we see the connection diagram, first, we'll set the Unit ID for the sensor. This ID will be used in our code later to get the readings. To do this, we need to access the DIP switch on the sensor's PCB. Gently open both ends of the sensor, one at a time.
 
Next, carefully remove the PCB from the metal shell. You'll find the DIP switch on the PCB, which determines the Unit ID. For this tutorial, we'll set the Unit ID to 1. Refer to the datasheet for detailed instructions on setting the Unit ID.

 

 

Now, reassemble the sensor securely. With that done, we're ready to connect the wires to the IRIV PiControl.

 

Connection Diagram

 

Power Supply Connection:

  • Start by powering up the power supply using 120-240V AC source.
  • Connect the power supply to the IRIV PiControl.

 

Sensor Connection:

Since we're working with an isolated power connection system in IRIV, we will have to use the external power supply for the sensor.

  • Connect the black wire to GND
  • Connect the red wire to VIN
  • Connect the yellow wire to (RS485 A) pin in IRIV
  • Connect the white wire to (RS485 B) pin in IRIV

 

Note: Please remember to handle all connections with care and double-check connections for accuracy.

 

Node-RED Programming

 

To start on Node-RED, first we need to install Modbus nodes. You can do this using the Node-RED palette manager. Then, Look for these Modbus nodes (node-red-contrib-modbus).

 

 

We will start by dragging an inject node onto the flow. Open its properties and set (Repeat) to interval every 1 second.

 

 

Next, drag and drop (Modbus Getter) node and open its properties window.

 

 

Adjust the following settings:

 

Unit-Id: 1 
When communicating with a Modbus device, you need to specify its unit ID so that the data exchange occurs with the correct device. Previously, we already set the unit-Id of the sensor to 1.

 

FC: FC 3: Read Holding Registers
This the function code, and it specifies the type of Modbus function to be performed.


Address: 0
The address specifies the starting register from which data will be read or written. Type in 0 For the temperature and humidity sensor we are using.


Quantity: 2 
The quantity specifies the number of registers to be read or written. For instance, if you want to read the temperature and humidity data from two consecutive registers, you would specify the starting address and a quantity of 2.

 

 

Next, we have to edit the server settings. Change the server Type to Serial.


For the serial port, click on the search icon, and then choose this port (/dev/tty/ACM0)


Change the serial type to RTU


Click on Add, then close the window.

 

 

Now, drag a function node to get the humidity readings, open its properties and write this short code. Number 0 in this line is to get the humidity reading from the Modbus Getter node. Click done.

 

 

Drag another function node to get the temperature readings, open its properties, and write this code, make sure to adjust this number to 1, to get the temperature readings.

 

 

Now, drag 2 debug nodes to display the readings in the debug window. Connect all the nodes together this way, then click Deploy, and you will notice the readings appear in the Debug window.

 

 

Now, let’s take this step further, and display the readings in the dashboard.

 

Drag 2 gauge nodes, open the first one, and adjust these settings for humidity readings.

 

 

Open the second one, and adjust these settings for temperature readings.

 

 

Now, connect these nodes this way, and hit Deploy.

 

After that, open a new tab in your browser, and type in this address (iriv.local:1880/ui) to access the dashboard.

 

 

And there you go, now you can monitor the temperature and humidity through this Node-RED dashboard. 

 

That’s all for this tutorial, thanks for watching, and stay tuned for more.

Hardware Components




Chat hỗ trợ
Chat ngay