Control your 433Mhz RF Sockets via Internet by ESP8266 and Blynk App

My former setup to control 433Mhz RF sockets over the internet was realized with a RaspberryPi (GPIO Control Software + HTTP Server) and one cheap FSA1000a 433Mhz Sender. Since I had one unused ESP8266-01 (the small one with just 2 GPIO’s) it was crystal clear for me: “Time to change from Raspberry to another setup”. I muss admit, RaspberryPi was overpowered for this task. In german we say: “shoot at sparrows with Cannons”. But the project was build long time before ESP8266 was overrunning the IoT market.

Hardware you will need for the setup:

    1. ESP8266-01 Board
    1. USB/Serial Converter
    1. FSA1000a Sender
    1. 2.54mm pitch prototyping PCB
    1. Jumper
    1. USB Power Supply
    1. 433Mhz Antenna – an isolated wire with a length of 17.34cm
    x. Wires and Pin headers

Wire you setup based on this schematic:
ESP8266-01 - FSA1000a - FTDI Pinout

Software you will need for the setup:

Blynk App for Android
Blynk App for Apple Phones
ESP8266 Support Drivers for Arduino IDE
RCSwitch Library for Arduino IDE
Blynk Library for Arduino IDE

Blynk setup

Download and setup the Blynk App. After the installation create a new account using your email address. Sign in to be able to create a new project.As a new user you will receive free Energy Balance which you will need to invest in user interface items. Name the project, select the Hardware (ESP8266) and generate your Auth token. When you have accomplished the project setup, proceed with creating the User Interface:

IOT Blynk 433Mhz RC Switch User Interface

Add eight Buttons V0 – V7 based on my screenshot, Add a Push widget, and optionally two LED’s and two timers. Choose buttons names and colors based on your taste 🙂 Both timers can be used for scheduled control e.g. to turn the coffee machine each morning on and turn the light each night on a certain time off. The LED’s are showing the state of timer control.

Getting started with programming
First of all you will need ESP8266 support packages for your Arduino IDE. If this package is not installed on your PC take following steps:
Select menu File > Preferences > Additional Boards Manager URLs and add this line:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Programming the ESP8266
Select board "ESP8266 Generic Module" in your Arduino IDE and set the Upload speed to 115200 baud. Now set the jumper and connect the board to your PC via USB cable. Choose the Port of your FTDI/Serial converter board.

Create new sketch, copy the code listed below and set following variables and defines:

const char* blynk_auth_token = "xxxxxx"; // will be generated by your Blynk App
const char* ssid = "MyWIFI-NetworkName"; // Your WiFi Network Name
const char* password = "MyWIFI-NetworkPass"; // WiFi Password

To get RC Codes for you RF Sockets, search internet for your RF Socket manufacturer or use this instruction how to read out RC Codes from your controller.
Change following define values to your’s:

#define PACKET_LENGTH 24
#define SWITCH_1_ON 7721996
#define SWITCH_1_OFF 7721987
#define SWITCH_2_ON 7697420
#define SWITCH_2_OFF 7697411
#define SWITCH_3_ON 7691276
#define SWITCH_3_OFF 7691267

Compile the project sketch. After the project was successful compiled make sure the jumper connection on ESP8266 between GND and GPIO0 is set. This jumper connection is needed to set the ESP8266 into the bootloader mode while power on. After the upload remove the jumper and power-cycle the setup (disconnect and connect the USB cable).

Now the setup shall go online and you mobile phone receive the Blynk push message: RC433: is now online

Arduino sketch to control 433Mhz RF Sockets

#include 
#include 
#include 
#include 

//******************************************************************
//  Defines     
//******************************************************************
// 433Mhz Settings
#define PACKET_LENGTH 24

#define SWITCH_1_ON   7721996
#define SWITCH_1_OFF  7721987
   
#define SWITCH_2_ON   7697420
#define SWITCH_2_OFF  7697411
   
#define SWITCH_3_ON   7691276
#define SWITCH_3_OFF  7691267 

//******************************************************************
//   Create Class-Objects    
//******************************************************************
RCSwitch mySwitch = RCSwitch();
WidgetLED led1(V10); //register to virtual pin 1
WidgetLED led2(V11); //register to virtual pin 1
SimpleTimer timer;

