Help needed with home automation RS485 bus (Sketch)

newbie alert

Am beginning a rather complex home automation and monitoring project integrating the following:

Existing solar hot water / heating system controller
Existing Heating controls / thermostats two zones
Pellet furnace controls
Electric usage monitoring
Lighting controls

Planning to use Arduino Yun as master for mega and nano slaves for the various monitors and controls.

The first challenge is to connect the devices and get them to work together.

Contemplated using 1wire bus to connect all the devices, but instead opted for RS485 due to distance and interference problems. Will likely run a cat7 cable throughout the house to cover power to the devices, RS485 and still have two free pairs left to eventually use for 10/100 ethernet.

Using the wiring and sketch example at https://arduino-info.wikispaces.com/SoftwareSerialRS485Example I successfully got the Yun and a clone nano to ā€˜talkā€™ to each other and get the onboard led to blink properly.

Next step would be to get the Yun working again with Cayenne including the RS485 sketch, attach a couple of temp sensors and relay to the Nano and see if I can get it to show in the Cayenne consoleā€¦ any suggestions how best to proceed? Is it possible to get sensors and controls to show up in Cayenne from a remote slave device via RS485?

I had the Yun set up in Cayenne before, but of course the new RS485 sketch wiped that out. Hereā€™s what I have so farā€¦

Thanks!
Brian

RS485 is a pretty old standard (whose only saving grace is the distance it was designed to cover). Why do you not prefer WiFi or LORA wireless? Is a hard wire required?

Iā€™m using my own devices, which work wellā€¦for all my purposes (home automation, alarm and security, access control, lighting and landscape control).

Iā€™m not entirely sure Gigabit can run on only 2 pairs, soā€¦let me know how it works. Iā€™m thinking if only 2 pairs are presented to the router/switch, it will default to 10bT.

I personally wouldnā€™t run +Vcc current through communications wire (usually 24 or 26 gauge).

As an installer, I canā€™t justify the expense of CAT7, -when Cat5e is so much cheaper with the same (usable) capabilities. -just a shout from the peanut gallery! :slight_smile:

I wanted to try RS485 because of the low cost, simple hardware vs adding additional wifi coverage. Walls here are 20 plus inches of wifi killing stone. There are also rooms involved for heating and electrical systems that are outside the home in separate small buildings. Aside from that overall power considerations would be lower. A few bucks for a nano and RS485 adapter vs adding wifi shields or more expensive hardware. CAT7 might be overkill but some of the paths it would take is near power and other signal sources so would rather spend a few bucks more to stay on the safe side and not have to worry too much about getting power to the modules since it could be supplied by a pair or two if needed from a single power supply. Cost wise I think there would be little if any difference. A clone nano and RS485 adapter costs around 8 bucks. Two pairs should work for 10/100 ethernet if I ever need it, otherwise may serve as spares if any break or degrade over time.

Thanks for the feedback though! Do let me know if any of my rationalizations seem out of whack.

all sounds reasonable to me. :slight_smile:

You can run a considerable about of power even through Cat5e Power over Ethernet - Wikipedia

What kind of power levels are present in PPPOE runs? Just curious. My previous Philippines wifi service used PPPOE to power the receiver in the antenna on the roof.

William

According to wiki : Power over Ethernet - Wikipedia thanks adam! saw your post after posting this

Category 5 cable uses 24 AWG conductors, which can safely carry 360 mA at 50 V according to the latest TIA ruling.[citation needed] The cable has eight conductors (only half of which are used for power) and therefore the absolute maximum power transmitted using direct current is 50 V Ɨ 0.360 A Ɨ 2 = 36 W. Considering the voltage drop after 100 m (330 ft), a PD would be able to receive 31.6 W. The additional heat generated in the wires by PoE at this current level (4.4 W per 100 m cable) limits the total number of cables in a bundle to be 100 cables at 45 Ā°C (113 Ā°F), according to the TIA. This can be somewhat alleviated by the use of Category 6 cable which uses 23 AWG conductors.

