1

I use the RCSwitch library receive signals with a RF receiver. I really need to change the pin the receiver is connected to on my Arduino Uno.

What should I change in my sketch? What pins can I connect the receiver to?

This is my code:

#include <RCSwitch.h>

RCSwitch receiver = RCSwitch();

void setup() {
  Serial.begin(9600);

  receiver.enableReceive(0);
  pinMode(1, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);

  Serial.println("READY");
}

void loop() {
  if (receiver.available()) {
    
    int value = receiver.getReceivedValue();

    Serial.println(value);

    switch(value) {
      case 1:
        digitalWrite(1, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        break;
      case 2:
        digitalWrite(1, LOW);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        break;
      case 3:
        digitalWrite(1, HIGH);
        digitalWrite(9, LOW);
        digitalWrite(10, HIGH);
        break;
      case 4:
        digitalWrite(1, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, LOW);
        break;
    }
  }
}
1
  • IIRC it needs an interrupt-capable pin, so 2 & 3 on an Uno. Why do you need to switch pins? Jun 11 at 17:59
3

You can change

receiver.enableReceive(0);

which uses pin 2, to

receiver.enableReceive(1);

which is pin 3 on the Uno. These are the numbers of the external interrupt. The Uno only has two of them, which are tied to those two pins. So as long as you are using the Arduino Uno, you need to use one of these. The Arduino Mega for example has more external interrupts.

For reference also look at the github page of the RCSwitch library and it's wiki, especially the site about receiving, where this is described.


Besides that: As you are using Serial, you might want to change

pinMode(1, OUTPUT);

to a different pin, since pins 0 and 1 are used for the Hardware Serial interface (Serial, which is connected to USB). So the usage of that pin collides with the serial communication.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.