This is the second phase of the Node-Red with LattePanda 3 Delta, this will guide you to interact with sensors and collect the data.
Let's Connect the Sensor:We can't directly use the LattePanda 3 Delta's GPIO with Node-Red. So, we have to use serial communication between internal Arduino and Node-Red.
First, we have to program the Arduino core with the sensors. In my Arduino tutorial, I have shown the DHT11 with Arduino core. I'm going to use the same configuration.
To use the DHT11 sensor, first, we need the DHT11 library. Go to the library manager and search for DHTLIB and install the library.
Then select the DHT11 Sensor test code in the examples.
Note in this example code they are using Digital Pin 5. So, we connect the DHT11 with pin 5 of the LP3 Arduino.
I have edited the code as per our needs.
Upload the code and open the serial monitor.
Note: Set baud rate as 115200
It will show you the Sensor status, Humidity level, and Temperature readings.
This is a simple message we can use this in serial communication to connect with Node-Red. But, if you are connecting more than 1 sensor means you have to do some changes in the data,
The easiest way to use multiple sensor data is JSON. We have packed all our sensor data into JSON and we can decode it by using Node-Red.
First, install the Arduino JSON library.
And use the following code to make the DHT11 data into a JSON output.
Here is the serial monitor response.
Let's make the JSON more beautiful.
serializeJsonPretty(doc, Serial);
This piece of code will make the JSON look beautiful. Here is the serial monitor response.
But note that, this beautiful JSON won't work in this serial mode. So use the normal JSON.
Integrate with Node-Red:Then open the Node-Red dashboard and add the serial input node and also a debug node.
Then select the correct port in the Serial input node.
Next, just connect it with the Debug node and click on Deploy.
Now our sensor data are linked with the Node-Red. Next covert the JSON into objects by using the JSON node.
Here are the node properties.
This is how the data lookalike after the JSON node.
Now we are having all the data in a readable format, let's make some UI to make it visually good and add the gauge node from the node pallet.
Open the properties of the gauge node and set the dashboard type. Then select the value in that enter
msg.payload.Temperature
Here are the complete properties.
Next, design the same with humidity.
That's all now all good, let's move on to the UI.
We have seen with the sensor interface with Node-Red, now you can connect the sensors and actuators as per you want and you can easily show these data in the UI. In the next tutorial will see how to transfer this sensor data into the cloud.
Comments