Loading... Please wait...

Using a 433Mhz transmitter to control an AC Mains Switch

Using a 433Mhz transmitter to control an AC Mains Switch

This example shows how to use a 433Mhz Transmitter/Receiver as supplied in the oddWires Pro kit and above to control a wireless AC Mains Switch. It uses the RCSwitch library available here.

Hardware Required

  • Arduino Board
  • 433Mhz Transmitter/Receiver pair
  • Male-Female jumper wires


To build the circuit connect transmitter Vcc to +5V, GND to GND and DATA to Arduino pin 10. On the second Arduino connect Vcc to +5V, GND to GND and DATA to pin 2. You can solder a short (around 10 in) wire to the antenna holes in each device. For very short distances this is not necessary.




Receiver Code

Use this code to determine what signal is being sent by the transmitter supplied with your AC Switch. You are going to record the code, the bit length and the pulse length. Those three parameters are then used in the transmit sketch to control the switch.

  Example for receiving
  If you want to visualize a telegram copy the raw data and
  paste it into http://test.sui.li/oszi/


RCSwitch mySwitch = RCSwitch();

void setup() {
  mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2

void loop() {
  if (mySwitch.available()) {
    output(mySwitch.getReceivedValue(), mySwitch.getReceivedBitlength(), mySwitch.getReceivedDelay(), mySwitch.getReceivedRawdata(),mySwitch.getReceivedProtocol());

Transmitter Code

This sketch shows how to switch the AC mains switch on/off every 5 seconds. You must set the three parameters from the receive sketch.

#include            // requires the RCSwitch library

RCSwitch mySwitch = RCSwitch(); // declare the switch

#define TRANSMITPIN 10  // Using Arduino Pin 10 to transmit

// Find the three values for your switch by using the Advanced Receieve sketch
// Supplied with the RCSwitch library

#define RCCODE 1397763  // This is one of the codes for a BH9936 AC Mains switch (USA)
#define BITLENGTH 24    // And the bitlength is 24
#define PULSELENGTH 166 // Amd the pulse length in microseconds is 166

void setup() {
  mySwitch.enableTransmit(TRANSMITPIN);  // enable transmission
  mySwitch.setPulseLength(PULSELENGTH);  // set the pulse length

void loop() {
  mySwitch.send(RCCODE, BITLENGTH); // Turn switch on/off
  delay(5000);                      // delay 5 seconds



What's News


Copyright 2019 oddWires. All Rights Reserved.
 Sitemap | oddWires