RF Signal Mess

Hello there,
I control 2 arduino with transmitters and 2 rf relays in the same room. I am sending a relay “2010202” with the code I use with the rc-switch library and another relay “2020202” with the other arduino. these two codes are sometimes interfering and activating the wrong relay. is that the reason codes are close to each other?
Should I use a different data type?

my code example:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
const int pencere=4;
void setup() {
pinMode(pencere,INPUT_PULLUP);
Serial.begin(9600);
mySwitch.enableTransmit(13);
}

void loop() {
if( digitalRead(pencere) == 0){
mySwitch.send(2010202 , 24);
}
else{
mySwitch.send(2010201, 24);
}
}

It could also be that your transmitters are interfering the receivers. If those transmitters are transmitters at the same time it is hard to say what happens. At least they should have different frequencies.

How about sending your code say three times. If you receive three or two similar codes, you can sure that it is correct.

The problem is in the RF protocol. It is very simple. The other problem is that you are transmitting far too often. The loop() transmits continuously. That is also illegal in most countries.
That RF protocol can not handle two Arduino boards transmitting at the same time.

Can you detect a state change of the digital pin ? and only transmit something if the state has changed.
Use the StateChangeDetection: https://www.arduino.cc/en/Tutorial/StateChangeDetection.

If the Arduino boards still have trouble sending at the same time, you could perhaps add a random delay and retransmit it once more.

The RadioHead (in ASK mode) or VirtualWire has a checksum and a better protocol. But then the receiver has to be an Arduino as well.
Or you can use transceivers, for example the cheap nRF24L01+ or the RFM96.
What if you have only one Arduino with a transmitter, and connect the other Arduino board somehow to the first one.

Thank you for your help. i change my code like this

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
long randNumber;
const int pencere = 4;
int sondurum = 0;
int durum = 0;
void setup() {
  pinMode(pencere, INPUT_PULLUP);
  Serial.begin(9600);
  mySwitch.setRepeatTransmit(5);
  mySwitch.enableTransmit(13);
}

void loop() {
  durum = digitalRead(pencere);
  if (durum != sondurum)
  {
    if ( durum == 0) {
      mySwitch.send(4010202 , 24);
      Serial.println("Pencere Kapali");
    }
    else {
      mySwitch.send(4010201, 24);
      Serial.println("Pencere Acik");
    }
    delay(500);
  }
  sondurum = durum;
}

its not work same time send signal as you said. so this code sender is door sensor on 2 door.system dont work if they open 2 door exactly same time. can i put random delay in code for send signal different period?
thank again for your help and sorry for my google translated english.

You can try a random delay. But the protocol is too simple, I don't now if that will fix it.
Perhaps you can retransmit it after a random delay.

The mySwitch.setRepeatTransmit() is set to 5. You could try to lower that number and try to transmit it once more. If that does not help, then you might try to transmit it three times with random delay in between.

The random function is a fixed sequence. Both Arduino boards could create the same random numbers. You can make it more random with analog inputs. See randomSeed().

void setup()
{
  randomSeed(analogRead(0));
  ...
  mySwitch.send(4010202 , 24);   // transmit
  long randomdelay = random( 100, 1000);
  delay( randomdelay);              // random delay
  mySwitch.send(4010202 , 24);   // retransmit

Did you take a look at the nRF24L01+ modules ?

i found this article and wait my attiny and nrf’s. i will try this

I can briefly describe the system as follows.
air conditioning in hotel rooms, a system that closes when windows or doors open.
It consists of 3 parts.

  1. the rf relay plugged into the air conditioner (right in pic)
  2. arduino that detects the door with the reed relay and sends a signal to the air conditioner. (mid in pic)
  3. reed relay (left in pic)

arduino and relay are connected to 220v-5v, 220v-12v adapters as continuous operation is required

and here my code

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
int rndnumber=0;
const int window = 4;
int laststatus = 0;
int actstatus = 0;
void setup() {
  pinMode(window, INPUT_PULLUP);
  //Serial.begin(9600);
  mySwitch.setRepeatTransmit(5);
  mySwitch.enableTransmit(13);
}

void loop() {
  actstatus = digitalRead(window);
  if (actstatus != laststatus)
  {
    //rndnumber=random(1,500);
    if ( actstatus == 0) {
      //delay(1000);
      mySwitch.send(3040202 , 24);
      Serial.println("Window Closed");
    }
    else {
      //delay(1000);
      mySwitch.send(3040201, 24);
      Serial.println("Window Open");
    }
    delay(500);
  }
  laststatus = actstatus;
}

some rooms have 2 air conditioner and 2 window.
when i run this code and component in this double rooms,
I set the codes differently but the signals are mixed. sometimes the sensor 1 is closing the air conditioner 2. sometimes it does not work at all. Sometimes when I touch my finger, it sends a signal, even though there is no movement on the sensor. When I connect it to pc with ft1232, it works fine. reed relay connected to pin 4 with pull-up gnd
I have combined all elements of the gnd lines. do i have to connect another place this gnd pin
that is not stable. Is there a part that I missed?
thank you

Perhaps there is a problem with the circuit to the reed relais. Perhaps it is sending far too much data.
Is the reed relay connect to the GND and the input pin ?
You could add a pullup resistor of 2k2 or 4k7 from the input pin to the 5V. The internal pullup resistor is weak.

thank you for reply.
i change my reed connection from gnd to 5v manual pullup with 10k resistor

like here Monitor Your Door Using Magnetic Reed Switch and Arduino | Random Nerd Tutorials

does this affect signal confusion?

or can i upgrade to nrf24l01+

The schematic in that link has a puldown resistor and the reed switch connected to 5V. I don't understand how you have wired it.
Continueus sending data because of a floating input has a higher chance that the receiver combines the two and gets the wrong data.

The nRF24L01+ is running at 3.3V, but the pins are 5V tolerant. It does not have the signal confusion.
However, the receiver must be also an Arduino board with a nRF24L01+.

When both the transmitter and receiver have an Arduino board, you might also use the VirtualWire/RadioHead library.

sorry my mistake. i change my connection with gnd internal pullup to 5v 10k resistor pulldown like as link

If I go to NRF24101. i need to make this pcb for 23 different rooms. do I have an address conflict problem? Can I define 23 different addresses?

Are you getting paid for this project? Are you asking for free engineering design help?

Paul

I woudnt use a system like this in a commercial environment like hotel rooms.
The problem is the RC switches as they dont provide state information to the controller thats sending the commands to switch them on and off, so you dont really know if they are actually being switched or not.
The problem will get worse with lots of them in close proximity.

Paul_KD7HB:
Are you getting paid for this project? Are you asking for free engineering design help?

Paul

this is not commercial system. its free engineering for understand to learn arduino working principles

mauried:
I woudnt use a system like this in a commercial environment like hotel rooms.
The problem is the RC switches as they dont provide state information to the controller thats sending the commands to switch them on and off, so you dont really know if they are actually being switched or not.
The problem will get worse with lots of them in close proximity.

yes it is a big problem. on this system cant check actually switch status

hi again,

i change system from rf433 to nrf24l01

finally its working

i use this example for ackpayload

thank you for all

:slight_smile: Cool.