IMT3 Environmental Monitoring Pt.3

In this part we’ll look at the Node-RED flow that controls the Arduino with a 4-Relay Shield attached. As previously mentioned, these relays are used to allow us to remotely reset the All Sky Camera and HiTechAstro Wx STn, which we found had a tendency to hang and wouldn’t reset unless the USB connection was broken and remade. As we would not be in a position to unplug and re-plug the USB connections I came up with a solution. By modified some short USB extension cables and breaking into the +5v line I could then connect to the ‘Normally Closed’ contacts of one of the relays, picking the relay effectively turns off the USB device connected to that cable.

Relay Shield that attaches directly to an Arduino UNO

Modified USB extension cable
Snapshot of the flow to control the relays to reset ASC and Wx Stn

For this solution, we don’t write any code for the Arduino but do load it with Standard Firmata code that comes with the Arduino IDE.

Just open a new sketch, select the StandardFirmata from the Examples and upload to the Arduino.

Firmata is a generic protocol for communicating with microcontrollers from software on a host computer. It is intended to work with any host computer software package.

If not done already we need to go to npm and install the node-red-node-arduino nodes.

Originally I used a Dashboard Switch to select each relay, but it can get confusing when turning on the relay turns off the device attached, so I replaced the Switch with a Button node, pass the message to a Trigger node that will activate for 7 seconds (give the OS time to recognize the USB device has been disconnected), debounce the signal before passing onto the Arduino Output node which connects to the local Arduino and writes to the selected digital pin turning the relevant Relay On.

As there are only a few basic nodes in this flow, here are some snapshots of how each is set-up:

This button will appear on the Dashboard under the Reset Controls group

7 seconds seems long enough but can easily be changed.

Off Button

On Button

debounce the signal
debug options
Pin 7 drives the appropriate relay

So the above covers the two relays that are used to reset the All Sky Camera and HiTechAsto Wx Stn. The same building blocks are used to control a pair of battery power LED worklights to provide illumination for the Web Cameras we have dotted around the dome and on the mount. After inadvertently leaving the lights on, on one occasion, the batteries needed to be replaced after a single use. So now in addition to having switches control the lights, we also have Buttons to push for preset times on of 1, 3, 7 or 10 minutes, with an option to turn them off early.

LED lighting control

Unlit dome

Picture-in-Picture
Flip-Flat Closed
Just a couple of counter-weights
Will the last one out please turn off the lights

Wrapping up for today

Here’s the Node-RED flow for the Relay Shield