So with Cat7 @ 23 or even 22 awg should be just fine for running a few Nanoā€™s or other Arduinoā€™s. Since each pair is shielded and another shield around that there shouldnā€™t be much heat problem running even a bit moreā€¦ Iā€™m not expecting heavy loads, just some sensors and relays. I could power each Arduino with wall warts, but would probably be nice to be able to power down / reset from a central point.

So power wise think itā€™s quite ok as extra pairs will be available if needed.

I amended the title for help with applying an Arduino sketch which is my next step. Does anyone know of any good examples out there with multiple Arduinoā€™s on RS485 with remote sensors and/or relays? Below the Master and Slave sketches that I loaded before and seemed to work. Iā€™ve googled around, but unfortunately my sketch knowledge is very limited :frowning: Any pointers or even general directions appreciated!

Master:

/* YourDuino SoftwareSerialExample1
   - Connect to another Arduino running "YD_SoftwareSerialExampleRS485_1Remote"
   - Connect this unit Pins 10, 11, Gnd
   - Pin 3 used for RS485 direction control
   - To other unit Pins 11,10, Gnd  (Cross over)
   - Open Serial Monitor, type in top window. 
   - Should see same characters echoed back from remote Arduino

   Questions: terry@yourduino.com 
*/

/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin

#define SSerialTxControl 3   //RS485 Direction control

#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("YourDuino.com SoftwareSerial remote loop example");
  Serial.println("Use Serial Monitor, type in upper window, ENTER");
  
  pinMode(Pin13LED, OUTPUT);   
  pinMode(SSerialTxControl, OUTPUT);    
  
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver   
  
  // Start the software serial port, to another device
  RS485Serial.begin(4800);   // set the data rate 

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  digitalWrite(Pin13LED, HIGH);  // Show activity
  if (Serial.available())
  {
    byteReceived = Serial.read();
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit   
    RS485Serial.write(byteReceived);          // Send byte to Remote Arduino
    
    digitalWrite(Pin13LED, LOW);  // Show activity    
    delay(10);
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit       
  }
  
  if (RS485Serial.available())  //Look for data from other Arduino
   {
    digitalWrite(Pin13LED, HIGH);  // Show activity
    byteReceived = RS485Serial.read();    // Read received byte
    Serial.write(byteReceived);        // Show on Serial Monitor
    delay(10);
    digitalWrite(Pin13LED, LOW);  // Show activity   
   }  

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

//NONE
//*********( THE END )***********

Slave / Remote:

/* YourDuino SoftwareSerialExample1Remote
   - Used with YD_SoftwareSerialExampleRS485_1 on another Arduino
   - Remote: Receive data, loop it back...
   - Connect this unit Pins 10, 11, Gnd
   - To other unit Pins 11,10, Gnd  (Cross over)
   - Pin 3 used for RS485 direction control   
   - Pin 13 LED blinks when data is received  
   
   Questions: terry@yourduino.com 
*/

/*-----( Import needed libraries )-----*/
#include <SoftwareSerial.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin

#define SSerialTxControl 3   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

#define Pin13LED         13

/*-----( Declare objects )-----*/
SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX

/*-----( Declare Variables )-----*/
int byteReceived;
int byteSend;

void setup()   /****** SETUP: RUNS ONCE ******/
{
  // Start the built-in serial port, probably to Serial Monitor
  Serial.begin(9600);
  Serial.println("SerialRemote");  // Can be ignored
  
  pinMode(Pin13LED, OUTPUT);   
  pinMode(SSerialTxControl, OUTPUT);  
  
  digitalWrite(SSerialTxControl, RS485Receive);  // Init Transceiver
  
  // Start the software serial port, to another device
  RS485Serial.begin(4800);   // set the data rate 
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  //Copy input data to output  
  if (RS485Serial.available()) 
  {
    byteSend = RS485Serial.read();   // Read the byte 
    
    digitalWrite(Pin13LED, HIGH);  // Show activity
    delay(10);              
    digitalWrite(Pin13LED, LOW);   
    
    digitalWrite(SSerialTxControl, RS485Transmit);  // Enable RS485 Transmit    
    RS485Serial.write(byteSend); // Send the byte back
    delay(10);   
    digitalWrite(SSerialTxControl, RS485Receive);  // Disable RS485 Transmit      
//    delay(100);
  }// End If RS485SerialAvailable
  
}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//NONE

