Calculating Frequencies

Hello everyone,
Well I am a beginner with node red an programming. And I'm trying to finde ways to learn more.
I want to make a diagram for two vibration sensors input. The signal is only 1 or 0. The Signal should be continuous to measure how many beats per minute. p.s: I'm trying to measure it per second to get the one minute
The problem it starts looking good but then the signal begin to converge on each other. And It shows me another resullts. and the y axis is shown with a +60 ... I wanted to multiple it!.
flows (1).json (56.7 KB)

Welcome to the forum @YoOoS

Please see this post for how to post flows or code - How to share code or flow json

However, when posting you should only include the few nodes necessary to show the problem, not your complete system. You can do that be selecting the nodes of interest and exporting just those.

How are the vibration sensors connecting to the machine and what frequency are they?

Since you are a beginner I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour. A small investment for a lot of gain.

Thank youPreformatted text for replying @Colin

I attached the necessary nodes with message.

I watched the whole play list from the developers and from Steve Cope. Which they are really great.

The vibration sensors are connected via digital GPIO 17 and 27. As I only need to count how much beats is coming to Raspberry .

The signal for the vibration sensor will be using servo motor to hit a barrier and calculate the frequency. How ever the flow for servo is not made yet and I am just shaking the sensor :smile:

[
    {
        "id": "ee91b877.3dd5f8",
        "type": "debug",
        "z": "d38741fb.c23a7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 210,
        "y": 380,
        "wires": []
    },
    {
        "id": "f0676dd2.c2bad",
        "type": "debug",
        "z": "d38741fb.c23a7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 210,
        "y": 660,
        "wires": []
    },
    {
        "id": "9031ed1d.fe3e",
        "type": "rpi-gpio in",
        "z": "d38741fb.c23a7",
        "name": "GPIO17-pin11 White",
        "pin": "17",
        "intype": "up",
        "debounce": "150",
        "read": false,
        "bcm": true,
        "x": 210,
        "y": 440,
        "wires": [
            [
                "ee91b877.3dd5f8",
                "ef7d3bb.7297fc8"
            ]
        ]
    },
    {
        "id": "b343dba6.7792e8",
        "type": "rpi-gpio in",
        "z": "d38741fb.c23a7",
        "name": "GPIO27-pin13 Green",
        "pin": "27",
        "intype": "up",
        "debounce": "150",
        "read": false,
        "bcm": true,
        "x": 140,
        "y": 580,
        "wires": [
            [
                "f0676dd2.c2bad",
                "76d7d4cd0cba4a84"
            ]
        ]
    },
    {
        "id": "ef7d3bb.7297fc8",
        "type": "function",
        "z": "d38741fb.c23a7",
        "name": "",
        "func": "var count = flow.get('count')||0;\n\nif (msg.payload = 1){\n    \ncount +=1;\n\nmsg.payload=count;\n\nflow.set('count',count)\n\n}\n\n/*raw = msg.payload;\nif (raw ==1){\n    beat = msg.payload;\n    \n} else {\n    nobeat= msg.payload;\n}\nsignal = (beat  / 1) * 60;\n\nmsg.payload = signal;*/\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 460,
        "y": 440,
        "wires": [
            [
                "1783087423be467b",
                "99061d15c416d07f",
                "85c8bad0d7c287ba"
            ]
        ]
    },
    {
        "id": "b9136b2.2a63598",
        "type": "ui_chart",
        "z": "d38741fb.c23a7",
        "name": "",
        "group": "16973422.73256c",
        "order": 4,
        "width": 0,
        "height": 0,
        "label": "Test",
        "chartType": "line",
        "legend": "false",
        "xformat": "HH:mm:ss",
        "interpolate": "bezier",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "60",
        "removeOlderPoints": "",
        "removeOlderUnit": "1",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 910,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "45b0f10f.dc956",
        "type": "ui_button",
        "z": "d38741fb.c23a7",
        "name": "",
        "group": "16973422.73256c",
        "order": 5,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "Flush",
        "tooltip": "",
        "color": "",
        "bgcolor": "",
        "className": "",
        "icon": "",
        "payload": "timestamp",
        "payloadType": "str",
        "topic": "topic",
        "topicType": "msg",
        "x": 210,
        "y": 760,
        "wires": [
            [
                "810c2d24.154ce"
            ]
        ]
    },
    {
        "id": "810c2d24.154ce",
        "type": "function",
        "z": "d38741fb.c23a7",
        "name": "Flush",
        "func": "msg.payload = [];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 350,
        "y": 760,
        "wires": [
            [
                "b9136b2.2a63598"
            ]
        ]
    },
    {
        "id": "1783087423be467b",
        "type": "debug",
        "z": "d38741fb.c23a7",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 670,
        "y": 520,
        "wires": []
    },
    {
        "id": "76d7d4cd0cba4a84",
        "type": "function",
        "z": "d38741fb.c23a7",
        "name": "",
        "func": "var count = context.get('count')||0;\n\nif (msg.payload = 1){\n    \ncount +=1;\n\nmsg.payload=count;\n\ncontext.set('count',count)\n\n}\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 580,
        "wires": [
            [
                "b9136b2.2a63598"
            ]
        ]
    },
    {
        "id": "99061d15c416d07f",
        "type": "delay",
        "z": "d38741fb.c23a7",
        "name": "",
        "pauseType": "delay",
        "timeout": "1",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 680,
        "y": 360,
        "wires": [
            [
                "4de5341fb8118dcc"
            ]
        ]
    },
    {
        "id": "85c8bad0d7c287ba",
        "type": "function",
        "z": "d38741fb.c23a7",
        "name": "",
        "func": "raw = msg.payload;\n\nSignal = raw*60;\n\nmsg.payload = Signal;\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 800,
        "y": 460,
        "wires": [
            [
                "b9136b2.2a63598"
            ]
        ]
    },
    {
        "id": "4de5341fb8118dcc",
        "type": "function",
        "z": "d38741fb.c23a7",
        "name": "set count to 0",
        "func": "var count = flow.get('count')||0;\n\ncount = 0;\nflow.set('count', count);\n\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 420,
        "y": 320,
        "wires": [
            [
                "ef7d3bb.7297fc8"
            ]
        ]
    },
    {
        "id": "16973422.73256c",
        "type": "ui_group",
        "name": "Automatisch Group",
        "tab": "2ce8bd4a.579392",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "2ce8bd4a.579392",
        "type": "ui_tab",
        "name": "Automatisch Mode",
        "icon": "mi-show_chart",
        "order": 4,
        "disabled": false,
        "hidden": false
    }
]

Here is alittle trick with a join node, you can join as string and output on a timeout, then in your function just use the string length property.
e.g.

[{"id":"cd7fe0fa.a311f8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.3","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":250,"y":4400,"wires":[["1c81b23.518e54e"]]},{"id":"1c81b23.518e54e","type":"switch","z":"c791cbc0.84f648","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":4400,"wires":[["abea33d6.f9113"]]},{"id":"abea33d6.f9113","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"3","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":570,"y":4380,"wires":[["85c8bad0d7c287ba","1783087423be467b"]]},{"id":"85c8bad0d7c287ba","type":"function","z":"c791cbc0.84f648","name":"","func":"msg.payload = msg.payload.length* 20;\nmsg.topic = \"one\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":4400,"wires":[["b9136b2.2a63598","1783087423be467b"]]},{"id":"1783087423be467b","type":"debug","z":"c791cbc0.84f648","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":730,"y":4600,"wires":[]},{"id":"b9136b2.2a63598","type":"ui_chart","z":"c791cbc0.84f648","name":"","group":"16973422.73256c","order":4,"width":0,"height":0,"label":"Test","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"bezier","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":"60","removeOlderPoints":"","removeOlderUnit":"1","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":970,"y":4520,"wires":[[]]},{"id":"810c2d24.154ce","type":"function","z":"c791cbc0.84f648","name":"Flush","func":"msg.payload = [];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":460,"y":4560,"wires":[["b9136b2.2a63598"]]},{"id":"1a6cc1c1.5a8fd6","type":"function","z":"c791cbc0.84f648","name":"","func":"msg.payload = msg.payload.length* 60;\nmsg.topic = \"two\"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":750,"y":4460,"wires":[["b9136b2.2a63598"]]},{"id":"45b0f10f.dc956","type":"ui_button","z":"c791cbc0.84f648","name":"","group":"16973422.73256c","order":5,"width":0,"height":0,"passthru":true,"label":"Flush","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"timestamp","payloadType":"str","topic":"topic","topicType":"msg","x":300,"y":4560,"wires":[["810c2d24.154ce"]]},{"id":"eeec8e47.466e48","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"1","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":580,"y":4460,"wires":[["1a6cc1c1.5a8fd6"]]},{"id":"42c50ff5.82d07","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":4560,"wires":[["45b0f10f.dc956"]]},{"id":"769c24.7afa3bdc","type":"switch","z":"c791cbc0.84f648","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":4460,"wires":[["eeec8e47.466e48"]]},{"id":"3fe5e99f.e22276","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.4","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":250,"y":4460,"wires":[["769c24.7afa3bdc"]]},{"id":"16973422.73256c","type":"ui_group","name":"Automatisch Group","tab":"2ce8bd4a.579392","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"2ce8bd4a.579392","type":"ui_tab","name":"Automatisch Mode","icon":"mi-show_chart","order":4,"disabled":false,"hidden":false}]

Hi @YoOoS,
Perhaps you could also use the node-red-contrib-msg-speed node to measure at which rate your messages arrive. BTW I have not looked at your flow, so perhaps it cannot solve your problem...
Bart

@E1cid , @BartButenaers Thanks for replying guys
I tried a combination of both solutions and came up with the following nodes.
Sorry for my late replay but I got busy during the week.
Thank you guys for your help.

[
    {
        "id": "9666b001f57e502a",
        "type": "inject",
        "z": "d4b57f82ecac12af",
        "name": "1 Secondd repeater",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "0.1",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "1",
        "payload": "1",
        "payloadType": "str",
        "x": 220,
        "y": 240,
        "wires": [
            [
                "858d9038b944273b"
            ]
        ]
    },
    {
        "id": "9cbe39878713dfe1",
        "type": "inject",
        "z": "d4b57f82ecac12af",
        "name": "3 Secondds repeater",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "3",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "2",
        "payload": "1",
        "payloadType": "str",
        "x": 240,
        "y": 360,
        "wires": [
            [
                "ee5c7505260c653b"
            ]
        ]
    },
    {
        "id": "858d9038b944273b",
        "type": "switch",
        "z": "d4b57f82ecac12af",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 510,
        "y": 240,
        "wires": [
            [
                "dbe0a843759c1393"
            ]
        ]
    },
    {
        "id": "dbe0a843759c1393",
        "type": "msg-speed",
        "z": "d4b57f82ecac12af",
        "name": "",
        "frequency": "sec",
        "interval": 1,
        "estimation": false,
        "ignore": false,
        "pauseAtStartup": false,
        "topicDependent": false,
        "x": 710,
        "y": 240,
        "wires": [
            [
                "475bc5f2ea951b1b",
                "dc77ed05d3c5f6f5"
            ],
            []
        ]
    },
    {
        "id": "e489946e764b9425",
        "type": "msg-speed",
        "z": "d4b57f82ecac12af",
        "name": "",
        "frequency": "sec",
        "interval": "5",
        "estimation": false,
        "ignore": false,
        "pauseAtStartup": false,
        "topicDependent": false,
        "x": 710,
        "y": 360,
        "wires": [
            [
                "222c4a80c6a0e568"
            ],
            []
        ]
    },
    {
        "id": "ee5c7505260c653b",
        "type": "switch",
        "z": "d4b57f82ecac12af",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 1,
        "x": 510,
        "y": 360,
        "wires": [
            [
                "e489946e764b9425"
            ]
        ]
    },
    {
        "id": "34d636d18b291ad7",
        "type": "inject",
        "z": "d4b57f82ecac12af",
        "name": "Reset",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "speed_reset",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payloadType": "date",
        "x": 230,
        "y": 520,
        "wires": [
            [
                "dbe0a843759c1393",
                "e489946e764b9425",
                "e2cc65c41f31cf33"
            ]
        ]
    },
    {
        "id": "8da7d5bc508897f2",
        "type": "ui_chart",
        "z": "d4b57f82ecac12af",
        "name": "",
        "group": "2986bda09d7615db",
        "order": 2,
        "width": 0,
        "height": 0,
        "label": "Test chart ",
        "chartType": "line",
        "legend": "true",
        "xformat": "HH:mm:ss",
        "interpolate": "bezier",
        "nodata": "",
        "dot": false,
        "ymin": "",
        "ymax": "",
        "removeOlder": "60",
        "removeOlderPoints": "",
        "removeOlderUnit": "1",
        "cutout": 0,
        "useOneColor": false,
        "useUTC": false,
        "colors": [
            "#1f77b4",
            "#aec7e8",
            "#ff7f0e",
            "#2ca02c",
            "#98df8a",
            "#d62728",
            "#ff9896",
            "#9467bd",
            "#c5b0d5"
        ],
        "outputs": 1,
        "useDifferentColor": false,
        "className": "",
        "x": 1060,
        "y": 300,
        "wires": [
            []
        ]
    },
    {
        "id": "475bc5f2ea951b1b",
        "type": "debug",
        "z": "d4b57f82ecac12af",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 870,
        "y": 120,
        "wires": []
    },
    {
        "id": "410b44f783d3c89b",
        "type": "debug",
        "z": "d4b57f82ecac12af",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 540,
        "wires": []
    },
    {
        "id": "dc77ed05d3c5f6f5",
        "type": "function",
        "z": "d4b57f82ecac12af",
        "name": "",
        "func": "msg.payload = msg.payload*60;\nmsg.topic = \"one\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 240,
        "wires": [
            [
                "8da7d5bc508897f2"
            ]
        ]
    },
    {
        "id": "222c4a80c6a0e568",
        "type": "function",
        "z": "d4b57f82ecac12af",
        "name": "",
        "func": "msg.payload = msg.payload*60;\nmsg.topic = \"two\";\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 380,
        "wires": [
            [
                "410b44f783d3c89b",
                "8da7d5bc508897f2"
            ]
        ]
    },
    {
        "id": "e2cc65c41f31cf33",
        "type": "function",
        "z": "d4b57f82ecac12af",
        "name": "",
        "func": "msg.payload = [];\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 500,
        "y": 520,
        "wires": [
            [
                "8da7d5bc508897f2"
            ]
        ]
    },
    {
        "id": "2986bda09d7615db",
        "type": "ui_group",
        "name": "Test",
        "tab": "d06307a126c2db4f",
        "order": 2,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "d06307a126c2db4f",
        "type": "ui_tab",
        "name": "Test mode",
        "icon": "mi-show_chart",
        "order": 4,
        "disabled": false,
        "hidden": false
    }
]
1 Like

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