ĐỌC GIÁ TRỊ CỦA CẢM BIẾN ĐO TỐC ĐỘ GIÓ, HƯỚNG GIÓ VÀ ĐƯA CÁC GIÁ TRỊ HIỂN THỊ LÊN INTERNET | Cộng đồng Arduino Việt Nam

`Bạn Cần Chuẩn Bị Thư Viện Cho iNut Cảm Biến Cho Arduino :https://github.com/ngohuynhngockhanh/iNut-Arduino-library

CODE ARDUINO

#include 

iNut sensor;
int VaneValue;// raw analog value from wind vane
int Direction;// translated 0 - 360 direction
int CalDirection;// converted value with offset applied
int LastValue;
#define Offset 0;
void setup()
 {   
   Serial.begin(9600);


   LastValue = 1;
   Serial.println("Vane Value\tDirection\tHeading");
   sensor.setup(3);
 }

 void loop()
 {
  VaneValue = analogRead(A2);
  Direction = map(VaneValue, 0, 1023, 0, 360);
  CalDirection = Direction + Offset;
  if(CalDirection > 360)
  CalDirection = CalDirection - 360;
if(CalDirection < 0)
CalDirection = CalDirection + 360;
// Only update the display if change greater than 2 degrees.
if(abs(CalDirection - LastValue) > 5)
{
Serial.print(VaneValue); Serial.print("\t\t");
Serial.print(CalDirection); Serial.print("\t\t");
getHeading(CalDirection);
LastValue = CalDirection;
}
}
// Converts compass direction to heading
void getHeading(int direction) {
if(direction < 22)
Serial.println("Bắc");
else if (direction < 67)
Serial.println("Đông Bắc");
else if (direction < 112)
Serial.println("Đông");
else if (direction < 157)
Serial.println("Đông Nam");
else if (direction < 212)
Serial.println("Nam");
else if (direction < 247)
Serial.println("Tây Nam");
else if (direction < 292)
Serial.println("Tây");
else if (direction < 337)
Serial.println("Tây Bắc");
else
Serial.println("Bắc");
sensor.setValue(1,direction  );
  unsigned long timer = 0;
   int sensorValue = analogRead(A3);
   float outvoltage = sensorValue * (5.0 / 1023.0);
   Serial.print("Dien ap = ");
   sensor.setValue(2,outvoltage);
   Serial.print(outvoltage);
   Serial.println("V");
   float Level = 6*outvoltage;//The level of wind speed is proportional to the output voltage.
   Serial.print("Cap do gio ");
   sensor.setValue(0,Level);
   Serial.print(Level);

//   Serial.println(" level now");
   Serial.println();
   Serial.print("");
  sensor.loop();
 }

Trên APP INUT

Bạn theo dõi link này để cài đặt app, tạo tài khoản và đăng nhập vào, chọn thiết bị: http://arduino.vn/cc

Bước 1: Mở app iNut, chọn vào phần cài đặt -> chọn iNut Cảm Biến

Bước 2: Xem thông tin hiển thị trên iNut

Xem thêm: Phụ kiện máy dệt kim Kim máy dệt Golden Sharp giá rẻ nhất tháng 03/2022

TRÊN INUT NODE RED IDE
Các bạn xem cách thiết lập iNut Node Red Ide theo link : http://arduino.vn/cc

Các bạn vào phần import, copy paste đoạn code này vào theo hướng dẫn : http://arduino.vn/bai-viet/6797-huong-dan-su-dung-inut-cam-bien-va-node-red-ide-de-hien-thi-bieu-do-thoi-tiet

[
    {
        "id": "e6aa6a4d.549c08",
        "type": "subflow",
        "name": "Lấy dữ từ iNut",
        "info": "",
        "in": [
            {
                "x": 50,
                "y": 30,
                "wires": [
                    {
                        "id": "b2696ea9.2b3d6"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 1000,
                "y": 180,
                "wires": [
                    {
                        "id": "9fe08818.572a48",
                        "port": 0
                    }
                ]
            },
            {
                "x": 1000,
                "y": 260,
                "wires": [
                    {
                        "id": "9fe08818.572a48",
                        "port": 1
                    }
                ]
            },
            {
                "x": 980,
                "y": 320,
                "wires": [
                    {
                        "id": "9fe08818.572a48",
                        "port": 2
                    }
                ]
            }
        ],
        "inputLabels": [
            "Nhận đầu vào MQTT IN từ iNut cảm biến"
        ],
        "outputLabels": [
            "Luồng cảm biến 1",
            "Luồng cảm biến 2",
            "Luồng cảm biến 3",
            "Luồng cảm biến 4",
            "Luồng cảm biến 5",
            "Luồng cảm biến 6",
            "Luồng cảm biến 7",
            "Luồng cảm biến 8"
        ]
    },
    {
        "id": "b2696ea9.2b3d6",
        "type": "json",
        "z": "e6aa6a4d.549c08",
        "name": "",
        "property": "payload",
        "action": "",
        "pretty": false,
        "x": 165,
        "y": 84,
        "wires": [
            [
                "4da8cac2.24acf4"
            ]
        ]
    },
    {
        "id": "9fe08818.572a48",
        "type": "switch",
        "z": "e6aa6a4d.549c08",
        "name": "Phân luồn",
        "property": "relayId",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "1",
                "vt": "num"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "num"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 825.9869575500488,
        "y": 288.1562738418579,
        "wires": [
            [],
            [],
            []
        ]
    },
    {
        "id": "4da8cac2.24acf4",
        "type": "function",
        "z": "e6aa6a4d.549c08",
        "name": "Lặp",
        "func": "if (!msg.states) {\n    msg.states = msg.payload\n    msg.i = 0\n    return msg;\n} else {\n    msg.i++\n    if (msg.states[msg.i])\n        return msg;\n}\n",
        "outputs": 1,
        "noerr": 0,
        "x": 327.89060974121094,
        "y": 83.33600330352783,
        "wires": [
            [
                "fb3946a3.9ccf78"
            ]
        ]
    },
    {
        "id": "fb3946a3.9ccf78",
        "type": "function",
        "z": "e6aa6a4d.549c08",
        "name": "Lấy trạng thái thiết bị",
        "func": "msg.relayId = msg.i\nmsg.payload = msg.states[msg.i].state\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 477.89060974121094,
        "y": 183.33600330352783,
        "wires": [
            [
                "4da8cac2.24acf4",
                "9fe08818.572a48"
            ]
        ]
    },
    {
        "id": "2ca49b8.92f0764",
        "type": "ui_gauge",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "900c0194.8d7a9",
        "order": 1,
        "width": "6",
        "height": "3",
        "gtype": "gage",
        "title": "Hướng Gió",
        "label": "",
        "format": "{{value}}",
        "min": 0,
        "max": "360",
        "colors": [
            "#1f964f",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 790,
        "y": 360,
        "wires": []
    },
    {
        "id": "9b857a7b.7c7b4",
        "type": "ui_gauge",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "ec123a3f.3570f8",
        "order": 1,
        "width": "6",
        "height": "3",
        "gtype": "gage",
        "title": "Gió",
        "label": "m/s",
        "format": "{{value}}",
        "min": 0,
        "max": "10",
        "colors": [
            "#1f964f",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 730,
        "y": 180,
        "wires": []
    },
    {
        "id": "f398e233.c33db8",
        "type": "subflow:e6aa6a4d.549c08",
        "z": "edde96c.5e59968",
        "name": "",
        "x": 380,
        "y": 300,
        "wires": [
            [
                "b7eadbd9.cf44a8"
            ],
            [
                "a958973.76e2de8"
            ],
            [
                "2ee5cd9c.c01b1a"
            ]
        ]
    },
    {
        "id": "9889a59d.5e737",
        "type": "ui_gauge",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "2df6fcf.9ea0804",
        "order": 1,
        "width": "6",
        "height": "3",
        "gtype": "gage",
        "title": "Hiệu Điện Thế",
        "label": "V",
        "format": "{{value}}",
        "min": 0,
        "max": "12",
        "colors": [
            "#1f964f",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 760,
        "y": 420,
        "wires": []
    },
    {
        "id": "b7eadbd9.cf44a8",
        "type": "change",
        "z": "edde96c.5e59968",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Gió",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 180,
        "wires": [
            [
                "9b857a7b.7c7b4",
                "f125cd8c.b65ff8"
            ]
        ]
    },
    {
        "id": "f125cd8c.b65ff8",
        "type": "ui_chart",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "ec123a3f.3570f8",
        "order": 2,
        "width": "6",
        "height": "6",
        "label": "Biểu Đồ Gió",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "Biểu Đồ Gió",
        "dot": false,
        "ymin": "-5",
        "ymax": "10",
        "removeOlder": "2",
        "removeOlderPoints": "2000",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 830,
        "y": 40,
        "wires": [
            [
                "d8137742.96b5c"
            ]
        ]
    },
    {
        "id": "2ee5cd9c.c01b1a",
        "type": "change",
        "z": "edde96c.5e59968",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Lưu Lượng Mưa",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 550,
        "y": 420,
        "wires": [
            [
                "2f5c0ef.76a0072",
                "9889a59d.5e737"
            ]
        ]
    },
    {
        "id": "2f5c0ef.76a0072",
        "type": "ui_chart",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "2df6fcf.9ea0804",
        "order": 2,
        "width": "6",
        "height": "6",
        "label": "Biểu Đồ Dòng điện",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "linear",
        "nodata": "Biểu Đồ Lưu Lượng Mưa",
        "dot": false,
        "ymin": "0",
        "ymax": "12",
        "removeOlder": "2",
        "removeOlderPoints": "2000",
        "removeOlderUnit": "60",
        "cutout": 0,
        "useOneColor": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "useOldStyle": false,
        "outputs": 1,
        "x": 750,
        "y": 480,
        "wires": [
            [
                "659c6d2b.43b72c"
            ]
        ]
    },
    {
        "id": "a958973.76e2de8",
        "type": "change",
        "z": "edde96c.5e59968",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "Hướng Gió",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 570,
        "y": 300,
        "wires": [
            [
                "2ca49b8.92f0764",
                "82551c31.606ae",
                "bcbd9e0f.e899d8"
            ]
        ]
    },
    {
        "id": "82551c31.606ae",
        "type": "ui_gauge",
        "z": "edde96c.5e59968",
        "name": "",
        "group": "900c0194.8d7a9",
        "order": 2,
        "width": "6",
        "height": "5",
        "gtype": "compass",
        "title": "La Bàn",
        "label": "NEWS",
        "format": "{{value}}",
        "min": "0",
        "max": "16",
        "colors": [
            "#00b500",
            "#e6e600",
            "#ca3838"
        ],
        "seg1": "",
        "seg2": "",
        "x": 780,
        "y": 240,
        "wires": []
    },
    {
        "id": "bcbd9e0f.e899d8",
        "type": "function",
        "z": "edde96c.5e59968",
        "name": "Set Hướng Theo Yêu Cầu",
        "func": "var huong;\nif (msg.payload < 22) {\n    huong = \"Bắc\";\n}\nelse if (msg.payload < 67) {\n    huong = \"Đông Bắc\";\n}\nelse if (msg.payload < 112) {\n    huong = \"Đông \";\n}\nelse if (msg.payload < 157) {\n    huong = \"Đông Nam\";\n}\nelse if (msg.payload < 212) {\n    huong = \"Nam\";\n}\nelse if (msg.payload < 247) {\n    huong = \"Tây Nam\";\n}\nelse if (msg.payload < 292) {\n    huong = \"Tây\";\n}\nelse if (msg.payload < 337) {\n    huong = \"Tây Bắc\";\n}\nelse{\n        huong = \"Bắc\";\n\n}\n\nmsg.payload = huong;\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "x": 810,
        "y": 300,
        "wires": [
            [
                "21b921b0.7553ae",
                "2dac6164.a48c06"
            ]
        ]
    },
    {
        "id": "21b921b0.7553ae",
        "type": "ui_text",
        "z": "edde96c.5e59968",
        "group": "900c0194.8d7a9",
        "order": 2,
        "width": 0,
        "height": 0,
        "name": "",
        "label": "Hướng:",
        "format": "{{msg.payload}}",
        "layout": "row-center",
        "x": 1020,
        "y": 300,
        "wires": []
    },
    {
        "id": "ccb46a4a.ecdec8",
        "type": "inject",
        "z": "edde96c.5e59968",
        "name": "",
        "topic": "",
        "payload": "3",
        "payloadType": "num",
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "x": 350,
        "y": 400,
        "wires": [
            [
                "a958973.76e2de8"
            ]
        ]
    },
    {
        "id": "d8137742.96b5c",
        "type": "debug",
        "z": "edde96c.5e59968",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 1010,
        "y": 40,
        "wires": []
    },
    {
        "id": "659c6d2b.43b72c",
        "type": "debug",
        "z": "edde96c.5e59968",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 1020,
        "y": 480,
        "wires": []
    },
    {
        "id": "8eaf0349.bddf08",
        "type": "mqtt in",
        "z": "edde96c.5e59968",
        "name": "[MQTT-IN]iNut cảm biến - iNut CB",
        "topic": "request/u3h91VsxpfQv1dWncBsaaD2jQn42/HyK0c0_Er/22749716e8a9ba9272e4b71f266f555c760383618091",
        "qos": "2",
        "broker": "e8294b7d.15c56",
        "x": 170,
        "y": 360,
        "wires": [
            [
                "f398e233.c33db8"
            ]
        ]
    },
    {
        "id": "675a9f41.d1f29",
        "type": "http request",
        "z": "edde96c.5e59968",
        "name": "[REST][GET]iNut cảm biến - iNut CB",
        "method": "GET",
        "ret": "txt",
        "url": "https://connect.mysmarthome.vn/api/1.0/request/u3h91VsxpfQv1dWncBsaaD2jQn42/HyK0c0_Er/22749716e8a9ba9272e4b71f266f555c760383618091/req_device",
        "tls": "",
        "x": 610,
        "y": 620,
        "wires": [
            []
        ]
    },
    {
        "id": "3ef4c273.01e0ae",
        "type": "http request",
        "z": "edde96c.5e59968",
        "name": "[REST][POST]iNut cảm biến - iNut CB",
        "method": "POST",
        "ret": "txt",
        "url": "https://connect.mysmarthome.vn/api/1.0/request/u3h91VsxpfQv1dWncBsaaD2jQn42/HyK0c0_Er/22749716e8a9ba9272e4b71f266f555c760383618091/req_device_toggle",
        "tls": "",
        "x": 1010,
        "y": 620,
        "wires": [
            []
        ]
    },
    {
        "id": "2dac6164.a48c06",
        "type": "debug",
        "z": "edde96c.5e59968",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "x": 1000,
        "y": 360,
        "wires": []
    },
    {
        "id": "900c0194.8d7a9",
        "type": "ui_group",
        "z": "",
        "name": "DATA 3",
        "tab": "8bba984b.8fef7",
        "order": 3,
        "disp": true,
        "width": "6",
        "collapse": true
    },
    {
        "id": "ec123a3f.3570f8",
        "type": "ui_group",
        "z": "",
        "name": "DATA 1",
        "tab": "8bba984b.8fef7",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": true
    },
    {
        "id": "2df6fcf.9ea0804",
        "type": "ui_group",
        "z": "",
        "name": "DATA 2",
        "tab": "8bba984b.8fef7",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": true
    },
    {
        "id": "e8294b7d.15c56",
        "type": "mqtt-broker",
        "name": "",
        "broker": "mqtt.mysmarthome.vn",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": true,
        "keepalive": "60",
        "cleansession": true,
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": ""
    },
    {
        "id": "8bba984b.8fef7",
        "type": "ui_tab",
        "z": "",
        "name": "Thời Tiết",
        "icon": "dashboard",
        "order": 1,
        "disabled": false,
        "hidden": false
    }
]

GIAO DIỆN LÀM VIỆC

Source: https://dvn.com.vn
Category: Phụ Kiện

Alternate Text Gọi ngay