2023年9月22日 星期五

Raspberry Pi Smart temperature and humidity controller

Purpose:

這個專題以Raspberry Pi為核心配合DHT22溫溼度模組來做智慧溫度濕度控制器. 在Raspberry Pi中用Node-Red為圖形化界面監看與控制, 當溫度或濕度達到設定的臨界值時, 就控制相對應的Relay Port開啟風扇電源或是除濕機的電源.

This Project uses Raspberry Pi as the core and use DHT22 temperature and humidity module to make a smart temperature and humidity controller. Node-Red is used as a graphical interface for monitoring and control in Raspberry Pi. When the temperature or humidity reaches the set critical value, Just control the corresponding Relay Port to turn on the fan power or dehumidifier power.


Fundamental:

Raspberry Pi:

Raspberry Pi is a popular embedded system board that is relatively small in size and easy to use. Its applications range from hobbyist to professional work areas.

Node-RED
Node-RED is a programming tool for wiring together hardware devices, APIs and online services in new and interesting ways. It provides a browser-based editor that makes it easy to wire together flows using the wide range of nodes in the palette that can be deployed to its runtime in a single-click.
Node-RED 是 IBM 以 Node.js 為基礎, 開發出來的視覺化 IOT 開發工具, 透過「流程圖」方式的操作,透過 Node-RED 完成許多後端才能做的事情.
Node-RED is a visual IOT development tool developed by IBM based on Node.js. Through the operation of "flow chart", Node-RED can accomplish many things that can only be done in the back end.

DHT22

Digital-output relative humidity & temperature sensor/module

DHT22 output calibrated digital signal. It utilizes exclusive digital-signal-collecting-technique and humidity sensing technology, assuring its reliability and stability.Its sensing elements is connected with 8-bit single-chip computer. Every sensor of this model is temperature compensated and calibrated in accurate calibration chamber and the calibration-coefficient is saved in type of programme in OTP memory, when the sensor is detecting, it will cite coefficient from memory.

Circuit:


Node-Red  [manage palette]:
安裝 [node-red-node-pi-gpio]
安裝 [node-red-dashboard]
安裝 [node-red-contrib-dht-sensor] 
安裝 [ node-rede-contrib-ui-led]
YouTubeDemo:


Project Flow:
[
    {
        "id": "aef41f4e7f9ffcd2",
        "type": "tab",
        "label": "Smart Controller",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "c2aa9ab7d944216f",
        "type": "group",
        "z": "aef41f4e7f9ffcd2",
        "name": "Dehumidifier Power",
        "style": {
            "label": true,
            "color": "#0070c0"
        },
        "nodes": [
            "dad906e5056313b7",
            "15d973b809fcf8c5",
            "ab8ca2c6987b9821",
            "0c9d579aa745e441"
        ],
        "x": 634,
        "y": 579,
        "w": 432,
        "h": 162
    },
    {
        "id": "c864c5cb1857aff5",
        "type": "group",
        "z": "aef41f4e7f9ffcd2",
        "name": "Fan Power",
        "style": {
            "label": true,
            "color": "#0070c0"
        },
        "nodes": [
            "c312bc57f817ba13",
            "bd7640195caa6ca9",
            "3295f6dfc16a53aa",
            "ee26765eecfa5105"
        ],
        "x": 734,
        "y": 39,
        "w": 432,
        "h": 162
    },
    {
        "id": "b1ca411cd3db418d",
        "type": "group",
        "z": "aef41f4e7f9ffcd2",
        "name": "DHT22",
        "style": {
            "label": true,
            "color": "#ff3f3f"
        },
        "nodes": [
            "b58557c19cf33861",
            "d8c369caf9c49e2a",
            "734a368317708723",
            "7b53ca8fb09a6ec9",
            "55f04fd31173302d",
            "6e9ff33159e25b5b",
            "7915f1ddd5bac848",
            "3ebed56c0f1d3c49",
            "5a392ccf4706717c",
            "f4664c58d588e0d5"
        ],
        "x": 94,
        "y": 219,
        "w": 812,
        "h": 302
    },
    {
        "id": "dad906e5056313b7",
        "type": "rpi-gpio out",
        "z": "aef41f4e7f9ffcd2",
        "g": "c2aa9ab7d944216f",
        "name": "",
        "pin": "21",
        "set": true,
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 980,
        "y": 620,
        "wires": []
    },
    {
        "id": "15d973b809fcf8c5",
        "type": "ui_button",
        "z": "aef41f4e7f9ffcd2",
        "g": "c2aa9ab7d944216f",
        "name": "",
        "group": "2104cf7020a0d823",
        "order": 6,
        "width": 3,
        "height": 2,
        "passthru": false,
        "label": "Relay1 ON",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 730,
        "y": 620,
        "wires": [
            [
                "dad906e5056313b7",
                "ab8ca2c6987b9821"
            ]
        ]
    },
    {
        "id": "ab8ca2c6987b9821",
        "type": "ui_led",
        "z": "aef41f4e7f9ffcd2",
        "g": "c2aa9ab7d944216f",
        "order": 2,
        "group": "2104cf7020a0d823",
        "width": 3,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "1",
                "valueType": "num"
            },
            {
                "color": "#808080",
                "value": "0",
                "valueType": "num"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 990,
        "y": 700,
        "wires": []
    },
    {
        "id": "0c9d579aa745e441",
        "type": "ui_button",
        "z": "aef41f4e7f9ffcd2",
        "g": "c2aa9ab7d944216f",
        "name": "",
        "group": "2104cf7020a0d823",
        "order": 7,
        "width": 3,
        "height": 2,
        "passthru": false,
        "label": "Relay1 OFF",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "0",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 730,
        "y": 700,
        "wires": [
            [
                "dad906e5056313b7",
                "ab8ca2c6987b9821"
            ]
        ]
    },
    {
        "id": "b58557c19cf33861",
        "type": "function",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "function 3",
        "func": "var num_h;\nnum_h=Number(msg.payload);\nif(num_h>65)\n{\n    num_h=1;\n}\nelse\n{\n    num_h = 0;\n}\nmsg.payload=num_h;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 480,
        "wires": [
            [
                "dad906e5056313b7",
                "ab8ca2c6987b9821"
            ]
        ]
    },
    {
        "id": "d8c369caf9c49e2a",
        "type": "inject",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "1",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 210,
        "y": 400,
        "wires": [
            [
                "734a368317708723"
            ]
        ]
    },
    {
        "id": "734a368317708723",
        "type": "rpi-dht22",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "topic": "rpi-dht22",
        "dht": 22,
        "pintype": "0",
        "pin": "18",
        "x": 400,
        "y": 400,
        "wires": [
            [
                "7b53ca8fb09a6ec9",
                "55f04fd31173302d"
            ]
        ]
    },
    {
        "id": "7b53ca8fb09a6ec9",
        "type": "function",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "function 1",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 360,
        "wires": [
            [
                "6e9ff33159e25b5b",
                "7915f1ddd5bac848",
                "f4664c58d588e0d5"
            ]
        ]
    },
    {
        "id": "55f04fd31173302d",
        "type": "function",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "function 2",
        "func": "//var num_h;\n//num_h=Number(msg.humidity);\nmsg.payload=msg.humidity\n//msg.payload=num_h;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 600,
        "y": 420,
        "wires": [
            [
                "3ebed56c0f1d3c49",
                "5a392ccf4706717c",
                "b58557c19cf33861"
            ]
        ]
    },
    {
        "id": "6e9ff33159e25b5b",
        "type": "ui_gauge",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "group": "0e2b7585a755f9de",
        "order": 1,
        "width": 5,
        "height": 4,
        "gtype": "gage",
        "title": "Temperature",
        "label": "C",
        "format": "{{value}}",
        "min": "15",
        "max": "50",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 810,
        "y": 320,
        "wires": []
    },
    {
        "id": "7915f1ddd5bac848",
        "type": "ui_chart",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "group": "0e2b7585a755f9de",
        "order": 2,
        "width": 5,
        "height": 4,
        "label": "Temperature",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "15",
        "ymax": "50",
        "removeOlder": "30",
        "removeOlderPoints": "",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 810,
        "y": 360,
        "wires": [
            []
        ]
    },
    {
        "id": "3ebed56c0f1d3c49",
        "type": "ui_gauge",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "group": "0e2b7585a755f9de",
        "order": 7,
        "width": 5,
        "height": 4,
        "gtype": "gage",
        "title": "Humidity",
        "label": "%",
        "format": "{{value}}",
        "min": "30",
        "max": "90",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "diff": false,
        "className": "",
        "x": 800,
        "y": 400,
        "wires": []
    },
    {
        "id": "5a392ccf4706717c",
        "type": "ui_chart",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "",
        "group": "0e2b7585a755f9de",
        "order": 8,
        "width": 5,
        "height": 4,
        "label": "Humidity",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm",
        "interpolate": "linear",
        "nodata": "",
        "dot": false,
        "ymin": "30",
        "ymax": "90",
        "removeOlder": "1",
        "removeOlderPoints": "",
        "removeOlderUnit": "3600",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 800,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "c312bc57f817ba13",
        "type": "rpi-gpio out",
        "z": "aef41f4e7f9ffcd2",
        "g": "c864c5cb1857aff5",
        "name": "",
        "pin": "16",
        "set": true,
        "level": "0",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 1080,
        "y": 80,
        "wires": []
    },
    {
        "id": "bd7640195caa6ca9",
        "type": "ui_button",
        "z": "aef41f4e7f9ffcd2",
        "g": "c864c5cb1857aff5",
        "name": "",
        "group": "2104cf7020a0d823",
        "order": 8,
        "width": 3,
        "height": 2,
        "passthru": false,
        "label": "Relay2 ON",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "1",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 830,
        "y": 80,
        "wires": [
            [
                "c312bc57f817ba13",
                "3295f6dfc16a53aa"
            ]
        ]
    },
    {
        "id": "3295f6dfc16a53aa",
        "type": "ui_led",
        "z": "aef41f4e7f9ffcd2",
        "g": "c864c5cb1857aff5",
        "order": 4,
        "group": "2104cf7020a0d823",
        "width": 3,
        "height": 1,
        "label": "",
        "labelPlacement": "left",
        "labelAlignment": "left",
        "colorForValue": [
            {
                "color": "#ff0000",
                "value": "1",
                "valueType": "num"
            },
            {
                "color": "#808080",
                "value": "0",
                "valueType": "num"
            }
        ],
        "allowColorForValueInMessage": false,
        "shape": "circle",
        "showGlow": true,
        "name": "",
        "x": 1090,
        "y": 160,
        "wires": []
    },
    {
        "id": "ee26765eecfa5105",
        "type": "ui_button",
        "z": "aef41f4e7f9ffcd2",
        "g": "c864c5cb1857aff5",
        "name": "",
        "group": "2104cf7020a0d823",
        "order": 9,
        "width": 3,
        "height": 2,
        "passthru": false,
        "label": "Relay2 OFF",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "0",
        "payloadType": "num",
        "topic": "topic",
        "topicType": "msg",
        "x": 830,
        "y": 160,
        "wires": [
            [
                "c312bc57f817ba13",
                "3295f6dfc16a53aa"
            ]
        ]
    },
    {
        "id": "f4664c58d588e0d5",
        "type": "function",
        "z": "aef41f4e7f9ffcd2",
        "g": "b1ca411cd3db418d",
        "name": "function 4",
        "func": "var num_t;\nnum_t=Number(msg.payload);\nif(num_t>26)\n{\n    num_t=1;\n}\nelse\n{\n    num_t = 0;\n}\nmsg.payload=num_t;\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 260,
        "wires": [
            [
                "3295f6dfc16a53aa",
                "c312bc57f817ba13"
            ]
        ]
    },
    {
        "id": "046f084a03bdabc2",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 3,
        "width": 1,
        "height": 1
    },
    {
        "id": "56fc7974bf0df6d5",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 4,
        "width": 1,
        "height": 1
    },
    {
        "id": "d2f0e79dd5618e5f",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 5,
        "width": 1,
        "height": 1
    },
    {
        "id": "7114d12cc24c98d3",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 6,
        "width": 1,
        "height": 1
    },
    {
        "id": "dc633da99afabc3c",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 9,
        "width": 1,
        "height": 1
    },
    {
        "id": "4f778b6229bc3367",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 10,
        "width": 1,
        "height": 1
    },
    {
        "id": "230e208a37857a0e",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 11,
        "width": 1,
        "height": 1
    },
    {
        "id": "095e70cc3213bfde",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "0e2b7585a755f9de",
        "order": 12,
        "width": 1,
        "height": 1
    },
    {
        "id": "e0fd59ec6ed4609c",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "2104cf7020a0d823",
        "order": 1,
        "width": 1,
        "height": 1
    },
    {
        "id": "c526f957ab3b1226",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "2104cf7020a0d823",
        "order": 3,
        "width": 3,
        "height": 1
    },
    {
        "id": "fbc05b659121e403",
        "type": "ui_spacer",
        "z": "aef41f4e7f9ffcd2",
        "name": "spacer",
        "group": "2104cf7020a0d823",
        "order": 5,
        "width": 2,
        "height": 1
    },
    {
        "id": "2104cf7020a0d823",
        "type": "ui_group",
        "name": "Power Relay",
        "tab": "e0180b1b272f835d",
        "order": 2,
        "disp": true,
        "width": 12,
        "collapse": false,
        "className": ""
    },
    {
        "id": "0e2b7585a755f9de",
        "type": "ui_group",
        "name": "DHT22",
        "tab": "e0180b1b272f835d",
        "order": 1,
        "disp": true,
        "width": 11,
        "collapse": false,
        "className": ""
    },
    {
        "id": "e0180b1b272f835d",
        "type": "ui_tab",
        "name": "Raspberry",
        "icon": "dashboard",
        "order": 6,
        "disabled": false,
        "hidden": false
    }
]

沒有留言:

張貼留言