//*********( THE END )***********

In the examples above from https://arduino-info.wikispaces.com/SoftwareSerialRS485Example it seems these sketches apply to two arduinoā€™s chatting with each other but I donā€™t see anything identifying how to addresses more than twoā€¦ with identifiers for each, much less read a remote sensorā€¦ Iā€™ll try to add another Nano or the Mega this evening time permitting and have a 100 meter roll of 22awg Cat7 ordered for further testingā€¦ Plenty of sensors and relays on hand :wink: Again any help with appropriate sketches appreciated! Thanks!!

Found this interesting resource Iā€™m reviewing that seems to answer some of my questions on addressing multiple Arduinoā€™s and querying sensorsā€¦ might be a good starting point if anyone wants to chip in.

Over the next few days will be doing a graphical layout of the house, device locations and RS485 bus path for reference. Iā€™ll post it here when done.

Managed to make a quick diagram. I knowā€¦ pretty ambitiousā€¦ eekā€¦ Red line is the proposed RS485 bus, can be wired pretty much as shown with existing tubing already in place. Total length around 200-250 meters. Something like 10 or 11 Arduinoā€™s spread around for dedicated tasks collecting temp, weather, electric current data and controlling switches, pumps, lights and fans. Enough to keep me tinkering around for quite a whileā€¦

1 Like

To keep me busy until Cat7 cable arrives and can start installing it, will likely start with the furnaceā€¦ Iā€™ve already played around some with the sensors involved and done some very basic sketches that work on the bench. This can run stand alone and only have a couple months left for heating so guess nothing lost trying it out first. Iā€™ll learn more about sketches along the way which will likely be helpful down the road with the bus project. Hereā€™s the basic idea:

Itā€™s a furnace that burns pellets, now using sunflower husk pellets but any will do. The challenges are:
-Efficiency - when burning efficiently, flue temps should be somewhere between 250 and 300 Celsius. Have a Max 6685 K thermocouple setup that Iā€™ve tested out and works fine for these higher tempsā€¦ Termocoppia K + modulo MAX6675 - sensore temperatura per ARDUINO - ART. CD23 | eBay Fuel and air mix can be controlled by the blower fan and feed motor that are currently manually adjusted. I plan to try out these 220 volt 4KW dimmer/motor controls Driver AC 4000W 220V - Dimmer regolatore di velocitĆ  giri - ART. CO15 | eBay I first thought about using stepper motors to turn the knob up and down but in the end itā€™s only a potentiometer so looking at replacint the pot with a digital potentiometer of the same/similar value. Iā€™m ok with soldering and electronic type stuff. Will just have to play around with the air/fuel/flue temp to find a good algorithm to try and maintain the flue temp within range when the unit is on.

-Monitoring- With the already installed flow meter, I should be able to monitor flow and in/out temperatures and use that to calculate and log thermal output BTU or KWH. The output temp DS18bB20 in the diagram will actually be inside the boiler itself and serve as both boiler and output temp since they are the same.

-Pump- The pump should only turn on when the boiler temp reaches a set temperature, usually 60 Celsius. If I can get things running as planned, I might try also regulating the pump to speed up when the boiler temp rises, and slow down when boiler temp fallsā€¦ - weā€™ll seeā€¦

-Pellet level- Iā€™m constantly forgetting to fill the damned thing up and hate getting up in the middle of the night to do soā€¦ I 've played around with the ultrasound sensor, but yet to see if it will measure up with pellets instead of my handā€¦ otherwise will have to find some other level measuring method. I guess knowing the dimensions and level, could also calculate consumption in kilograms per operating hour and also actual BTU/KWH per kilogram burned to check efficiency at different flue tempsā€¦