//******************************************************************
//  Global Variables     
//******************************************************************
const char* blynk_auth_token = "xxxxxx"; 
const char* ssid     = "MyWIFI-NetworkName";
const char* password = "MyWIFI-NetworkPass";

bool BlynkConExist = false;

//******************************************************************
//  Setup Function    
//******************************************************************
void setup()
{
  // work arround for a bug, to disable access point... 
  WiFi.persistent(false);  

  // Initialize RCSwitch and select Pin which is used for sending the data
  mySwitch.enableTransmit(2);
  Serial.begin(9600);

  // Initialize Blynk connection
  Blynk.begin(blynk_auth_token, ssid, password); 
  Blynk.connect();

  // waint until WiFi becomes connected 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  
  // Set initial LED States
  led1.off();
  led2.off();

  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP()); 
  
  // check every 10 seconds if still connected
  timer.setInterval(10000L, CheckConnection); 
  
}

//******************************************************************
//       Check WiFi Connection and try to establish if disconnected
//******************************************************************
void CheckConnection(){

  // Check if connected and the Flag Value, Set connected Flag is connected
  if (Blynk.connected() && (BlynkConExist == false) ) {
    BlynkConExist = true;
    Blynk.notify("RC433: is now online");
  }
  // Reset connected Flag if not connected
  if (!(Blynk.connected()) && (BlynkConExist == true) ) {
    BlynkConExist = false;
  }
  
  if(!BlynkConExist){
    Blynk.connect(40000);  // 40000 ~ 10Sec timeout
  }
}

//******************************************************************
//        Turn once Switches ON/OFF
//******************************************************************
//### Action for Virtual Pin 0:     Switch 1 ON
BLYNK_WRITE(0) {  
 mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 1:     Switch 1 OFF
BLYNK_WRITE(1) {
  mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
}

//### Action for Virtual Pin 2:     Switch 2 ON
BLYNK_WRITE(2) { 
  mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 3:     Switch 2 OFF
BLYNK_WRITE(3) {
   mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
}

//### Action for Virtual Pin 4:     Switch 3 ON
BLYNK_WRITE(4) {
  mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 5:     Switch 3 OFF
BLYNK_WRITE(5) {
   mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
}

//******************************************************************
//      Turn all Switches ON or OFF
//******************************************************************
//### Action for Virtual Pin 6:     All ON
BLYNK_WRITE(6) {
   mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
   delay(100);
   mySwitch.send(SWITCH_2_ON, PACKET_LENGTH);
   delay(100);
   mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
}

//### Action for Virtual Pin 7:     All OFF
BLYNK_WRITE(7) {
    mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
    delay(100);
    mySwitch.send(SWITCH_2_OFF, PACKET_LENGTH);
    delay(100);
    mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
}
//******************************************************************
//        Timer Controlled ON/OFF Operation on Switch 1 and 3
//******************************************************************
//### Timer 1: Turn Switch 1 ON than OFF
BLYNK_WRITE(8)
{
  if(param.asInt() == 1) {
    mySwitch.send(SWITCH_1_ON, PACKET_LENGTH);
    led1.on();
    Blynk.notify("RC433: Timer controlled Switch 1 is now ON");
  }
  else {
    mySwitch.send(SWITCH_1_OFF, PACKET_LENGTH);
    led1.off();
    Blynk.notify("RC433: Timer controlled Switch 1 is now OFF");
  }
}
//### Timer 2: Turn Switch 3 ON than OFF
BLYNK_WRITE(9)
{
  if(param.asInt() == 1) {
    mySwitch.send(SWITCH_3_ON, PACKET_LENGTH);
    Blynk.notify("RC433: Timer controlled Switch 3 is now ON");
    led2.on();
  }
  else {
    mySwitch.send(SWITCH_3_OFF, PACKET_LENGTH);
    Blynk.notify("RC433: Timer controlled Switch 3 is now OFF");
    led2.off();
  }
}
//******************************************************************
//        Endless Loop (main() function)
//******************************************************************
void loop() {
  if(BlynkConExist){
    Blynk.run();
  }
  timer.run();
}

Click to rate this post!
[Total: 10 Average: 4]

One thought on “Control your 433Mhz RF Sockets via Internet by ESP8266 and Blynk App”

  1. Really great project. Will the above code work with the ESP8266 12E? I’ve tried it but no success.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.