Nano PWM / analogWrite conflicts with RC-Switch

Hi,
I try to set a PWM using a RC module, every part works (PWM dimming, RC sending / receiving commands), but I can not put them together.
It seems analogWrite conflicts the RC-Switch, as soon as I use analogWrite I do not receive any commands.

Minimal example code (run on an arduino Nano):

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup() {
  Serial.begin(9600);
  Serial.println("Begin");
  mySwitch.enableReceive(0);  // Receiver on interrupt 0 => that is pin #2
  // uncommenting will prevent RC-Switch from receiving anything
  //analogWrite(9, 50);
}

void loop() {
  if (mySwitch.available()) {
    Serial.println(mySwitch.getReceivedValue(), HEX);
    mySwitch.resetAvailable();
  }
}

Any ideas on what i am doing wrong? Thank you in advance.

The RCSwitch library does the 433MHz protocol in software. That uses almost all the Arduino Nano. It uses a interrupt and no timers.
The analogWrite() uses hardware timers inside the Nano to make a PWM signal. That does not conflict with the RCSwitch.

My first impression is that it should work and it is probably something in hardware.

Can you do a test ? Disconnect everything from the Nano, except the USB power and the receiver module to pin 2. Add the line with analogWrite (with nothing connected to pin 9). Can it receive ? It is important that nothing is connected to pin 9, not even a loose wire.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.