[SOLVED] Sending serial command to arduino with openhab

Tags: #<Tag:0x00007f617a284668> #<Tag:0x00007f617a2844d8>

I currently installed openhabian to a Raspberry Pi 3. I have a 4 channel relay connected to an Arduino. I would like that the relays can switch on and off using openhab. The relays can be switched using serial. I have read that you can use an esp8266, but I don’t have access to this. How can I make this connection work without using an esp8266. Is this maybe possible through gpio pins?

This is my Arduino code:

#define RELAY1 2
#define RELAY2 3
#define RELAY3 4
#define RELAY4 5

void setup(){

pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);

void loop (){
if (Serial.available()) {
char ser = Serial.read();
case β€˜1’: AAN(RELAY1); break;
case β€˜2’: AAN(RELAY2); break;
case β€˜3’: AAN(RELAY3); break;
case β€˜4’: AAN(RELAY4); break;
case β€˜5’: UIT(RELAY1); break;
case β€˜6’: UIT(RELAY2); break;
case β€˜7’: UIT(RELAY3); break;
case β€˜8’: UIT(RELAY4); break;

void AAN(int8_t pin) {
digitalWrite(pin, LOW);

void UIT(int8_t pin) {
digitalWrite(pin, HIGH);

//RELAY1 AAN = 1
//RELAY2 AAN = 2
//RELAY3 AAN = 3
//RELAY4 AAN = 4
//RELAY1 UIT = 5
//RELAY2 UIT = 6
//RELAY3 UIT = 7
//RELAY4 UIT = 8

Make this connection through the GPIO serial port:

How to enable it:

Then you could use the Serial binding

1 Like