The Investigation of a Low Cost DAQ with Arduino and Node Red on/off switch

Arduino code that is written on the arduino IDE. The code consists of the on/off algorithm and source codes found online for ds18b20 and thermistor sensors. This is read through the com4 port(applicable) and is fed into a node palette for either the ds18b20 or thermistor in order to plot the graph depiction of the temperature behavior of each sensor, this analyses must be done for each sensor one at a time. A simultaneous visual display does not work. The live data capturing is saved as a csv format on a specified folder that the user must create

[{"id":"834374e6.7cfef8","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"d1c5ea59.cd2e88","type":"comment","z":"834374e6.7cfef8","name":"Notes","info":"This system will record data from the analog channels\non the board of choice (Arduino in this case), \ncombine it into a single data stream and save it\nto text file in a csv format.\n\nIts intent is for the logging of temperature\ndata in research settings, where CSV stored \ninformation is common practice to ease importing \ninto subsequent software used for post-processing \nand detailed analysis such as MATLAB or Python.\n\nThe intent is also that the temperature node can\nbe copied and reused as additional temperature\nchannels are used, with subsequent minimal \nmodification of the downstream nodes.\n","x":1166,"y":225,"wires":[]},{"id":"9334d199.4cdf","type":"debug","z":"834374e6.7cfef8","name":"","active":false,"console":"false","complete":"payload","x":1074,"y":514,"wires":[]},{"id":"40cbf0fc.9ec","type":"file","z":"834374e6.7cfef8","name":"Save to Text File","filename":"C:\\Users\\Thomas\\Desktop\\nodejs node red arduino ssr\\don\\temp","appendNewline":true,"createDir":false,"overwriteFile":"false","x":1285,"y":427,"wires":[]},{"id":"cac927c9.a492e8","type":"inject","z":"834374e6.7cfef8","name":"Timestamp (10sec)","topic":"timestamp","payload":"","payloadType":"date","repeat":"10","crontab":"","once":true,"x":240,"y":444,"wires":[["4c77708.b66c19","c06671e0.2eb36","ef71616.d5abfa"]]},{"id":"50837353.80bf1c","type":"template","z":"834374e6.7cfef8","name":"Convert to CSV","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload.timestamp}} , {{payload.sensor1}} , {{payload.sensor2}};","x":1065,"y":380,"wires":[["40cbf0fc.9ec","3dffbf93.aee62"]]},{"id":"4c77708.b66c19","type":"function","z":"834374e6.7cfef8","name":"timeConvert","func":"//create date object from timestamp injected in\nvar dt = new Date(msg.payload); \n\n\n//Create timestamp with only the time, no date, information\nmsg.payload = {\n    timestamp: dt.getHours() + ':' + \ndt.getMinutes() + ':' + dt.getSeconds()\n}\n\n//Get the month information out\nvar month = dt.getMonth() + 1;  \n\n//Create Filename that data will be saved to\nmsg.filename = dt.getFullYear() + '_' + month \n+ '_' + dt.getDate() + \n'_tempLog.txt';\n\n//Convert log name to string - required for saveFile node\nmsg.filename = msg.filename.toString();\n\nreturn msg;","outputs":1,"noerr":0,"x":499,"y":441,"wires":[["53328342.60319c","83907e4f.14b57"]]},{"id":"53328342.60319c","type":"function","z":"834374e6.7cfef8","name":"Join Data Streams","func":"/*\nThis file is based on the flow supplied at \nhttp://flows.nodered.org/flow/8ba7f90f3ea8d92b1e01\nby mharizanov\n\nAll sensors that you have added will need to\nto be added to the code below\n\n*/\ncontext.data = context.data || new Object();\n\n//Add all\n//Wait for information and store it when it comes\nswitch (msg.topic) {\n    case \"sensor1\":\n        context.data.sensor1 = msg.payload;\n        msg = null;\n        break;\n    case \"sensor2\":\n        context.data.sensor2 = msg.payload;\n        msg = null;\n        break;\n    case \"timestamp\":\n        context.data.timestamp = msg.payload.timestamp;\n        context.filename = msg.filename;\n        msg = null;\n        break;\n        \n    default:\n        msg = null;\n    \tbreak;\n}\n\n//When all the data bins are filled, send out the information in one clump\nif(context.data.sensor1 != null && context.data.sensor2 != null && context.data.timestamp != null) {\n    msg = new Object();\n    msg.payload = context.data;\n    msg.filename = context.filename;\n    context.data=null;\n\treturn msg;\n\t\n} else return null; //msg;\n\n\n\n\n\n\n\n","outputs":1,"noerr":0,"x":836,"y":360,"wires":[["50837353.80bf1c","9334d199.4cdf"]]},{"id":"87a7246e.1c59a8","type":"debug","z":"834374e6.7cfef8","name":"","active":true,"console":"false","complete":"false","x":854,"y":244,"wires":[]},{"id":"3dffbf93.aee62","type":"debug","z":"834374e6.7cfef8","name":"","active":true,"console":"false","complete":"false","x":1283,"y":352,"wires":[]},{"id":"c06671e0.2eb36","type":"function","z":"834374e6.7cfef8","name":"Temperature Thermistor Sensor1","func":"//Access the sensors you wish to use\nsensorName = \"sensor1\";\nvar sensor = global.get(sensorName);\n\n//Create variables\nvar T;\nvar R;\nvar analogueOut = 0;  //analogue out\n\n// Steinhart-Hart B parameter Equation variables\n//these values are far from the standard and were fitted using an excel sheet\nvar B = 3434;\nvar T0 = 298.15;\nvar rPass = 9.64; //resitance of passive resitor in kOhm\nvar rThermistor = 9.2; //resistance of thermistor at room temperature in kOhm\n\n//Take readings\nanalogueOut =  sensor.scaleTo(0, 1023); //read sensor info, scale to value between 0 and 1023\n//calculate resistance of thermistor\nR = rPass / ((1023 / analogueOut)-1); \n//calculate correspnding temperature in degC of thermistor based on resistance value using Steinhart-Hart equation\n//B parameter version of steinhart equation\nT = 1 / (1/T0 + 1/B*Math.log(R/rThermistor)) - 273.15;\n//Round Number to 2 decimals\nT = Math.round(T * 100) / 100;    \n\n//Send the information out\nnode.send({topic: sensorName , payload: T , id: '2'});  //send inforamtion out of node, attach topic to payload for identification later\n\n \n\n","outputs":1,"noerr":0,"x":556,"y":245,"wires":[["53328342.60319c","87a7246e.1c59a8"]]},{"id":"e550913e.1300c","type":"johnny5","z":"834374e6.7cfef8","name":"Initialise Sensors","func":" //Create all the sensor instances you wish\n //The j5 node is only run once, thus there is no\n //chance of multiple instances being created.\n var sensorA4 = new five.Sensor({\n    pin: \"A4\",\n      });     //read in values from sensor\n var sensorA5 = new five.Sensor({\n    pin: \"A5\",\n      });     //read in values from sensor\n         \n//make sensors available across all function nodes\nglobal.set(\"sensor1\" , sensorA4);  // this is now available to other nodes\nglobal.set(\"sensor2\" , sensorA5);  // this is now available to other nodes","board":"f6259cee.ab8b8","noerr":0,"x":266,"y":245,"wires":[["c06671e0.2eb36","ef71616.d5abfa"]]},{"id":"ef71616.d5abfa","type":"function","z":"834374e6.7cfef8","name":"Temperature Thermistor Sensor2","func":"//Access the sensors you wish to use\nsensorName = \"sensor2\";\nvar sensor = global.get(sensorName);\n\n\n//Create variables\nvar T;\nvar R;\nvar analogueOut = 0;  //analogue out\n\n// Steinhart-Hart B parameter Equation variables\n//these values are far from the standard and were fitted using an excel sheet\nvar B = 3434;\nvar T0 = 298.15;\nvar rPass = 9.64; //resitance of passive resitor in kOhm\nvar rThermistor = 9.2; //resistance of thermistor at room temperature in kOhm\n\n//Take readings\nanalogueOut =  sensor.scaleTo(0, 1023); //read sensor info, scale to value between 0 and 1023\n//calculate resistance of thermistor\nR = rPass / ((1023 / analogueOut)-1); \n//calculate correspnding temperature in degC of thermistor based on resistance value using Steinhart-Hart equation\n//B parameter version of steinhart equation\nT = 1 / (1/T0 + 1/B*Math.log(R/rThermistor)) - 273.15;\n//Round Number to 2 decimals\nT = Math.round(T * 100) / 100;    \n\n//Send the information out\nnode.send({topic: sensorName , payload: T , id: '2'});  //send inforamtion out of node, attach topic to payload for identification later\n\n\n","outputs":1,"noerr":0,"x":556,"y":305,"wires":[["53328342.60319c","48cc624a.e59e7c"]]},{"id":"48cc624a.e59e7c","type":"debug","z":"834374e6.7cfef8","name":"","active":true,"console":"false","complete":"false","x":846,"y":305,"wires":[]},{"id":"f0baee6e.e8ad8","type":"comment","z":"834374e6.7cfef8","name":"Modification Notes","info":"The 'Join Data Dtreams' and 'Convert to CSV\" nodes need to be \nupdated with the names of the sensors actually used.\nIn this example those names are 'sensor1' and\n'sensor2', as seen in the J5 node.","x":496,"y":185,"wires":[]},{"id":"5b68008c.68b19","type":"comment","z":"834374e6.7cfef8","name":"J5 Node Connecting Notes","info":"The J5 node will not reconnect to the board after a \nchange has been made and it has been deployed.\n\nYou will have to restart node-red to allow the J5 node\nto connect.","x":266,"y":185,"wires":[]},{"id":"83907e4f.14b57","type":"debug","z":"834374e6.7cfef8","name":"","active":true,"console":"false","complete":"filename","x":786,"y":505,"wires":[]},{"id":"f6259cee.ab8b8","type":"nodebot","z":"834374e6.7cfef8","name":"COM4_port","username":"","password":"","boardType":"firmata","serialportName":"COM4","connectionType":"local","mqttServer":"","socketServer":"","pubTopic":"","subTopic":"","tcpHost":"","tcpPort":"","sparkId":"","sparkToken":"","beanId":"","impId":"","meshbluServer":"https://meshblu.octoblu.com","uuid":"","token":"","sendUuid":""}]

Flow Info

Created 6 years, 11 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • comment (x3)
  • debug (x5)
  • file (x1)
  • function (x4)
  • inject (x1)
  • template (x1)
Other
  • johnny5 (x1)
  • nodebot (x1)
  • tab (x1)

Tags

  • serialport
  • thermistor
  • firmata
  • steinhart-hart
  • johnny5
  • arduino
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option