Skip to content

Instantly share code, notes, and snippets.

@adamaero
Created April 9, 2019 23:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamaero/9a74c7337433d482002d57c3a8bbc883 to your computer and use it in GitHub Desktop.
Save adamaero/9a74c7337433d482002d57c3a8bbc883 to your computer and use it in GitHub Desktop.
Ultrasonic range sensor for smart trash bin with AWS and an ESP8266

Two LEDS are connected to the ESP8266. When the low threshold is surpassed, then the first LED goes on if the garbage goes that high (less than). When the high threshold is surpassed, then the second LED goes on, and the bin is completely full.

[{"id":"9581a256.f967c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"f9100a08.56d2d8","type":"mqtt in","z":"9581a256.f967c","name":"","topic":"voltage/#","qos":"0","datatype":"auto","broker":"ca490a2e.b63e58","x":140,"y":80,"wires":[["bfee19ad.124178"]]},{"id":"baf531b3.6059c","type":"ui_gauge","z":"9581a256.f967c","name":"","group":"bf1821a8.c694e","order":3,"width":"0","height":"0","gtype":"wave","title":"Bin","label":" gal.","format":"{{value}}","min":0,"max":"20","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":290,"y":360,"wires":[],"info":"#00ff00"},{"id":"d700faa9.ee5758","type":"mosca in","z":"9581a256.f967c","mqtt_port":1883,"mqtt_ws_port":8080,"name":"","username":"ajusurvey","password":"123klASDF","dburl":"","x":150,"y":40,"wires":[[]]},{"id":"34c97bcd.f2e1a4","type":"debug","z":"9581a256.f967c","name":"raw","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":150,"y":140,"wires":[]},{"id":"7ba32fb1.92b24","type":"function","z":"9581a256.f967c","name":"voltage to inches","func":"const mul = 16.8;\nconst add = 8.54;\n\n//msg.payload = parseInt(msg.payload);\n\nmsg.payload = msg.payload*mul + add;\n\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":220,"wires":[["97b49a28.68c208","d80d22fd.77726","42938a30.47b174"]]},{"id":"97b49a28.68c208","type":"function","z":"9581a256.f967c","name":"capacity","func":"const pih = -314.1592653589793;\nconst pls = 7854;\nconst div = 231;\n\nmsg.payload = (msg.payload*pih+pls)/div;\n\nreturn msg;","outputs":1,"noerr":0,"x":120,"y":360,"wires":[["29654962.a116f6"]]},{"id":"2437ebe8.21d3f4","type":"ui_text","z":"9581a256.f967c","group":"bf1821a8.c694e","order":1,"width":0,"height":0,"name":"","label":"Smart Bin: Capacity","format":"","layout":"col-center","x":380,"y":40,"wires":[]},{"id":"29654962.a116f6","type":"ui_gauge","z":"9581a256.f967c","name":"","group":"bf1821a8.c694e","order":4,"width":0,"height":0,"gtype":"gage","title":"Inches full","label":" inches","format":"{{inches}}","min":0,"max":"20","colors":["#00bf00","#ffff00","#ff0000"],"seg1":"","seg2":"","x":140,"y":420,"wires":[]},{"id":"d80d22fd.77726","type":"ui_chart","z":"9581a256.f967c","name":"","group":"bf1821a8.c694e","order":2,"width":0,"height":0,"label":"Real-Time","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"25","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"outputs":1,"x":330,"y":420,"wires":[[]]},{"id":"b97090c4.82238","type":"function","z":"9581a256.f967c","name":"Everything","func":"var lo_thres = context.get('lowpointSet') || 0;\nvar hi_thres = context.get('highpointSet') || 0;\nvar begin = context.get('begin') || 0;\nvar value = context.get('voltage') || 0;\n\nif( msg.topic === 'lowpointSet')\n{\n lo_thres = msg.payload;\n\n context.set('lowpointSet', lo_thres);\n}\nelse if( msg.topic === 'highpointSet')\n\n{\n hi_thres = msg.payload;\n context.set('highpointSet', hi_thres);\n}\n\nelse if( msg.topic === 'voltage')\n{\n value = parseFloat(msg.payload);\n\n if(value < 0)\n {\n value = 0;\n }\n begin = 1;\n context.set('begin', begin);\n context.set('voltage', value);\n}\n\n \n\nvar mqtt_msg = { payload: lo_thres.toString() + \";\" + hi_thres.toString() };\nvar email_subject = \"Capacity Update\";\nvar measurement_value = {payload: value};\nvar th_debug = {payload: [lo_thres, hi_thres] };\n\nif(value < lo_thres)\n var email_msg = {topic: email_subject, payload: \"Warning: Full capacity! Low Value : \" + measurement_value.payload.toString() + '\"', begin: begin };\n\nelse if (value < hi_thres)\n var email_msg = {topic: email_subject, payload: \"Warning: Nearly filled. High Value : \" + measurement_value.payload.toString() + '\"', begin: begin };\n\nreturn [mqtt_msg, email_msg, measurement_value, th_debug];","outputs":3,"noerr":0,"x":450,"y":360,"wires":[["6f97c0b7.14464"],["e8a06686.b06ae8"],["883664c5.e09f78"]]},{"id":"6f97c0b7.14464","type":"mqtt out","z":"9581a256.f967c","name":"","topic":"MQTTtoboard","qos":"0","retain":"","broker":"ca490a2e.b63e58","x":660,"y":340,"wires":[]},{"id":"e8a06686.b06ae8","type":"delay","z":"9581a256.f967c","name":"","pauseType":"delay","timeout":"20","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":520,"y":420,"wires":[["1d1a4fb5.ac4d6"]]},{"id":"adb46194.58d57","type":"ui_slider","z":"9581a256.f967c","name":"","label":"Too full","tooltip":"","group":"bf1821a8.c694e","order":5,"width":"5","height":"1","passthru":true,"outs":"all","topic":"lowpointSet","min":".07","max":"0.23","step":".05","x":540,"y":80,"wires":[["1c09c66e.5c613a"]]},{"id":"1c09c66e.5c613a","type":"ui_numeric","z":"9581a256.f967c","name":"","label":"low thresh.","tooltip":"","group":"bf1821a8.c694e","order":6,"width":0,"height":0,"passthru":true,"topic":"lowpointSet","format":"{{value}}","min":".07","max":"0.23","step":"0.01","x":570,"y":140,"wires":[["adb46194.58d57","70fba7be.8b7888"]]},{"id":"678214c9.348a9c","type":"ui_slider","z":"9581a256.f967c","name":"","label":"Nearly full","tooltip":"","group":"bf1821a8.c694e","order":7,"width":"5","height":"1","passthru":true,"outs":"all","topic":"highpointSet","min":"0.24","max":"0.5","step":".05","x":460,"y":180,"wires":[["ef8778ed.52e7c8"]]},{"id":"ef8778ed.52e7c8","type":"ui_numeric","z":"9581a256.f967c","name":"","label":"high thresh.","tooltip":"","group":"bf1821a8.c694e","order":8,"width":0,"height":0,"passthru":true,"topic":"highpointSet","format":"{{value}}","min":"0.24","max":"0.5","step":"0.01","x":530,"y":240,"wires":[["678214c9.348a9c","c5ae4f71.72f8a"]]},{"id":"5613f2ab.ff997c","type":"inject","z":"9581a256.f967c","name":"","topic":"volts","payload":"0.08","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":360,"y":120,"wires":[["adb46194.58d57","1c09c66e.5c613a"]]},{"id":"55d28044.bbf78","type":"inject","z":"9581a256.f967c","name":"","topic":"inches","payload":"0.3","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":180,"wires":[["678214c9.348a9c","ef8778ed.52e7c8"]]},{"id":"70fba7be.8b7888","type":"change","z":"9581a256.f967c","name":"flo.low→msg.payload","rules":[{"t":"set","p":"low","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":180,"wires":[["b97090c4.82238"]]},{"id":"c5ae4f71.72f8a","type":"change","z":"9581a256.f967c","name":"flo→msg","rules":[{"t":"set","p":"high","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":280,"wires":[["b97090c4.82238"]]},{"id":"bfee19ad.124178","type":"range","z":"9581a256.f967c","minin":"30","maxin":"360","minout":"0","maxout":"1","action":"scale","round":false,"property":"payload","name":"","x":130,"y":200,"wires":[["7ba32fb1.92b24","34c97bcd.f2e1a4","8f0ac55b.2b6118"]]},{"id":"8f0ac55b.2b6118","type":"change","z":"9581a256.f967c","name":"flo→msg","rules":[{"t":"set","p":"payload","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":160,"y":260,"wires":[["b97090c4.82238","d365cf2b.0d3bf"]]},{"id":"1d1a4fb5.ac4d6","type":"e-mail","z":"9581a256.f967c","server":"smtp.gmail.com","port":"465","secure":true,"tls":false,"name":"ajusurvey@gmail.com","dname":"email","x":670,"y":440,"wires":[]},{"id":"d365cf2b.0d3bf","type":"debug","z":"9581a256.f967c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":300,"wires":[]},{"id":"883664c5.e09f78","type":"debug","z":"9581a256.f967c","name":"end","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":670,"y":400,"wires":[]},{"id":"42938a30.47b174","type":"range","z":"9581a256.f967c","minin":"8","maxin":"26","minout":"25","maxout":"0","action":"scale","round":false,"property":"payload","name":"","x":210,"y":320,"wires":[["baf531b3.6059c"]]},{"id":"ca490a2e.b63e58","type":"mqtt-broker","z":"","name":"","broker":"m16.cloudmqtt.com","port":"12131","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"bf1821a8.c694e","type":"ui_group","z":"","name":"Default","tab":"6e1e16a4.908bc8","disp":false,"width":"6","collapse":false},{"id":"6e1e16a4.908bc8","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1,"disabled":false,"hidden":false}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment