1

Topic: 2 relay in one switsh

hi ...
I have 2 channel relay modle .. i put in  4 and 5 pin
in normaly 2 switch control it

i need to control it with one switsch .. means if switsh off turn relay number one on
and number 2 off , and if switch on turn number one off and turn the number 2 relay

2

Re: 2 relay in one switsh

Like this

void loop()
{
    static uint8_t switch_PreviousValue = RemoteXY.switch;

    // if switch value changed
    if ( RemoteXY.switch != switch_PreviousValue )
    {
        digitalWrite( pin_relay1, RemoteXY.switch == 0 ? HIGH : LOW  );
        digitalWrite( pin_relay2, RemoteXY.switch == 0 ? LOW  : HIGH );
        switch_PreviousValue = RemoteXY.switch;
    }
}

Maybe need to invert logic, depending if your relays are Active LOW or Active HIGH.

3

Re: 2 relay in one switsh

Tnx frind i found an error in complate
Please can get me the full surce

Guillaume wrote:

Like this

void loop()
{
    static uint8_t switch_PreviousValue = RemoteXY.switch;

    // if switch value changed
    if ( RemoteXY.switch != switch_PreviousValue )
    {
        digitalWrite( pin_relay1, RemoteXY.switch == 0 ? HIGH : LOW  );
        digitalWrite( pin_relay2, RemoteXY.switch == 0 ? LOW  : HIGH );
        switch_PreviousValue = RemoteXY.switch;
    }
}

Maybe need to invert logic, depending if your relays are Active LOW or Active HIGH.

4

Re: 2 relay in one switsh

exit status 1
expected unqualified-id before 'switch'

872564 wrote:

Tnx frind i found an error in complate
Please can get me the full surce

Guillaume wrote:

Like this

void loop()
{
    static uint8_t switch_PreviousValue = RemoteXY.switch;

    // if switch value changed
    if ( RemoteXY.switch != switch_PreviousValue )
    {
        digitalWrite( pin_relay1, RemoteXY.switch == 0 ? HIGH : LOW  );
        digitalWrite( pin_relay2, RemoteXY.switch == 0 ? LOW  : HIGH );
        switch_PreviousValue = RemoteXY.switch;
    }
}

Maybe need to invert logic, depending if your relays are Active LOW or Active HIGH.

5

Re: 2 relay in one switsh

Replace RemoteXY.switch with your own variable, my crystal ball is broken so I can't see what variable name you used...

6

Re: 2 relay in one switsh

tnx bro
im sory about your crystal ball
frind thats messege after update ( exit status 1
'struct<unnamed>' has no member named 'SWITCH_1')

i feel the code from bigining is error
i had make alot of change on it
please can make afull code
i connect the 2 relay on pin 10 and 11
blotooth tx rx on pin 2 and 3

please make full code for me

Guillaume wrote:

Replace RemoteXY.switch with your own variable, my crystal ball is broken so I can't see what variable name you used...