RC-Switch Library

is not yet ported but by using the example-code provided by the author of rc-switch I managed to talk to a “dip switch” model:

  This is a minimal sketch without using the library at all but only works for
  the 10 pole dip switch sockets. It saves a lot of memory and thus might be 
  very useful to use with ATTinys :)

int RCLpin = D7;  // modified run with a Spark Core

void setup() {
    pinMode(RCLpin, OUTPUT);

void loop() {
    RCLswitch(0b010001000001);  // DIPs at rc power outlet: 0100010000 ON:01

    RCLswitch(0b010001000010);  // DIPs at rc power outlet: 0100010000 OFF:10

void RCLswitch(uint16_t code) {
    for (int nRepeat=0; nRepeat<6; nRepeat++) {
        for (int i=4; i<16; i++) {
            if (((code << (i-4)) & 2048) > 0) {
            } else {

void RCLtransmit(int nHighPulses, int nLowPulses) {
    digitalWrite(RCLpin, HIGH);
    delayMicroseconds( 350 * nHighPulses);
    digitalWrite(RCLpin, LOW);
    delayMicroseconds( 350 * nLowPulses);

Worked fine with one of those cheap 433Mhz modules from china!

Original code can be found at: http://code.google.com/p/rc-switch/source/browse/trunk/examples/TypeA_WithDIPSwitches_Lightweight/TypeA_WithDIPSwitches_Lightweight.ino



P.S. Germany: Funksteckdosen von http://www.pollin.de/shop/suchergebnis.html?S_TEXT=550666


Finally I managed to kind of “port” and run it thanks to the arduino.h-fix and some compiler options to get the error messages ignored. (lines 34-48)

See http://pastebin.com/BNS7ndLv




@Frido any experience with something similar for the Conrad FS20 System ? (auch gerne in Deutsch!)

Sorry. No. Seems far more complex!

Has anyone got this to work with the Web IDE?

Does anyone know af any UK sockets that will work with the ‘simple’ code at the top of the thread?

I don’t see why it wouldn’t work… looks pretty simple.

I tried Frido version, with the example in attached at the end of pastebin site.
unfortunately it is not working for me I get a bunch of errors.

In file included from ../inc/spark_wiring.h:30:0,
  from ../inc/application.h:31,
  from /433test.cpp:2:
 ../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
 /RCSwitch.cpp:33:15: error: 'RCSwitch' has not been declared

Is there anyone being able to import this as libery successfully please?

Thank you for your help


I just took my (raw!) paste bin source code, pasted in a new project on sparculator (aka “WEB-IDE”) and it compiled without any error!

BTW: Anybody may feel free to create a sparculator-library!!!

Output of arm-none-eabi-size:

text	 data	 bss	 dec	 hex
70832	3104	12548	86484	151

In a nutshell:
Flash used	73936 / 110592	66.9 %
RAM used	15652 / 20480	76.4 %

Thank you for your reply.
I just tried to copy paste all the raw in one single file and i can compile it.
I guess it was just the fact that I was splitting it to .h .cpp and ino… that is why!
anyway if someone understood how to port it to the library system… I’ll be more than happy to test it!!!

Sending it works perfectly, but if I would like to receive a signal… it does not work…

I used this code:

RCSwitch mySwitch = RCSwitch();

void setup() {

void loop() {
    if (mySwitch.available())
        int value = mySwitch.getReceivedValue();
        if (value == 0)
            Serial.print("Unknown encoding");
            Serial.print("Received ");
            Serial.print( mySwitch.getReceivedValue() );
            Serial.print(" / ");
            Serial.print( mySwitch.getReceivedBitlength() );
            Serial.print("bit ");
            Serial.print("Protocol: ");
            Serial.println( mySwitch.getReceivedProtocol() );

Am I missing something?
Thank you,

Hi dk,

I don’t know what kind of receiver module do you use, but if you use a 5 volt module this could by a problem on port D2.

In my code I also added

pinMode(Dx, INPUT);



and this works for me.

I hope this helps you.


Hi guys,

I’ve a working RCSwitch port for Spark here: https://github.com/suda/RCSwitch :smile: Tested both sending (using D0) and receiving (D3). ReceiveDemo_Advanced and SparkFunction examples contain some integration with Spark Cloud.

It’s also added to Community Libraries in web IDE.

Thanks to @wgbartley and @Frido for initial version of this port :slight_smile:


Awsome, @suda! Thanks for your work, I’ll definitely be adding this into my next project :smile:

1 Like

Thanks so much @suda! Works perfectly.

Hi @suda so I’ve completed a project using the RC-Switch library for original arduino, and I’m trying to use your library to get my photon working with my switches. The receive demo works fine but I can’t seem to use the send demo to transmit the codes. I’ve tried two brands of switches i have no problem contorlling from my arduino. Any photon specific issues?

Hmmm I must admit I haven’t tested it w/ Photon. Do you have two Particle devices or Particle+Arduino so you could try sending data from one to another?

My other Photon is tied up, I can see if I can get it back. I’ll PM you if I’m ready. Thanks for the assistance.

Anyone who cares, my issue is resolved. Thanks to @suda’s help I found that for the Photon the pulse length option needs to be enabled and set to 180 (ms). Although it doesn’t seem to work with my other switches. I wonder if I have to change the pulse length for different types of switches.

1 Like

That helped me greatly! Thank you for sharing!