4.Relays Remote Switch Module

Description:

One main MCU managing the RFM95 module and 4 output to command 4 relays.

One 5vDC power supply driving a 3.3 v dc regulator to power the RFM95 module.

As shown in the picture above, the 1st prototype was made off an arduino uno and 4 channel ready made opto-isolated relay board.

It has later migrate to a Arduino pro mini as MCU and a home made 4 channel relay PCB without opto isolation. I remove the opto-isolation protection because the 5Vdc power supply is the same for all circuits. I is not shown on the schematic below but the output of the relay is connected to a passive fuse protection.

The relays are songle 5vdc 10A type:

and are protected with a 5A AC fuse.

The are driven by a BC547 transistor as switch with a fly back diode.

Schematic:

Libraries:

This is the list of the libraries used tn the code:

    • SPI.h Generic arduino library to communicate via SPI. Used by tthe RF95 module.

    • EEPROM.h generic arduino library to read and write to the EEPROM

  • RH_RF95.h by airspayce to communicate with the RF95 lora module

  • RHReliableDatagram.h by airspayce to make an adressable network via the RF95 library.

The code:

Check below the SolarEnergyMonitorDIVING1.ino for the source code.

At startup the state of the relays is read from the EEPROM and is apply to each relay. As for the main monitor the relay state is an integer where each bit represent on relay. Ex: RLY=3=binary 0100 the second relay is on and all the others Off.Then the code initialize the RF95 module.

In the main loop the code wait for any incoming radio packet. A ping command should be received from one of the monitors every 3 minutes. if no radio packet has arrived the last 4 minute, the MCU try to reboot the radio module.

when radio packet are received they are decoded using the protocol [FROM][TO][CDE][RLY]

FROM is the sender, TO is the receiver and can be the address of the lora module or the RH_BROADCAST_ADDRESS generic address CDE is the command to execute and RLY the payload.

If the packet is address to RH_BROADCAST_ADDRESS the module execute the command and don't reply to the sender as acknowledgement.

The available commands are:

When a specific command lie Ie:GARDENON is decoded, a mask is apply to the relay state to switch ON only the Garden relay without affecting the state of the other relays.

When a ping command is received the RLY state is compared with the one send as payload in the sender packet and if there is any difference priority is given to the relay state received from the sender. in that case if the module miss the nightOn SETRELAY command send at a fixed time it will be corrected when the next ping command will be received.

The module reply to a PING command with the PONG command followed by the last relay state.

Next:Node-RED interface>>>>>