# Domotica in home

**URL:** <https://forum.arduino.cc/t/domotica-in-home/1102810>\
**Category:** Networking, Protocols, and Devices\
**Created:** [March 16, 2023, 2:35pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810 "2023-03-16T14:35:53Z")\
**Posts on this page:** 19\
**Page:** 2

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 19, 2023, 9:44am UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/21 "2023-03-19T09:44:48Z")

</div>

> [@Hedalen](#):
>
> for example the SN75176B how to connect that to the mega or the uno ports?

I would suggest you use one of the readily available RS485 modules, usually with a MAX485 line driver/receiver chip on it. There are a lot of existing help guides and tutorials on the web & youtube for Arduino & RS485.

> [@Hedalen](#):
>
> what is the ftdi232

If you are referring to the board above the Pi in your image, then I suspect it's simply implying that the USB-RS485 board is using one of the FTDI FT232 series of chips to handle the USB-serial interface.

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 19, 2023, 12:35pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/22 "2023-03-19T12:35:05Z")

</div>

but the mega and the uno, have the RX and TX ports onboard, so why to use other prints with it

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 19, 2023, 2:13pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/23 "2023-03-19T14:13:38Z")

</div>

> [@Hedalen](#):
>
> so why to use other prints with it

I'm not sure what you mean by this? Did you mean pins?

EDIT: When using an Arduino UNO (your image in post #20), with only one hardware serial port, it is not advisable to use that same port (ie the Tx & Rx pins) for your RS485 comms. If you were to use SoftwareSerial or AltSoftSerial to create a second serial port for your RS485 comms, then that would leave the original hardware serial port for sketch loading and debugging etc. Note the limitations of a software serial port - max baud rate of 9600 or maybe 19200 if you are lucky.

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 20, 2023, 9:10am UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/24 "2023-03-20T09:10:39Z")

</div>

sorry, with prints, i mean motherboards  
its only to make a pin from the slave high or low, so 9600 is good enough

---

<div class="post-metadata">

**Author:** ![anon57585045](https://avatars.discourse-cdn.com/v4/letter/a/ed8c4c/32.png) [@anon57585045](https://forum.arduino.cc/u/anon57585045)\
**Post date:** [March 20, 2023, 12:22pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/25 "2023-03-20T12:22:19Z")

</div>

> [@Hedalen](#):
>
> but the mega and the uno, have the RX and TX ports onboard, so why to use other prints with it

Are you referring to the RS-485 bus direction control lines?

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 20, 2023, 1:47pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/26 "2023-03-20T13:47:12Z")

</div>

> [@Hedalen](#):
>
> but the mega and the uno, have the RX and TX ports onboard, so why to use other prints with it

Ok, so if i'm understanding you now, the reason that there are other boards involved (the RS485 modules), is that you have more than 2 devices exchanging data.

For 2 devices you can simply connect board #1 TX -\> board #2 RX, and board #1 RX to board #2 TX. That would work over short distances.

Your drawing in post #20 shows 3 UNOs and a PI communicating over some as yet unknown distance using a half duplex RS485 bus. That would be a suitable hard wired way of exchanging data between devices.

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 20, 2023, 1:50pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/27 "2023-03-20T13:50:49Z")

</div>

the largest distance will be around the 30 mtrs  
in total, i want to use 7 slaves

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 20, 2023, 2:26pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/28 "2023-03-20T14:26:17Z")

</div>

No problem for RS485. I would still suggest you look at the MySensors website as a lot of the work is done for you.

> **[Building a wired RS485 sensor network | MySensors - Create your own Connected...](https://www.mysensors.org/build/rs485)**
>
> Do It Yourself, Internet of Things

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 24, 2023, 3:38pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/29 "2023-03-24T15:38:46Z")

</div>

i have found a lot on the site from [DroneBot Workshop](https://forum.dronebotworkshop.com/)  
so i got 2 arduinos talking with eachother, now working at the next problem, to send commands about ports from the master to the slave

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 27, 2023, 6:41am UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/30 "2023-03-27T06:41:02Z")

</div>

but what to change in the sketch, when i will change a port status on the master and send that to my slave

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 27, 2023, 4:16pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/31 "2023-03-27T16:16:10Z")

</div>