5 sensors
1 x 4 relays
2 motor controls (maybe 3 including future pump mod)

Can a nano handle it? Am I heading in the right direction?

Apologies if Iā€™m posting all this in the wrong section but thought this would be a good place to document my plans and get any tips/advice/critique along the wayā€¦ along with reporting what works out and what doesnā€™t.

Thanks!

There are plenty of devices being powered by PoE that draw a lot more power than an Arduino + sensors. Is this poor design too? Cisco Video Surveillance 6620 and 6630 IP Cameras Data Sheet - Cisco

Very kewl! :slight_smile: For you, Brian-
RS485 can be made star topography- kind ofā€¦

Ah! I see now that you will run RS485 2-pair wires through Cat7 cable, using RJ45 connectors? I understand nowā€¦and perhaps use the (2) spare pairs to carry +Vcc? Well, you may need a couple ā€œvoltage boostā€ power supplies every 50 linear foot of wire. Thatā€™s kind of a lot of devices you propose to put on that bus.

1 Like

Hi Bill!
Thanks for that resource :slight_smile: The loopbacks are a bit exaggerated on the diagram with the only long loopback going to the roof and back for the collector temperature and possible weather station, really only need outside temp to control the heating temp sent to the radiators in the house via an automatic 3 way valve. I could try and use the K thermocouple or even a PT1000 and adjust the line resistance factors to the thermocouple (iā€™ve seen a couple sketches that do this). This loopback is only 20 meters or so in total so weā€™ll see. Yes, adding it all up I might have to use some of those 3 extra pairs to beef things up a bit or use an occasional wall wart. Iā€™ll keep track of the loads etc as the system grows and adapt from there. Already decided to go with 22AWG Cat7 instead of 23AWG thanks to your constructive critique. One of the reasons for trying this ā€˜my wayā€™ is that I have a 3kw online sinewave UPS system in the office already as short power outages are fairly frequent here. I really donā€™t need the ethernet capability as most of the house and some of the outside area is wired anyway, so really have three 22awg pairs available for powerā€¦ 100 meters of cable is on the way so will be able to do some testing and measurements next week as time permits. Iā€™ll let ya know when I have some more data. Again Thanks!

Update

My main challenge was the distance from remote sensors beyond normal 1wire range. I ran across this product that should allow more centralized sensing and control without the need for multiple arduinoā€™s thus requiring multiple arduinoā€™s that would talk on a bus to relay the temp/sensor values.

http://www.ebay.it/itm/RESOLino-Pt1000-Shield-Arduino-Erweiterungsplatine-/122526426439

GitHub - resol-de/RESOLino_Pt1000: An Arduino library and shield firmware to measure Pt1000 temperature sensors using RESOL's shield. should soon be updated with a 16 channel example sketch.

Itā€™s an 8 channel Pt100, Pt1000, KTY, NTC or PTC shield. Since my current solar/heating controller uses PT1000 should work out well without having to put new sensors and wiring everywhere. According to the vendor two boards can be used for 16 channels that would cover all my temp sensor needs making the installation much more simple.

My current system also controls the speed of the pump to the solar and pellet heater to achieve max temp from these circuits, slowing down when sun is lower and speeding up in full sunlight. Iā€™ve seen PWM control of 220V motors is a bit tricky so am looking at these pumps that should be able to be controlled directly by PWM http://www.grundfos.com/products/find-product/upm3-solar.html


datasheet https://net.grundfos.com/Appl/ccmsservices/public/literature/filedata/Grundfosliterature-5439390.pdf

Iā€™ll be working on this through the summer so will update as things progress, but thought Iā€™d drop this info in for others doing similar projects.

As always constructive critique and suggestions appreciated!

1 Like

Very nice! Canā€™t wait to see a project post for this!