Here is my circuit and NodeRed flow to control a 12v cooling fan for the RPi
My Pi is used in a fairly high ambient temperature so a little cooling might be required in summer
(I actually solved the problem that was causing my Pi to overheat but Id put together the cooling controller so I went ahead and installed it anyway )
Circuit diagram
NodeRed flow
NodeRed code
My Pi is used in a fairly high ambient temperature so a little cooling might be required in summer
(I actually solved the problem that was causing my Pi to overheat but Id put together the cooling controller so I went ahead and installed it anyway )
Circuit diagram
NodeRed flow
NodeRed code
Code:
[{"id":"1189fc4b.908fa4","type":"ui_switch","z":"9793012f.3afaf","name":"Fan Override","label":"Fan switch","group":"693e1549.6d363c","order":0,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"1","onvalueType":"num","onicon":"","oncolor":"","offvalue":"0","offvalueType":"num","officon":"","offcolor":"","x":510,"y":1220,"wires":[["dfb0d3e9.3b755"]]},{"id":"dfb0d3e9.3b755","type":"rpi-gpio out","z":"9793012f.3afaf","name":"Fan control on GPIO18","pin":"12","set":true,"level":"0","freq":"","out":"out","x":850,"y":1260,"wires":[]},{"id":"234b0bca.01bb54","type":"function","z":"9793012f.3afaf","name":"CPU Fan threshold","func":"str = msg.payload;\nmsg.payload = str.substring(5,9);\nmsg.payload = Number(msg.payload);\nif(msg.payload >65) msg.payload = 1;\nelse if(msg.payload <=65) msg.payload = 0;\nreturn msg;","outputs":1,"noerr":0,"x":530,"y":1320,"wires":[["dfb0d3e9.3b755"]]},{"id":"32c875db.e8e48a","type":"exec","z":"9793012f.3afaf","command":"vcgencmd measure_temp","addpay":false,"append":"","useSpawn":"","timer":"","oldrc":false,"name":"RPi Temp.","x":330,"y":1320,"wires":[["234b0bca.01bb54","cc33579b.e30ba8"],[],[]]},{"id":"cc33579b.e30ba8","type":"function","z":"9793012f.3afaf","name":"CPU Temp","func":"str = msg.payload\nmsg.payload = str.substring(5,9);\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":1360,"wires":[["e8101264.ed32e","318c3d17.88c2d2"]]},{"id":"504fcc1f.10ed74","type":"inject","z":"9793012f.3afaf","name":"","topic":"","payload":"","payloadType":"date","repeat":"10","crontab":"","once":false,"x":124.5,"y":1328.25,"wires":[["32c875db.e8e48a"]]},{"id":"e8101264.ed32e","type":"ui_gauge","z":"9793012f.3afaf","name":"","group":"3067d01a.af5d4","order":2,"width":0,"height":0,"gtype":"gage","title":"CPU Temperature","label":"C","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"x":830,"y":1360,"wires":[]},{"id":"318c3d17.88c2d2","type":"ui_chart","z":"9793012f.3afaf","name":"","group":"2381998f.63b6d6","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","ymin":"","ymax":"","removeOlder":"3","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"x":830,"y":1400,"wires":[[],[]]},{"id":"693e1549.6d363c","type":"ui_group","z":"","name":"Col3","tab":"7ae3bc3.4c07544","order":3,"disp":false,"width":"3"},{"id":"3067d01a.af5d4","type":"ui_group","z":"","name":"Col1","tab":"7ae3bc3.4c07544","order":1,"disp":false,"width":"3"},{"id":"2381998f.63b6d6","type":"ui_group","z":"","name":"Temp Chart","tab":"8b537ae0.9e5938","disp":true,"width":"10"},{"id":"7ae3bc3.4c07544","type":"ui_tab","z":"","name":"RPi Control","icon":"dashboard","order":4},{"id":"8b537ae0.9e5938","type":"ui_tab","z":"","name":"CPU Temp","icon":"dashboard","order":5}]