Relay bord with z-uno

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
plutonium
Posts: 8
Joined: 05 Mar 2017 19:39

Relay bord with z-uno

Post by plutonium »

Hi,

I new to z-uno but familiar to arduino.
I have i relaybord, this kind https://www.m.nu/servo-motorer-robotics ... ge-nosto-1

I thought that I just could hook it up to pinout 13 and run it with the relaycontrol example. But I cannot seems to get it to work. The 13 pin is always HIGH, but led LED on z-uno reacts to domoticz commands (On/Off).

What do I do wrong?

Code: Select all

/*
 * This example shows basic Switch Binary functionality
 * Control an external relay on pin 13
 */

// pin number, where relay is connected
#define RELAY_PIN     13

// variable to store current relay state
byte lastSetValue;

// next macro sets up the Z-Uno channels
// in this example we set up 1 switch binary channel
// you can read more on http://z-uno.z-wave.me/Reference/ZUNO_SWITCH_BINARY/
ZUNO_SETUP_CHANNELS(ZUNO_SWITCH_BINARY(getter, setter));

void setup() {
  pinMode(RELAY_PIN, OUTPUT); // set up relay pin as output
}

void loop() {
  // loop is empty, because all the control comes over the Z-Wave
}


// function, which returns the previously saved relay value
// this function runs only once the controller asks
byte getter() {
    return lastSetValue;
}


// function, which sets new relay state
// this function runs only once the controller sends new value
void setter(byte newValue) {
  // newValue is a variable, holding a "value"
  // which came from the controller or other Z-Wave device
  if (newValue > 1) { // if greater then zero
    digitalWrite(RELAY_PIN, HIGH); //turn relay on
  } else {            // if equals zero
    digitalWrite(RELAY_PIN, LOW); //turn relay off
  }

  // save the new value in a variable
  lastSetValue = newValue;
}
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Relay bord with z-uno

Post by p0lyg0n1 »

It sounds strange... If you see that LED changes its state it means that PIN13 changes its state too. You can check it via multimeter. White LED connected directly to PIN13. May be you connect relay control to another PIN? PIN13 = PW1 (see http://z-uno.z-wave.me/technical/pinout/).
Your code have a strange place

Code: Select all

 if (newValue > 1) { // if greater then zero
    digitalWrite(RELAY_PIN, HIGH); //turn relay on
  } else {            // if equals zero
    digitalWrite(RELAY_PIN, LOW); //turn relay off
  }
the original code from SimpleSwitch.ino is

Code: Select all

if (value > 0) {    // if greater then zero
    digitalWrite (LED_PIN, HIGH); //turn LED on
  } else {            // if equals zero
    digitalWrite(LED_PIN, LOW);   //turn LED off
  } 
And another one feature(it a restriction of a protocol): You have to exclude/include your Z-Uno from controller if you reload the sketch or you have to use macro

Code: Select all

ZUNO_SETUP_DEBUG_MODE(DEBUG_ON);
after ZUNO_SETUP_CHANNELS macro in your code for debug purposes.
plutonium
Posts: 8
Joined: 05 Mar 2017 19:39

Re: Relay bord with z-uno

Post by plutonium »

Thanks for your reply.
I think I figured it out, but I don't know why it appears... But when I drive my relay board with 5V it is always on, but when I change to 3V it react as it should do... Does anyone know why?
p0lyg0n1
Posts: 242
Joined: 04 Aug 2016 07:14

Re: Relay bord with z-uno

Post by p0lyg0n1 »

You have to control relay via its nominal voltage. I don't know what schematic was used for your relay module, but by default Arduino Uno use 5V logic, when Z-Uno use 3.3v logic. To control it you can use some attional drivers: channel transistor, darlington array etc. The most simple way is to connect module via ULN2003. Here is an example https://www.elprocus.com/wp-content/upl ... nd-Off.jpg. Replace 12v to 5v in schematics and all will be ok. Another way is to use 3.3v compatible relay modules (any modules/shields for cortex-based boards, shields fo RaspberryPi use 3.3v logic too).
hansendw
Posts: 2
Joined: 01 Apr 2019 01:37

Re: Relay bord with z-uno

Post by hansendw »

You have “if (newValue>1)”. Did you want “0”?
Post Reply