> [@Hedalen](#):
>
> but what to change in the sketch

What sketch? Perhaps post the sketch you are referring to.

> [@Hedalen](#):
>
> when i will change a port status on the master

I'm not sure I understand your terminology here. From my limited use of another home automation package called Domoticz, there is the fancy PC application front end (I think that is referred to as the controller), there is the interface device between the PC application and your slaves (I think that is referred to as the gateway - perhaps this is your mega?), and then there are your slaves (your UNOs?).

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 27, 2023, 4:23pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/32 "2023-03-27T16:23:57Z")

</div>

by means of a push button on the master, the master should give a command to one of the slaves, which should make a pin high or low on a slave ( mega or uno )  
maybe, i can find out by myself, to what slave the master will send the commando.

this is the sketch for the slave

```arduino
type or paste code here

```

/\*  
I2C Slave Control Demo  
i2c-slave-demo-control.ino  
Demonstrate use of I2C bus  
Receives potentimeter position data  
Controls LED blink rate  
DroneBot Workshop 2019  
[https://dronebotworkshop.com](https://dronebotworkshop.com)  
\*/

// Include Arduino Wire library for I2C  
#include \<Wire.h\>

// Define Slave I2C Address  
#define SLAVE\_ADDR 8

// Define LED Pin  
int LED = 13;

// Variable for received data  
int rd;

// Variable for blink rate  
int br;

void setup() {

pinMode(LED, OUTPUT);

// Initialize I2C communications as Slave  
Wire.begin(SLAVE\_ADDR);

// Function to run when data received from master  
Wire.onReceive(receiveEvent);

// Setup Serial Monitor  
Serial.begin(9600);  
Serial.println("I2C Slave Demonstration");  
}

void receiveEvent() {  
// read one character from the I2C  
rd = Wire.read();  
// Print value of incoming data  
Serial.println(rd);

}  
void loop() {  
delay(50);

// Calculate blink value  
br = map(rd, 1, 255, 100, 2000);

digitalWrite(LED, HIGH);  
delay(br);  
digitalWrite(LED, LOW);  
delay(br);

}

`> Blockquote`

this for the master

> Blockquote  
> /\*  
> I2C Master Control Demo  
> i2c-master-demo-control.ino  
> Demonstrate use of I2C bus  
> Master sends potentimeter position data  
> DroneBot Workshop 2019  
> [https://dronebotworkshop.com](https://dronebotworkshop.com)  
> \*/

// Include Arduino Wire library for I2C  
#include \<Wire.h\>

// Define Slave I2C Address  
#define SLAVE\_ADDR 8

// Analog pin for potentiometer  
int analogPin = 0;  
// Integer to hold potentiometer value  
int val = 0;

void setup() {

// Initialize I2C communications as Master  
Wire.begin();

}

void loop() {  
delay(50);

// Read pot value  
// Map to range of 1-255 for flash rate  
val = map(analogRead(analogPin), 0, 1023, 255, 1);

// Write a charatre to the Slave  
Wire.beginTransmission(SLAVE\_ADDR);  
Wire.write(val);  
Wire.endTransmission();

}

> Blockquote

`

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 27, 2023, 4:33pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/33 "2023-03-27T16:33:57Z")

</div>

So you have one master Arduino (an UNO or a Mega) and several slave Arduinos (which can also be UNOs or Megas). These are all linked together by a half-duplex RS485 link?

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 27, 2023, 4:45pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/34 "2023-03-27T16:45:25Z")

</div>

the master is a mega  
they are linked bij the sda and the scl ports

---

<div class="post-metadata">

**Author:** ![markd833](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/markd833/32/1186928_2.png) [@markd833](https://forum.arduino.cc/u/markd833)\
**Post date:** [March 27, 2023, 4:58pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/35 "2023-03-27T16:58:12Z")

</div>

Ah, you've switched to using I2C as your method of communication.

A couple of comments on your slave code off the top of my head:

1. I think that receiveEvent is called as part of interrupt handling so you shouldn't print inside that function.
2. You might want to declare the variable rd as volatile.

I'm confused. You talk about a pushbutton, but your code for the "master" is reading an analogue value from the A0 pin. It appears that one sketch reads the position of the potentiometer, sends it over the I2C bus to a second sketch which varies the rate at which an LED flashes.

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [March 27, 2023, 5:03pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/36 "2023-03-27T17:03:57Z")

</div>

thats true, these sketches, are for me, where i try to work further with  
So instead of an analogue value, i will use some push buttons  
the same number as the slaves

---

<div class="post-metadata">

**Author:** ![Hedalen](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/hedalen/32/239050_2.png) [@Hedalen](https://forum.arduino.cc/u/Hedalen)\
**Post date:** [April 21, 2023, 1:32pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/37 "2023-04-21T13:32:56Z")

</div>

i have switched now to RS485, bcz of the distance  
so i must start again with all

---

<div class="post-metadata">

**Author:** ![qubits-us](https://avatars.discourse-cdn.com/v4/letter/q/5daacb/32.png) [@qubits-us](https://forum.arduino.cc/u/qubits-us)\
**Post date:** [April 21, 2023, 1:59pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/38 "2023-04-21T13:59:24Z")

</div>

Looks like ModBus..  
did some myself, few months ago..

[ModBus Units](https://github.com/qubits-us/Delphi-IO)

maybe it helps..

good luck.. ~q

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 18, 2023, 1:59pm UTC](https://forum.arduino.cc/t/domotica-in-home/1102810/39 "2023-10-18T13:59:33Z")

</div>

Closed on October 18, 2023, 1:59pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.

[Previous page](https://forum.arduino.cc/t/domotica-in-home/1102810.md?page=1)
