<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Binary button conflicting Relais with button]]></title><description><![CDATA[<p dir="auto">I use a sensor with 3 relais with button and 4 binary buttons. All 3 relais are working and 3 of the 4 buttons are working to but as soon as I hit the button on pin A1, the relay on pin A5 is switching. I have already tried to change the A1 pin in another but same result. Any idea how to solve this? included the code:```<br />
// 2x binary switch + dallas temp example<br />
// Connect button or door/window reed switch between<br />
// digitial I/O pin 4,5 (BUTTON_PIN_4/BUTTON_PIN_5 below) and GND.<br />
// Connect dallas temp sensor to digital pin 3</p>
<p dir="auto">#include &lt;MySensor.h&gt;<br />
#include &lt;SPI.h&gt;<br />
#include &lt;Bounce2.h&gt;<br />
#define DIGITAL_MOTION_SENSOR 3<br />
#define CHILD_ID_MOTION 6<br />
#define BUTTON1_PIN 2<br />
#define CHILD_ID_BUTTON1 4<br />
#define BUTTON2_PIN A0<br />
#define CHILD_ID_BUTTON2 3<br />
#define BUTTON3_PIN 8<br />
#define CHILD_ID_BUTTON3 5<br />
#define BUTTON4_PIN A1<br />
#define CHILD_ID_BUTTON4 1<br />
#define RELAY_ON 0                      // switch around for realy HIGH/LOW state<br />
#define RELAY_OFF 1<br />
#define RADIO_ID 43</p>
<p dir="auto">Bounce motionsDebouncer = Bounce();<br />
Bounce button1debouncer = Bounce();<br />
Bounce button2debouncer = Bounce();<br />
Bounce button3debouncer = Bounce();<br />
Bounce button4debouncer = Bounce();<br />
int oldValueButt1=-1;<br />
int oldValueButt2=-1;<br />
int oldValueButt3=-1;<br />
int oldValueButt4=-1;</p>
<p dir="auto">int lastMOTION;<br />
unsigned long SLEEP_TIME = 10000;<br />
unsigned long blockMotionTimer = 0;</p>
<p dir="auto">MySensor gw;</p>
<p dir="auto">#define noRelays 3<br />
const int relayPin[] = {A3, A7, A6}; //  switch around pins to your desire<br />
const int buttonPin[] = {4, A5, 7}; //  switch around pins to your desire</p>
<p dir="auto">class Relay             // relay class, store all relevant data (equivalent to struct)<br />
{<br />
public:<br />
int buttonPin;                    // physical pin number of button<br />
int relayPin;                     // physical pin number of relay<br />
byte oldValue;                    // last Values for key (debounce)<br />
boolean relayState;               // relay status (also stored in EEPROM)<br />
};</p>
<p dir="auto">Relay Relays[noRelays];<br />
Bounce debouncerRELAY[noRelays];<br />
MyMessage msgRELAY[noRelays], msgMOTION(CHILD_ID_MOTION, V_TRIPPED), msgBUTTON1(CHILD_ID_BUTTON1,V_TRIPPED), msgBUTTON2(CHILD_ID_BUTTON2,V_TRIPPED), msgBUTTON3(CHILD_ID_BUTTON3,V_TRIPPED), msgBUTTON4(CHILD_ID_BUTTON4,V_TRIPPED);</p>
<p dir="auto">void setup()<br />
{<br />
<a href="//sensors.begin" rel="nofollow ugc">//sensors.begin</a>();<br />
<a href="//gw.begin" rel="nofollow ugc">//gw.begin</a>();<br />
gw.begin(incomingMessage, AUTO, true);<br />
gw.sendSketchInfo("Motion/Button/relay", "1.0");</p>
<p dir="auto">// Setup the button<br />
pinMode(BUTTON1_PIN,INPUT);<br />
pinMode(BUTTON2_PIN,INPUT);<br />
pinMode(BUTTON3_PIN,INPUT);<br />
pinMode(BUTTON4_PIN,INPUT);<br />
// Activate internal pull-up<br />
digitalWrite(BUTTON1_PIN,HIGH);// Activate internal pull-up<br />
digitalWrite(BUTTON2_PIN,HIGH);<br />
digitalWrite(BUTTON3_PIN,HIGH);<br />
digitalWrite(BUTTON4_PIN,HIGH);</p>
<p dir="auto">gw.present(CHILD_ID_BUTTON1, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON2, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON3, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON4, S_DOOR);</p>
<pre><code>// After setting up the button, setup debouncer
</code></pre>
<p dir="auto">button1debouncer.attach(BUTTON1_PIN);<br />
button1debouncer.interval(5);<br />
button2debouncer.attach(BUTTON2_PIN);<br />
button2debouncer.interval (5);<br />
button3debouncer.attach(BUTTON3_PIN);<br />
button3debouncer.interval(5);<br />
button4debouncer.attach(BUTTON4_PIN);<br />
button4debouncer.interval (5);</p>
<p dir="auto">// Register binary input sensor to gw (they will be created as child devices)<br />
// You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.<br />
// If S_LIGHT is used, remember to update variable type you send in. See "msg" above.<br />
gw.present(CHILD_ID_BUTTON1, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON2, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON3, S_DOOR);<br />
gw.present(CHILD_ID_BUTTON4, S_DOOR);</p>
<p dir="auto">pinMode(DIGITAL_MOTION_SENSOR, INPUT_PULLUP);      // sets the motion sensor digital pin as input<br />
motionsDebouncer.attach(DIGITAL_MOTION_SENSOR);<br />
motionsDebouncer.interval(400);<br />
// Register all sensors to gw (they will be created as child devices)<br />
gw.present(CHILD_ID_MOTION, S_MOTION, "Motion needs presentation", true);</p>
<p dir="auto">for (int i = 0; i &lt; noRelays; i++)<br />
{<br />
Relays[i].buttonPin = buttonPin[i];              // assign physical pins<br />
Relays[i].relayPin = relayPin[i];<br />
msgRELAY[i].sensor = i;                                   // initialize messages<br />
msgRELAY[i].type = V_LIGHT;<br />
debouncerRELAY[i] = Bounce();                        // initialize debouncer<br />
debouncerRELAY[i].attach(buttonPin[i]);<br />
debouncerRELAY[i].interval(5);<br />
pinMode(Relays[i].buttonPin, INPUT_PULLUP);<br />
pinMode(Relays[i].relayPin, OUTPUT);<br />
Relays[i].relayState = gw.loadState(i);                               // retrieve last values from EEPROM<br />
digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly<br />
gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false));                 // make controller aware of last status<br />
gw.present(i, S_LIGHT);                               // present sensor to gateway<br />
delay(250);</p>
<p dir="auto">}</p>
<p dir="auto">}<br />
void loop()<br />
{<br />
gw.process();</p>
<p dir="auto">button1debouncer.update();<br />
// Get the update value<br />
int value = button1debouncer.read();</p>
<p dir="auto">if (value != oldValueButt1) {<br />
// Send in the new value<br />
gw.send(msgBUTTON1.set(value==HIGH ? 1 : 0));<br />
oldValueButt1 = value;<br />
}<br />
button2debouncer.update();<br />
// Get the update value<br />
value = button2debouncer.read();</p>
<p dir="auto">if (value != oldValueButt2) {<br />
// Send in the new value<br />
gw.send(msgBUTTON2.set(value==HIGH ? 1 : 0));<br />
oldValueButt2 = value;<br />
}<br />
button3debouncer.update();<br />
// Get the update value<br />
value = button3debouncer.read();</p>
<p dir="auto">if (value != oldValueButt3) {<br />
// Send in the new value<br />
gw.send(msgBUTTON3.set(value==HIGH ? 1 : 0));<br />
oldValueButt3 = value;<br />
}<br />
button4debouncer.update();<br />
// Get the update value<br />
value = button4debouncer.read();</p>
<p dir="auto">if (value != oldValueButt4) {<br />
// Send in the new value<br />
gw.send(msgBUTTON4.set(value==HIGH ? 1 : 0));<br />
oldValueButt4 = value;<br />
}</p>
<p dir="auto">for (byte i = 0; i &lt; noRelays; i++)<br />
{<br />
debouncerRELAY[i].update();<br />
byte value = debouncerRELAY[i].read();<br />
if (value != Relays[i].oldValue &amp;&amp; value == 0)<br />
{<br />
Relays[i].relayState = !Relays[i].relayState;<br />
digitalWrite(Relays[i].relayPin, Relays[i].relayState ? RELAY_ON : RELAY_OFF);<br />
gw.send(msgRELAY[i].set(Relays[i].relayState ? true : false));<br />
gw.saveState( i, Relays[i].relayState );<br />
}                 // save sensor state in EEPROM (location == sensor number)</p>
<pre><code>Relays[i].oldValue = value;
</code></pre>
<p dir="auto">}</p>
<p dir="auto">if (blockMotionTimer == 0) {<br />
if (motionsDebouncer.update()) {<br />
int value = motionsDebouncer.read();<br />
Serial.println( "PIR " + (String)value );<br />
gw.send( msgMOTION.set( value ), true ); // Also it might need inverted value<br />
blockMotionTimer = (millis() + SLEEP_TIME);<br />
}<br />
} else {<br />
motionsDebouncer.update(); // dummy update to prevent false trigger after timer expires<br />
if (blockMotionTimer &lt; millis()) {<br />
blockMotionTimer = 0;<br />
}<br />
}</p>
<p dir="auto">}</p>
<p dir="auto">void incomingMessage(const MyMessage &amp;message)<br />
{</p>
<p dir="auto">if (message.type == V_LIGHT)<br />
{<br />
if (message.sensor &lt; noRelays)            // check if message is valid for relays..... previous line  &lsqb;&lsqb;[ if (message.sensor &lt;=noRelays){ &rsqb;&rsqb;]<br />
{<br />
Relays[message.sensor].relayState = message.getBool();<br />
digitalWrite(Relays[message.sensor].relayPin, Relays[message.sensor].relayState ? RELAY_ON : RELAY_OFF); // and set relays accordingly<br />
gw.saveState( message.sensor, Relays[message.sensor].relayState ); // save sensor state in EEPROM (location == sensor number)<br />
}<br />
}<br />
<a href="//gw.wait" rel="nofollow ugc">//gw.wait</a>(50);</p>
<p dir="auto">}</p>
<pre><code></code></pre>
]]></description><link>https://forum.mysensors.org/topic/7127/binary-button-conflicting-relais-with-button</link><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Jul 2026 11:05:44 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/7127.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 08 Jul 2017 18:23:54 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Binary button conflicting Relais with button on Sat, 08 Jul 2017 19:35:36 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mfalkvidd" aria-label="Profile: mfalkvidd">@<bdi>mfalkvidd</bdi></a>  i thought is was ok because I defined 4 binary buttons 2, 8, A0 and A1 and they only work like a button. Beside these Buttons there is a class in use for the 3x relais with extra buttons to control the relais or do I make a mistake?</p>
]]></description><link>https://forum.mysensors.org/post/70803</link><guid isPermaLink="true">https://forum.mysensors.org/post/70803</guid><dc:creator><![CDATA[Dick]]></dc:creator><pubDate>Sat, 08 Jul 2017 19:35:36 GMT</pubDate></item><item><title><![CDATA[Reply to Binary button conflicting Relais with button on Sat, 08 Jul 2017 19:09:30 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/dick" aria-label="Profile: Dick">@<bdi>Dick</bdi></a> what you said in the introduction</p>
<blockquote>
<p dir="auto">I use a sensor with 3 relais with button and 4 binary buttons. All 3 relais are working and 3 of the 4 buttons are working to but as soon as I hit the button on pin A1, the relay on pin A5 is switching.</p>
</blockquote>
<p dir="auto">and the code you posted:</p>
<blockquote>
<p dir="auto">const int relayPin[] = {A3, A7, A6}; //  switch around pins to your desire<br />
const int buttonPin[] = {4, A5, 7}; //  switch around pins to your desire</p>
</blockquote>
<p dir="auto">don't match up.</p>
<ul>
<li>You're saying you have 3 relays and 4 buttons, but you have only 3 elements in the buttonPin array?</li>
<li>You're saying you have a button on pin A1 when A1 isn't used at all?</li>
<li>You're saying the relay on pin A5 is switching, when A5 is used for a button?</li>
</ul>
<p dir="auto">Could you clarify?<br />
Could you please use the code button to make the code section easier to read?</p>
]]></description><link>https://forum.mysensors.org/post/70800</link><guid isPermaLink="true">https://forum.mysensors.org/post/70800</guid><dc:creator><![CDATA[mfalkvidd]]></dc:creator><pubDate>Sat, 08 Jul 2017 19:09:30 GMT</pubDate></item></channel></rss>