Raspberry pi based Industrial Automation using Node-RED platform

Industrial Automation using Node-RED Dashboard and Raspberry pi

As Node-RED is an IoT tool and Raspberry pi can be used as a controller and processor, we can deploy Node-RED and Raspberry pi to collect data from sensors. Based on the sensor data and user-defined data from the Node-RED dashboard, we can control the dryer fan, heater, spray, and flap to dehumidify.

Components used:

  1. Raspberry Pi
  2. Arduino Uno
  3. Arduino ethernet shield
  4. Temperature sensor
  5. Humidity sensor
  6. Wifi router
  7. Relay module
  8. 7'' Raspberry Pi touch screen display

I have used the Arduino Ethernet shield to collect sensor data. After collecting data, Arduino will send data to Raspberry Pi through the MQTT protocol.

Video documentation of the project:
You can get an idea of how the system implemented by watching the video.

Node-RED Flows:

  • Admin
  • Pi Operations
  • Input Data
  • Fan Control
  • User input DB

Node-RED Node used:
You can download and install the flows from the Node-RED plotter or from the official pages of the individual node.

  • Node-RED default dashboard
  • MSSQL
  • GPIO etc.

You have to customize the database information and edit table info.

image

Communication Protocol:

The Pi Operations flow is given below:

[{"id":"66b2972b.29615","type":"tab","label":"Pi Operation","disabled":false,"info":""},{"id":"6c446926.f511b","type":"comment","z":"66b2972b.29615","name":"Spray","info":"","x":90,"y":380,"wires":[]},{"id":"d5d8818c.bcc3b","type":"comment","z":"66b2972b.29615","name":"Heater","info":"","x":90,"y":40,"wires":[]},{"id":"fa914a13.3eba7","type":"ui_text","z":"66b2972b.29615","group":"8ea9b56a.952ed","order":1,"width":0,"height":0,"name":"","label":"Heater Status","format":"{{msg.payload}}","layout":"row-spread","x":600,"y":200,"wires":[]},{"id":"6125d365.3371c4","type":"ui_text","z":"66b2972b.29615","group":"8ea9b56a.952ed","order":2,"width":0,"height":0,"name":"","label":"Spray Status","format":"{{msg.payload}}","layout":"row-spread","x":590,"y":620,"wires":[]},{"id":"600d310a.acc36","type":"ui_text","z":"66b2972b.29615","group":"8ea9b56a.952ed","order":4,"width":0,"height":0,"name":"","label":"Flap Open","format":"{{msg.payload}}","layout":"row-spread","x":1470,"y":180,"wires":[]},{"id":"90c9da79.b78798","type":"ui_text","z":"66b2972b.29615","group":"8ea9b56a.952ed","order":3,"width":0,"height":0,"name":"","label":"Flap Close","format":"{{msg.payload}}","layout":"row-spread","x":1450,"y":580,"wires":[]},{"id":"3c49022d.56c66e","type":"rpi-gpio out","z":"66b2972b.29615","name":"","pin":"40","set":true,"level":"1","freq":"","out":"out","x":1620,"y":100,"wires":[]},{"id":"ee76ad1f.26515","type":"rpi-gpio out","z":"66b2972b.29615","name":"","pin":"37","set":true,"level":"1","freq":"","out":"out","x":580,"y":540,"wires":[]},{"id":"e97b1ddd.b5d618","type":"rpi-gpio out","z":"66b2972b.29615","name":"","pin":"35","set":true,"level":"1","freq":"","out":"out","x":1540,"y":520,"wires":[]},{"id":"acce0f6b.e5646","type":"comment","z":"66b2972b.29615","name":"Fl-open","info":"","x":910,"y":80,"wires":[]},{"id":"b4532319.a7caf","type":"comment","z":"66b2972b.29615","name":"Fl-close","info":"","x":870,"y":480,"wires":[]},{"id":"df5743f1.91a398","type":"function","z":"66b2972b.29615","name":"Spray","func":"const spray = global.get(\"sprayState\");\nmsg.payload = spray ;\nreturn msg;","outputs":1,"noerr":0,"x":190,"y":540,"wires":[["89147cb4.4ccf68","7ec8a06c.15e82","6eeb62e2.2e301c"]]},{"id":"9fbef318.d5bbc","type":"inject","z":"66b2972b.29615","name":"","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":50,"y":540,"wires":[["df5743f1.91a398"]]},{"id":"89147cb4.4ccf68","type":"debug","z":"66b2972b.29615","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":190,"y":600,"wires":[]},{"id":"7ec8a06c.15e82","type":"change","z":"66b2972b.29615","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":620,"wires":[["6125d365.3371c4"]]},{"id":"8d68efe2.489898","type":"function","z":"66b2972b.29615","name":"Flap Open","func":"const flapOpen = global.get(\"flap_openState\");\nmsg.payload = flapOpen ;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":140,"wires":[["457671df.68924","8cd2470a.0e832"]]},{"id":"c39e0192.af7828","type":"inject","z":"66b2972b.29615","name":"","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":910,"y":140,"wires":[["8d68efe2.489898"]]},{"id":"457671df.68924","type":"debug","z":"66b2972b.29615","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1070,"y":220,"wires":[]},{"id":"2bd35812.765f7","type":"change","z":"66b2972b.29615","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1280,"y":180,"wires":[["600d310a.acc36"]]},{"id":"e141ebb2.d536b","type":"function","z":"66b2972b.29615","name":"Flap Close","func":"const flapClose = global.get(\"flap_closeState\");\nmsg.payload = flapClose ;\nreturn msg;","outputs":1,"noerr":0,"x":1030,"y":540,"wires":[["674c5fbd.2700b","3bf907c5.fd09c8"]]},{"id":"6b724a3e.d01b84","type":"inject","z":"66b2972b.29615","name":"","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":870,"y":540,"wires":[["e141ebb2.d536b"]]},{"id":"674c5fbd.2700b","type":"debug","z":"66b2972b.29615","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1030,"y":620,"wires":[]},{"id":"9bed41f5.b1643","type":"change","z":"66b2972b.29615","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1260,"y":580,"wires":[["90c9da79.b78798"]]},{"id":"20f73a35.d4b9ae","type":"delay","z":"66b2972b.29615","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":420,"wires":[["767d3297.5f1c44"]]},{"id":"8cd2470a.0e832","type":"rbe","z":"66b2972b.29615","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":1190,"y":100,"wires":[["de4f38c8.dc3788","2bd35812.765f7","ece33157.b65be"]]},{"id":"43ddb5ca.b6b614","type":"delay","z":"66b2972b.29615","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1480,"y":40,"wires":[["3c49022d.56c66e"]]},{"id":"3bf907c5.fd09c8","type":"rbe","z":"66b2972b.29615","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":1070,"y":480,"wires":[["542c0f1a.6c44a8","9bed41f5.b1643"]]},{"id":"1c929ca6.09857b","type":"delay","z":"66b2972b.29615","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1400,"y":460,"wires":[["e97b1ddd.b5d618"]]},{"id":"beb45215.1e76b","type":"switch","z":"66b2972b.29615","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":480,"wires":[["20f73a35.d4b9ae"],["ee76ad1f.26515"]]},{"id":"542c0f1a.6c44a8","type":"switch","z":"66b2972b.29615","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1230,"y":480,"wires":[["1c929ca6.09857b"],["e97b1ddd.b5d618"]]},{"id":"de4f38c8.dc3788","type":"switch","z":"66b2972b.29615","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1310,"y":60,"wires":[["43ddb5ca.b6b614"],["3c49022d.56c66e"]]},{"id":"343cb6af.060e02","type":"inject","z":"66b2972b.29615","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":1370,"y":100,"wires":[["3c49022d.56c66e"]]},{"id":"fa3b8876.5a3bf8","type":"inject","z":"66b2972b.29615","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":410,"y":540,"wires":[["ee76ad1f.26515"]]},{"id":"6eeb62e2.2e301c","type":"rbe","z":"66b2972b.29615","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":230,"y":480,"wires":[["beb45215.1e76b","586502ff.44e20c"]]},{"id":"586502ff.44e20c","type":"trigger","z":"66b2972b.29615","name":"","op1":"connected","op2":"no command","op1type":"str","op2type":"str","duration":"120","extend":true,"units":"s","reset":"","bytopic":"all","outputs":1,"x":270,"y":680,"wires":[["b96c8972.737c1"]]},{"id":"b96c8972.737c1","type":"function","z":"66b2972b.29615","name":"","func":"var flag = msg.payload;\nif (flag === \"no command\"){\n    msg.payload = \"1\";\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":680,"wires":[["e28d624c.338008"]]},{"id":"e28d624c.338008","type":"change","z":"66b2972b.29615","name":"SprayState","rules":[{"t":"set","p":"sprayState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":680,"wires":[[]]},{"id":"ece33157.b65be","type":"trigger","z":"66b2972b.29615","name":"","op1":"connected","op2":"no command","op1type":"str","op2type":"str","duration":"3","extend":true,"units":"min","reset":"","bytopic":"all","outputs":1,"x":1230,"y":260,"wires":[["2425756f.b34922"]]},{"id":"2425756f.b34922","type":"function","z":"66b2972b.29615","name":"","func":"var flag = msg.payload;\nif (flag === \"no command\"){\n    msg.payload = \"1\";\n    return msg;\n}\n","outputs":1,"noerr":0,"x":1390,"y":260,"wires":[["e4f2e9b2.ad3d3"]]},{"id":"e4f2e9b2.ad3d3","type":"change","z":"66b2972b.29615","name":"FlapOpenState","rules":[{"t":"set","p":"flap_openState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1560,"y":260,"wires":[[]]},{"id":"767d3297.5f1c44","type":"function","z":"66b2972b.29615","name":"","func":"\nconst sprayS = global.get(\"sprayState\");\n\nif (sprayS === 1){\n    msg.payload = \"1\";\n    return msg;\n}\nelse{\n    msg.payload = \"0\";\n    return msg;\n}\n","outputs":1,"noerr":0,"x":600,"y":420,"wires":[["ee76ad1f.26515","24b9cf4.254513"]]},{"id":"ab79d946.d55b78","type":"rpi-gpio out","z":"66b2972b.29615","name":"","pin":"33","set":true,"level":"1","freq":"","out":"out","x":640,"y":140,"wires":[]},{"id":"7f410ef9.210ac","type":"function","z":"66b2972b.29615","name":"Heater","func":"const heater = global.get(\"heaterState\");\nmsg.payload = heater ;\nreturn msg;","outputs":1,"noerr":0,"x":210,"y":160,"wires":[["3864d003.cee428","66885256.589c2c","1ab55909.1b0cff"]]},{"id":"33815118.773c3e","type":"inject","z":"66b2972b.29615","name":"","repeat":"2","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":70,"y":160,"wires":[["7f410ef9.210ac"]]},{"id":"3864d003.cee428","type":"debug","z":"66b2972b.29615","name":"","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":170,"y":220,"wires":[]},{"id":"9b880806.3ea4e","type":"change","z":"66b2972b.29615","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"0","fromt":"num","to":"ON","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"1","fromt":"num","to":"OFF","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":200,"wires":[["fa914a13.3eba7"]]},{"id":"66885256.589c2c","type":"rbe","z":"66b2972b.29615","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":270,"y":100,"wires":[["9b880806.3ea4e","933a6872.0a7f9"]]},{"id":"cd0adf61.4f18f","type":"delay","z":"66b2972b.29615","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":460,"y":40,"wires":[["7d282c3f.f93c1c"]]},{"id":"933a6872.0a7f9","type":"switch","z":"66b2972b.29615","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":410,"y":100,"wires":[["cd0adf61.4f18f"],["ab79d946.d55b78"]]},{"id":"f76c54ea.14379","type":"inject","z":"66b2972b.29615","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":430,"y":140,"wires":[["ab79d946.d55b78"]]},{"id":"1ab55909.1b0cff","type":"trigger","z":"66b2972b.29615","name":"","op1":"connected","op2":"no command","op1type":"str","op2type":"str","duration":"40","extend":true,"units":"s","reset":"","bytopic":"all","outputs":1,"x":350,"y":260,"wires":[["75d28444.1a4d04"]]},{"id":"75d28444.1a4d04","type":"function","z":"66b2972b.29615","name":"","func":"var flag = msg.payload;\nif (flag === \"no command\"){\n    msg.payload = \"1\";\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":260,"wires":[["d718db3e.327d7"]]},{"id":"d718db3e.327d7","type":"change","z":"66b2972b.29615","name":"HeaterState","rules":[{"t":"set","p":"heaterState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":630,"y":260,"wires":[[]]},{"id":"7d282c3f.f93c1c","type":"function","z":"66b2972b.29615","name":"","func":"\nconst heaterC = global.get(\"heaterState\");\n\nif (heaterC === 1){\n    msg.payload = \"1\";\n    return msg;\n}\nelse{\n    msg.payload = \"0\";\n    return msg;\n}\n","outputs":1,"noerr":0,"x":620,"y":40,"wires":[["ab79d946.d55b78","3ecf8eb.06398f2"]]},{"id":"3ecf8eb.06398f2","type":"change","z":"66b2972b.29615","name":"HeaterState","rules":[{"t":"set","p":"heaterState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":40,"wires":[[]]},{"id":"24b9cf4.254513","type":"change","z":"66b2972b.29615","name":"SprayState","rules":[{"t":"set","p":"sprayState","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":770,"y":420,"wires":[[]]},{"id":"8ea9b56a.952ed","type":"ui_group","name":"Machine State","tab":"6e79199b.0159e","order":9,"disp":true,"width":5,"collapse":true},{"id":"6e79199b.0159e","type":"ui_tab","name":"Dryer one","icon":"fa-table","order":4,"disabled":false,"hidden":false}]

Note:
Because of limitations, I can't share all flows here. Please visit my blog for flows and Arduino ethernet shield code.

More Details and Arduino code, flows can be found here:

9 Likes

I faced some problem and discussed here. You can have a look. Thanks!

Here is the full project details, Arduino code and Node-RED flows. Visit if you need:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.