[{"id":"f126d47c.2ee7f8","type":"tab","label":"Keyestudio 4Relay Shield","disabled":false,"info":""},{"id":"56ffe7a5.6b85f8","type":"comment","z":"f126d47c.2ee7f8","name":"Arduino with keystudio 4 relay shield on /dev/tty.usbmodem144301","info":"Bob T - 28July2019\n\nKeyestudio 4 card shield to control LED lights, \nHiTechAstroDeluxe weather station and \nZWO ASI120MC All Sky Camera \n\nBosch BME280 and Dallas DS18B20 displays on the Dashboard","x":440,"y":60,"wires":[]},{"id":"2e774dcf.e58aa2","type":"inject","z":"f126d47c.2ee7f8","name":"Off","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":125,"y":233,"wires":[["303f7492.3f85ec"]]},{"id":"303f7492.3f85ec","type":"delay","z":"f126d47c.2ee7f8","name":"de-bounce","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":310,"y":243,"wires":[["d50e09b8.fb1c18","2749f02d.7190b"]]},{"id":"84dc6735.a3c618","type":"inject","z":"f126d47c.2ee7f8","name":"On","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":125,"y":263,"wires":[["303f7492.3f85ec"]]},{"id":"5c5f0bd2.1c2534","type":"inject","z":"f126d47c.2ee7f8","name":"Off","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":463,"wires":[["f88adc8a.2c784"]]},{"id":"d7751e20.14c83","type":"inject","z":"f126d47c.2ee7f8","name":"On","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":493,"wires":[["f88adc8a.2c784"]]},{"id":"d59eb4bd.942ae8","type":"inject","z":"f126d47c.2ee7f8","name":"Off","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":615,"wires":[["2743f87.650a908"]]},{"id":"c1c23f86.91668","type":"inject","z":"f126d47c.2ee7f8","name":"On","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":645,"wires":[["2743f87.650a908"]]},{"id":"84553f20.8f26c","type":"inject","z":"f126d47c.2ee7f8","name":"Off","topic":"","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":840,"wires":[["35bc3b9f.4f8f94"]]},{"id":"39cd3cf9.7a7024","type":"inject","z":"f126d47c.2ee7f8","name":"On","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":870,"wires":[["35bc3b9f.4f8f94"]]},{"id":"f88adc8a.2c784","type":"delay","z":"f126d47c.2ee7f8","name":"de-bounce","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":315,"y":478,"wires":[["f55deca6.8236f","ec02039f.f8b64"]]},{"id":"2743f87.650a908","type":"delay","z":"f126d47c.2ee7f8","name":"de-bounce","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":520,"y":630,"wires":[["9f8d9580.1d3348"]]},{"id":"35bc3b9f.4f8f94","type":"delay","z":"f126d47c.2ee7f8","name":"de-bounce","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":520,"y":855,"wires":[["b44e31bd.88ac2"]]},{"id":"2749f02d.7190b","type":"debug","z":"f126d47c.2ee7f8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":650,"y":218,"wires":[]},{"id":"ec02039f.f8b64","type":"debug","z":"f126d47c.2ee7f8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":550,"y":428,"wires":[]},{"id":"a5a681c5.89e44","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"num","op2type":"str","duration":"7","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":345,"y":158,"wires":[["d0ab65b2.542c38","303f7492.3f85ec"]]},{"id":"d0ab65b2.542c38","type":"debug","z":"f126d47c.2ee7f8","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","x":640,"y":158,"wires":[]},{"id":"af46adb4.e7a03","type":"inject","z":"f126d47c.2ee7f8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":125,"y":158,"wires":[["a5a681c5.89e44"]]},{"id":"688bcc2f.63ec14","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"7","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":315,"y":360,"wires":[["f88adc8a.2c784"]]},{"id":"ab716ad9.cd6008","type":"inject","z":"f126d47c.2ee7f8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":125,"y":390,"wires":[["688bcc2f.63ec14"]]},{"id":"5a6fb133.d07c7","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"10","extend":false,"units":"min","reset":"false","bytopic":"all","name":"","x":415,"y":1035,"wires":[["35bc3b9f.4f8f94","2743f87.650a908"]]},{"id":"d50e09b8.fb1c18","type":"arduino out","z":"f126d47c.2ee7f8","name":"ZWO ASI120MC USB reset","pin":"7","state":"OUTPUT","arduino":"ae78048.c81a0f8","x":585,"y":285,"wires":[]},{"id":"f55deca6.8236f","type":"arduino out","z":"f126d47c.2ee7f8","name":"HiTechAstro Deluxe Wx Stn reset","pin":"6","state":"OUTPUT","arduino":"ae78048.c81a0f8","x":610,"y":478,"wires":[]},{"id":"9f8d9580.1d3348","type":"arduino out","z":"f126d47c.2ee7f8","name":"West LED lighting","pin":"5","state":"OUTPUT","arduino":"ae78048.c81a0f8","x":705,"y":630,"wires":[]},{"id":"b44e31bd.88ac2","type":"arduino out","z":"f126d47c.2ee7f8","name":"East LED lighting","pin":"4","state":"OUTPUT","arduino":"ae78048.c81a0f8","x":705,"y":855,"wires":[]},{"id":"d111e9f5.d3a008","type":"ui_switch","z":"f126d47c.2ee7f8","name":"Switch Relay4","label":"Switch East LED Lights on","tooltip":"","group":"4486153f.db803c","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":120,"y":930,"wires":[["35bc3b9f.4f8f94"]]},{"id":"1ed486f7.f803b9","type":"ui_switch","z":"f126d47c.2ee7f8","name":"Switch Relay3","label":"Switch West LED Lights on","tooltip":"","group":"4486153f.db803c","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":125,"y":690,"wires":[["2743f87.650a908"]]},{"id":"4cfa9507.32412c","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"207b2faf.303c7","order":1,"width":0,"height":0,"passthru":false,"label":"Reset ZWO ASI120MC","tooltip":"Press to reset camera, power will be turned off for 7 seconds","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":170,"y":113,"wires":[["a5a681c5.89e44"]]},{"id":"334aa4c3.95f1bc","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"207b2faf.303c7","order":1,"width":0,"height":0,"passthru":false,"label":"Reset  Wx Stn","tooltip":"Press to reset Weather Station, power is removed for 7 seconds","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":140,"y":338,"wires":[["688bcc2f.63ec14"]]},{"id":"dce61d46.cf408","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":6,"width":0,"height":0,"passthru":false,"label":"White LEDs on 10 min Timer","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":155,"y":987,"wires":[["5a6fb133.d07c7"]]},{"id":"1e8859e3.2aa6a6","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":4,"width":0,"height":0,"passthru":false,"label":"White LEDs on 3 min Timer","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":160,"y":780,"wires":[["88932bbe.119258"]]},{"id":"88932bbe.119258","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"3","extend":false,"units":"min","reset":"false","bytopic":"all","name":"","x":415,"y":780,"wires":[["2743f87.650a908","35bc3b9f.4f8f94"]]},{"id":"ab204ac6.07c528","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":5,"width":0,"height":0,"passthru":false,"label":"White LEDs on 7 min Timer","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":150,"y":1035,"wires":[["d37c1fc3.44ece"]]},{"id":"d37c1fc3.44ece","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"7","extend":true,"units":"min","reset":"false","bytopic":"all","name":"","x":415,"y":990,"wires":[["35bc3b9f.4f8f94","2743f87.650a908"]]},{"id":"9ec5abcd.94bff8","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":3,"width":0,"height":0,"passthru":false,"label":"White LEDs on 1 min Timer","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":160,"y":740,"wires":[["871ac8c.880b438"]]},{"id":"871ac8c.880b438","type":"trigger","z":"f126d47c.2ee7f8","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"1","extend":false,"units":"min","reset":"false","bytopic":"all","name":"","x":415,"y":735,"wires":[["35bc3b9f.4f8f94","2743f87.650a908"]]},{"id":"9b4c5ff.75b30a","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":6,"width":0,"height":0,"passthru":false,"label":"Turn Off All Lights","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":120,"y":1080,"wires":[["eb116cf.e91769"]]},{"id":"eb116cf.e91769","type":"trigger","z":"f126d47c.2ee7f8","op1":"0","op2":"false","op1type":"str","op2type":"bool","duration":"250","extend":false,"units":"ms","reset":"","bytopic":"all","name":"Reset Lights","x":355,"y":1095,"wires":[["d37c1fc3.44ece","5a6fb133.d07c7","88932bbe.119258","871ac8c.880b438","35bc3b9f.4f8f94","2743f87.650a908"]]},{"id":"9fd74bd7.3fd648","type":"ui_button","z":"f126d47c.2ee7f8","name":"","group":"4486153f.db803c","order":7,"width":0,"height":0,"passthru":true,"label":"Don't Push this button","tooltip":"","color":"","bgcolor":"","icon":"","payload":"true","payloadType":"bool","topic":"","x":250,"y":1290,"wires":[["2ed3e3dc.0f6cac"]]},{"id":"2ed3e3dc.0f6cac","type":"trigger","z":"f126d47c.2ee7f8","op1":"true","op2":"false","op1type":"bool","op2type":"bool","duration":"1","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":435,"y":1290,"wires":[["8af19751.a0fec8"]]},{"id":"ffabd20f.040af","type":"inject","z":"f126d47c.2ee7f8","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":80,"y":1290,"wires":[["9fd74bd7.3fd648"]]},{"id":"8af19751.a0fec8","type":"arduino out","z":"f126d47c.2ee7f8","name":"","pin":"13","state":"OUTPUT","arduino":"ae78048.c81a0f8","x":590,"y":1290,"wires":[]},{"id":"ae78048.c81a0f8","type":"arduino-board","z":"","device":"COM16"},{"id":"4486153f.db803c","type":"ui_group","z":"f126d47c.2ee7f8","name":"IMT3 - Lights","tab":"a9e9728d.77c83","order":6,"disp":true,"width":"6","collapse":true},{"id":"207b2faf.303c7","type":"ui_group","z":"","name":"Reset Controls","tab":"a9e9728d.77c83","order":7,"disp":true,"width":"6","collapse":true},{"id":"a9e9728d.77c83","type":"ui_tab","z":"f126d47c.2ee7f8","name":"IMT3","icon":"dashboard","order":2,"disabled":false,"hidden":false}]