# 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

[
{
"id": "ee91b877.3dd5f8",
"type": "debug",
"z": "d38741fb.c23a7",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 210,
"y": 380,
"wires": []
},
{
"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",
"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",
"bcm": true,
"x": 140,
"y": 580,
"wires": [
[
"76d7d4cd0cba4a84"
]
]
},
{
"id": "ef7d3bb.7297fc8",
"type": "function",
"z": "d38741fb.c23a7",
"name": "",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 460,
"y": 440,
"wires": [
[
"1783087423be467b",
"99061d15c416d07f",
]
]
},
{
"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": "",
"topic": "topic",
"topicType": "msg",
"x": 210,
"y": 760,
"wires": [
[
"810c2d24.154ce"
]
]
},
{
"id": "810c2d24.154ce",
"type": "function",
"z": "d38741fb.c23a7",
"name": "Flush",
"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": "",
"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"
]
]
},
{
"type": "function",
"z": "d38741fb.c23a7",
"name": "",
"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.

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": "topic",
"vt": "str"
}
],
"repeat": "0.1",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "1",
"x": 220,
"y": 240,
"wires": [
[
"858d9038b944273b"
]
]
},
{
"id": "9cbe39878713dfe1",
"type": "inject",
"z": "d4b57f82ecac12af",
"name": "3 Secondds repeater",
"props": [
{
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "3",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "2",
"x": 240,
"y": 360,
"wires": [
[
"ee5c7505260c653b"
]
]
},
{
"id": "858d9038b944273b",
"type": "switch",
"z": "d4b57f82ecac12af",
"name": "",
"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": "",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 510,
"y": 360,
"wires": [
[
"e489946e764b9425"
]
]
},
{
"type": "inject",
"z": "d4b57f82ecac12af",
"name": "Reset",
"props": [
{
},
{
"p": "speed_reset",
"v": "true",
"vt": "bool"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"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": "",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 900,
"y": 240,
"wires": [
[
"8da7d5bc508897f2"
]
]
},
{
"id": "222c4a80c6a0e568",
"type": "function",
"z": "d4b57f82ecac12af",
"name": "",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 900,
"y": 380,
"wires": [
[
"410b44f783d3c89b",
"8da7d5bc508897f2"
]
]
},
{
"id": "e2cc65c41f31cf33",
"type": "function",
"z": "d4b57f82ecac12af",
"name": "",
"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.