Kategorie
5. díl - Spínání silových obvodů (světla, zásuvky, topení atd.)
5. díl - Spínání silových obvodů (světla, zásuvky, topení atd.)
Spínání silových obvodů - zásuvek, světel, žaluzií, zavlažování a podobných zařízení na 230V je jedním za základních funkcí inteligentního domu. V Pi-Home používáme Arduino relé 230V/2A, které spína galvanicky oddělené instalační relé 230V 16 nebo 20A. V případě vícefázových okruhu se volí vícefázové instalační relé.
Co budeme potřebovat:
2. díl - OpenHAB na Raspberry Pi
Originál Arduino Mega s originál Ethernet 2 Shieldem (DIN držák)
Arduino SSR "High Trigger" relé 8x2A/230V (DIN držák)
Instalační relé např. EATON Z-R230/S nebo tižší Hager ERC125S případně vícefázové EATON Z-R230/4S
Zdroj DC 5V 40W (DIN)
Napájení a propojení
Arduino Mega je připojeno k RPi přes USB a pomocí LAN do interní sítě. K pinům Arduina je připojeno 8x2A/230V "High Trigger" relé. Napětí je zde přivedeno z externího zdroje DC 5V 40W. Dle počtů ovládaných výstupů můžete na DIN lištu umístit potřebné množství těchto relé a propojit je s Arduinem. Relé pak uzavírají okruh s instalačním relé v silové části rozvaděče. Pro vícefázové okruhy/spotřebiče použijte vícefázové instalační relé. Silnoproudů část si nechte naprojektovat od elektrikáře silnoproudu kde je pak samozřejmě nutná revize.
Tip: "High Trigger" relé doporučujeme z ochranného důvodu, kdyby náhodou odešel zdroj DC nedojde k sepnutí všech relé jako u "Low Trigger" modulů.
Jednoduché schéma ovládání silnoproudu
Celkový náhled na slaboproudý rozvaděč
Software
Pro ovládaní Arduino relé je vám k dispozici jednoduchý sketch, který odposloucháva MQTT komunikaci. V případě specifického tvaru topicu a hodnoty se zapne relé a tímto uzavře okruh. Pokud je těchto relé desek více, doporučuji je mít na samostatném Arduinu a nekombinovat na jednom Arduinu senzory, PIR a silnoproudé obvody.
Ukázkový sketch
V tomto jednoduchém sketchi jsou použité knihovny SPI.h, Ethernet2.h a PubSubClient.h. V adresáři pro Arduino se musí nacházet Makefile (název souboru) s obsahem níže. Zde je uvedeno, jaké knihovny budeme načítat a kde jsou umístěny. Knihovny můžete vyhledat na internetu a stáhnout. Dále je v Makefile jednoznačná specifikace Arduina, my používáme specifický název, jak se Arduino hlásí na cestě /dev/serial/by-id/usb-Arduinoxxxx Jednoduše jděte v SSH do této složky a zkuste zapojit/odpojit dané Arduino a zaznamenejte si jaký název se zde objeví. Jméno zařízení zkopírujte do Makefile níže. V sketchi jsou pak deklarované proměnné (piny), na kterých jsou připojeny jednotlivé relé desky a logika odposlechu MQTT pro akci, nějaký reconnect, atd.
Vzorový "Makefile"
ARDUINO_DIR = /usr/share/arduino
BOARD_TAG = mega2560
ARDUINO_PORT = /dev/serial/by-id/usb-Arduino__www.arduino.cc__0042_85036313530351F0E032-if00 (nahraďte vlastním názvem)USER_LIB_PATH = /usr/share/arduino/libraries/
ARDUINO_LIBS = Ethernet2 SPI pubsubclient
include /usr/share/arduino/Arduino.mk
Vzorový sketch "ArduinoPA1.ino"
/*
Arduino 1 (PA01)
- connects to an MQTT server
- publishes "hello world" to the topic "pihome"
- subscribes to the topic "pihome/xxx"
- controls as many relays as defined
- turns on/off a specific led when it receives a specific "on"/"off" from the "pihome/xxx" topic
- multiple arduino's with same generic sketch can run parallel to each other
- multiple arduino's need each to have a unique ip-addres, unique mac address and unique MQTT client-ID
- tested on arduino-mega with W5500 ethernet shield
*/
//------------------------------------------------------------------------------
#include <SPI.h>
#include <Ethernet2.h>
#include <PubSubClient.h>
// Set relay variables to Arduino digital pins
//PR01
// pin 0 RX
// pin 1 TX
// pin 4 (SS for SD Card)
int L011 = 5;
int L012 = 6;
int L013 = 7;
int L014 = 8;
int L021 = 9;
// pin 10 (SS for Ethernet)
int L022 = 11;
int L031 = 12;
int L041 = 13;
//PR02
int L042 = 2;
int L043 = 3;
int L111 = 14;
int L112 = 15;
int L121 = 16;
int L122 = 17;
int L131 = 18;
int L141 = 19;
// pin 20 SDA
// pin 21 SCL
//PR03
int L151 = 22;
int L152 = 24;
int L153 = 26;
int L154 = 28;
int L155 = 30;
int L156 = 32;
int L161 = 34;
int L201 = 36;
//PR04
int L211 = 23;
int L212 = 25;
int L221 = 27;
int L231 = 29;
int L241 = 31;
int S011 = 33;
int S012 = 35;
int S013 = 37;
//PR05
int S014 = 38;
int S015 = 40;
int S016 = 42;
int S111 = 44;
int S121 = 46;
int S131 = 47;
int S141 = 48;
int S142 = 49;
//PR06
int S151 = 39;
int S152 = 41;
int S153 = 43;
int S154 = 45;
// pin 50 (SS for Ethernet)
// pin 51 (MOSI)
// pin 52 (MISO)
// pin 53 (SCK)
//PR07
//A0 (D54)
// int Rez = 54;
// int Rez = 55;
// int Rez = 56;
// int Rez = 57;
// int Rez = 58;
// int Rez = 59;
// pin 60 inaccesibble
// int Rez = 61;
int S155 = 63;
int S161 = 64;
int S201 = 65;
int S211 = 66;
int S221 = 67;
int S231 = 68;
int S241 = 69;
//A15 (D69)
// Set variables to act as virtual switches
// Set variable values initially to LOW (and not HIGH)
// HIGH or LOW as defautl is based on Relay Board
//PR01
int ValL011 = LOW;
int ValL012 = LOW;
int ValL013 = LOW;
int ValL014 = LOW;
int ValL021 = LOW;
int ValL022 = LOW;
int ValL031 = LOW;
int ValL041 = LOW;
//PR02
int ValL042 = LOW;
int ValL043 = LOW;
int ValL111 = LOW;
int ValL112 = LOW;
int ValL121 = LOW;
int ValL122 = LOW;
int ValL131 = LOW;
int ValL141 = LOW;
//PR03
int ValL151 = LOW;
int ValL152 = LOW;
int ValL153 = LOW;
int ValL154 = LOW;
int ValL155 = LOW;
int ValL156 = LOW;
int ValL161 = LOW;
int ValL201 = LOW;
//PR04
int ValL211 = LOW;
int ValL212 = LOW;
int ValL221 = LOW;
int ValL231 = LOW;
int ValL241 = LOW;
//int REZ=
//PR05
int ValS011 = LOW;
int ValS012 = LOW;
int ValS013 = LOW;
int ValS014 = LOW;
int ValS015 = LOW;
int ValS016 = LOW;
int ValS111 = LOW;
//PR06
int ValS121 = LOW;
int ValS131 = LOW;
int ValS141 = LOW;
int ValS142 = LOW;
int ValS151 = LOW;
int ValS152 = LOW;
int ValS153 = LOW;
int ValS154 = LOW;
//PR07
int ValS155 = LOW;
int ValS161 = LOW;
int ValS201 = LOW;
int ValS211 = LOW;
int ValS221 = LOW;
int ValS231 = LOW;
int ValS241 = LOW;
//---------------------------------------------------------------------------
// Arduino MAC address must be unique for every node in same network
// To make a new unique address change last letter
// Arduino 1
byte mac[] = { 0xCC, 0xFA, 0x0C, 0xCA, 0x19, 0x01 };
// Unique static IP address of this Arduino 1
IPAddress ip(10,0,0,171);
// IP Address of your MQTT broker (OpenHAB server)
byte server[] = { 10, 0, 0, 24 };
// Handle and convert incoming MQTT messages ----------------------------------------
void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
String content="";
char character;
for (int num=0;num<length;num++) {
character = payload[num];
content.concat(character);
}
//Relay Power
// Set specific virtual switches on basis of specific incoming messages ----------------------------
if (content == "L011_on") { ValL011 = HIGH; }
if (content == "L011_off") { ValL011 = LOW; }
if (content == "L012_on") { ValL012 = HIGH; }
if (content == "L012_off") { ValL012 = LOW; }
if (content == "L013_on") { ValL013 = HIGH; }
if (content == "L013_off") { ValL013 = LOW; }
if (content == "L014_on") { ValL014 = HIGH; }
if (content == "L014_off") { ValL014 = LOW; }
if (content == "L021_on") { ValL021 = HIGH; }
if (content == "L021_off") { ValL021 = LOW; }
if (content == "L022_on") { ValL022 = HIGH; }
if (content == "L022_off") { ValL022 = LOW; }
if (content == "L031_on") { ValL031 = HIGH; }
if (content == "L031_off") { ValL031 = LOW; }
if (content == "L041_on") { ValL041 = HIGH; }
if (content == "L041_off") { ValL041 = LOW; }
if (content == "L042_on") { ValL042 = HIGH; }
if (content == "L042_off") { ValL042 = LOW; }
if (content == "L043_on") { ValL043 = HIGH; }
if (content == "L043_off") { ValL043 = LOW; }
if (content == "L111_on") { ValL111 = HIGH; }
if (content == "L111_off") { ValL111 = LOW; }
if (content == "L112_on") { ValL112 = HIGH; }
if (content == "L112_off") { ValL112 = LOW; }
if (content == "L121_on") { ValL121 = HIGH; }
if (content == "L121_off") { ValL121 = LOW; }
if (content == "L122_on") { ValL122 = HIGH; }
if (content == "L122_off") { ValL122 = LOW; }
if (content == "L131_on") { ValL131 = HIGH; }
if (content == "L131_off") { ValL131 = LOW; }
if (content == "L141_on") { ValL141 = HIGH; }
if (content == "L141_off") { ValL141 = LOW; }
if (content == "L151_on") { ValL151 = HIGH; }
if (content == "L151_off") { ValL151 = LOW; }
if (content == "L152_on") { ValL152 = HIGH; }
if (content == "L152_off") { ValL152 = LOW; }
if (content == "L153_on") { ValL153 = HIGH; }
if (content == "L153_off") { ValL153 = LOW; }
if (content == "L154_on") { ValL154 = HIGH; }
if (content == "L154_off") { ValL154 = LOW; }
if (content == "L155_on") { ValL155 = HIGH; }
if (content == "L155_off") { ValL155 = LOW; }
if (content == "L156_on") { ValL156 = HIGH; }
if (content == "L156_off") { ValL156 = LOW; }
if (content == "L161_on") { ValL161 = HIGH; }
if (content == "L161_off") { ValL161 = LOW; }
if (content == "L201_on") { ValL201 = HIGH; }
if (content == "L201_off") { ValL201 = LOW; }
if (content == "L211_on") { ValL211 = HIGH; }
if (content == "L211_off") { ValL211 = LOW; }
if (content == "L212_on") { ValL212 = HIGH; }
if (content == "L212_off") { ValL212 = LOW; }
if (content == "L221_on") { ValL221 = HIGH; }
if (content == "L221_off") { ValL221 = LOW; }
if (content == "L231_on") { ValL231 = HIGH; }
if (content == "L231_off") { ValL231 = LOW; }
if (content == "L241_on") { ValL241 = HIGH; }
if (content == "L241_off") { ValL241 = LOW; }
if (content == "S011_on") { ValS011 = HIGH; }
if (content == "S011_off") { ValS011 = LOW; }
if (content == "S012_on") { ValS012 = HIGH; }
if (content == "S012_off") { ValS012 = LOW; }
if (content == "S013_on") { ValS013 = HIGH; }
if (content == "S013_off") { ValS013 = LOW; }
if (content == "S014_on") { ValS014 = HIGH; }
if (content == "S014_off") { ValS014 = LOW; }
if (content == "S015_on") { ValS015 = HIGH; }
if (content == "S015_off") { ValS015 = LOW; }
if (content == "S016_on") { ValS016 = HIGH; }
if (content == "S016_off") { ValS016 = LOW; }
if (content == "S111_on") { ValS111 = HIGH; }
if (content == "S111_off") { ValS111 = LOW; }
if (content == "S121_on") { ValS121 = HIGH; }
if (content == "S121_off") { ValS121 = LOW; }
if (content == "S131_on") { ValS131 = HIGH; }
if (content == "S131_off") { ValS131 = LOW; }
if (content == "S141_on") { ValS141 = HIGH; }
if (content == "S141_off") { ValS141 = LOW; }
if (content == "S142_on") { ValS142 = HIGH; }
if (content == "S142_off") { ValS142 = LOW; }
if (content == "S151_on") { ValS151 = HIGH; }
if (content == "S151_off") { ValS151 = LOW; }
if (content == "S152_on") { ValS152 = HIGH; }
if (content == "S152_off") { ValS152 = LOW; }
if (content == "S153_on") { ValS153 = HIGH; }
if (content == "S153_off") { ValS153 = LOW; }
if (content == "S154_on") { ValS154 = HIGH; }
if (content == "S154_off") { ValS154 = LOW; }
if (content == "S155_on") { ValS155 = HIGH; }
if (content == "S155_off") { ValS155 = LOW; }
if (content == "S161_on") { ValS161 = HIGH; }
if (content == "S161_off") { ValS161 = LOW; }
if (content == "S201_on") { ValS201 = HIGH; }
if (content == "S201_off") { ValS201 = LOW; }
if (content == "S211_on") { ValS211 = HIGH; }
if (content == "S211_off") { ValS211 = LOW; }
if (content == "S221_on") { ValS221 = HIGH; }
if (content == "S221_off") { ValS221 = LOW; }
if (content == "S231_on") { ValS231 = HIGH; }
if (content == "S231_off") { ValS231 = LOW; }
if (content == "S241_on") { ValS241 = HIGH; }
if (content == "S241_off") { ValS241 = LOW; }
// Set digital pin states according to virtual switch settings
digitalWrite(L011, ValL011);
digitalWrite(L012, ValL012);
digitalWrite(L013, ValL013);
digitalWrite(L014, ValL014);
digitalWrite(L021, ValL021);
digitalWrite(L022, ValL022);
digitalWrite(L031, ValL031);
digitalWrite(L041, ValL041);
digitalWrite(L042, ValL042);
digitalWrite(L043, ValL043);
digitalWrite(L111, ValL111);
digitalWrite(L112, ValL112);
digitalWrite(L121, ValL121);
digitalWrite(L122, ValL122);
digitalWrite(L131, ValL131);
digitalWrite(L141, ValL141);
digitalWrite(L151, ValL151);
digitalWrite(L152, ValL152);
digitalWrite(L153, ValL153);
digitalWrite(L154, ValL154);
digitalWrite(L155, ValL155);
digitalWrite(L156, ValL156);
digitalWrite(L161, ValL161);
digitalWrite(L201, ValL201);
digitalWrite(L211, ValL211);
digitalWrite(L212, ValL212);
digitalWrite(L221, ValL221);
digitalWrite(L231, ValL231);
digitalWrite(L241, ValL241);
digitalWrite(S011, ValS011);
digitalWrite(S012, ValS012);
digitalWrite(S013, ValS013);
digitalWrite(S014, ValS014);
digitalWrite(S015, ValS015);
digitalWrite(S016, ValS016);
digitalWrite(S111, ValS111);
digitalWrite(S121, ValS121);
digitalWrite(S131, ValS131);
digitalWrite(S141, ValS141);
digitalWrite(S142, ValS142);
digitalWrite(S151, ValS151);
digitalWrite(S152, ValS152);
digitalWrite(S153, ValS153);
digitalWrite(S154, ValS154);
digitalWrite(S155, ValS155);
digitalWrite(S161, ValS161);
digitalWrite(S201, ValS201);
digitalWrite(S211, ValS211);
digitalWrite(S221, ValS221);
digitalWrite(S231, ValS231);
digitalWrite(S241, ValS241);
}
// Initiate instances -----------------------------------
EthernetClient arduino1;
PubSubClient client(server, 1883, callback, arduino1);
void setup()
{
digitalWrite(L011, LOW);
digitalWrite(L012, LOW);
pinMode(L011, OUTPUT);
pinMode(L012, OUTPUT);
// Setup ethernet connection to MQTT broker
Ethernet.begin(mac, ip);
if (client.connect("arduino1", "openhabian", "openhabian")) {
client.publish("pihome","Hello world - here Arduino1 with IP 10.0.0.171");
client.subscribe("pihome/lights");
client.subscribe("pihome/sockets");
}
}
//-----------------------------------------------
long lastReconnectAttempt = 0;
boolean reconnect() {
if (client.connect("arduino1", "openhabian", "openhabian")) {
// Once connected, publish an announcement...
client.publish("pihome","Arduino 1 - reconnected");
client.subscribe("pihome/lights");
client.subscribe("pihome/sockets");
}
return client.connected();
}
//----------------------------------------------
void loop()
{
if (!client.connected()) {
long now = millis();
if (now - lastReconnectAttempt > 5000) {
lastReconnectAttempt = now;
// Attempt to reconnect
if (reconnect()) {
lastReconnectAttempt = 0;
}
}
} else {
// Client connected
client.loop();
}
}
// End of sketch ---------------------------------
OpenHAB 3
V OpenHAB by jste již měli dle tutoriálu mít světla a zásuvky. Zkuste je z mobilu zapnout/vypnout a vaše relé by na tyto úkony mělo reagovat. Toto řešení lze neomezeně rozšířit. Máme zkušenosti s bezproblémovou instalaci až s 200 relé.
Tip: Na jednu desku Arduino Mega s Ethernet shieldem se vejde až 6 kusů 8x SSR relay board co je až 48 světel/zásuvek/čerpadel atd. na jedno Arduino Mega