Using the Nodemcu V3 to Send 433mhz With Blynk

In this Instructable I will show how to control a socket with a build in code using a 433mhz transmitter and Blynk.

If you follow these steps you will be able to control multiple sockets by using the Blynk app for iOS and Android. You can turn sockets on/off and you can even use a timer along with them so you can, for example, turn on the coffee machine as soon as you wake up!

Step 1: The Necessary Items

For this tutorial you will need a couple of parts:

  • A NodeMCU v3 (or v2 for that matter) ($3 dollars)
  • A FS1000a 433mhz transmitter ($1 dollar)
  • Three female-female jumper wire ($1 dollar)
  • Controllable sockets that use a default code ($5 to $10 dollars)
  • An iOS or Android device with the Blynk app running on it.

Total cost: $10-$20 dollars

Step 2: Setting Up the Remote

In this tutorial we are using sockets and a remote with a default code which you can change. If you remove the bottom from the remote you will see 5 numbers with sliders which you can turn on (up) or off (down).

Pick a code which is random and can't be used by, for example, your neighbours who use the same code.

For this tutorial we are using the code: up, down, down, down, down which translates to 10000.

Step 3: Setting Up the Sockets

In the previous step we used the code 10000 for the remote. We now have to use this code on the sockets as well.

On the backside of the socket there is a little flap which you can pull away. Under this flap there are 10 numbers. The first 5 are the code for the remote (so up, down, down, down, down) and the next 5 digits (and in some cases letters) can be put in randomly, to your liking. Make sure every socket has a unique code. In this particular case my socket has code 10000 as well. This translates to 10000 for the remote, and 10000 for the socket. Your next socket could, for example, be 01000 (which translates to down, up, down, down down) etc. Remember these numbers so we can use them later on.

Step 4: Connecting the NodeMCU to the 433mhz Transmitter

Because we are only transmitting, and not receiving, we only need to use a transmitter which we can connect to the NodeMCU really easily, without having to use a breadboard.

Take three female-female wires and connect the wires as followed:

GND (Transmitter) -> G (NodeMCU)

VCC (Transmitter) -> 3V (NodeMCU)

DATA (Transmitter) -> D4 (NodeMCU)

Step 5: Setting Up the Code.

Arduino IDE

Connect the NodeMCU to your computer using a Micro USB cable. The next step is downloading the Arduino IDE (https://www.arduino.cc/en/main/software).

As soon as that is installed, open up the Arduino IDE and create a new file.

Go to the top of program, and select 'tools' in the menu bar. Make sure that you select the right board (WeMos D1 R2 & Mini) and the correct port (in my case it is COM3).

The next step is downloading the Blynk library (https://github.com/blynkkk/blynk-library/releases/ and installing that manually by dropping in the libaries and tools from the library in to your sketch folder (usually located at c:\Users\username\Documents\Arduino\).

Next up is downloading the RCSwitch library (https://github.com/sui77/rc-switch) and and installing that manually by dropping in the libaries and tools from the RCSwitch library in to your sketch folder (usually located at c:\Users\username\Documents\Arduino\).

Blynk

Grab your iOS or Android device and go to the Appstore or Playstore and download the Blynk application. As soon as you are in the App, create a new project. After you have done this you will receive an Auth code in your mailbox.

Back to Arduino IDE

Paste the following code in the file created in Arduino IDE.

#include <ESP8266WiFi.h>
#include <RCSwitch.h>
#include <BlynkSimpleEsp8266.h>

//******************************************************************
//  Defines     
//******************************************************************


char* housecode = "10000";
char* socketcode1 = "10000";
char* socketcode2 = "01000";
char* socketcode3 = "00100";
char* socketcode4 = "00010";
char* socketcode5 = "00001";

//******************************************************************
//   Create Class-Objects    
//******************************************************************


RCSwitch mySwitch = RCSwitch();


//******************************************************************
//  Global Variables     
//******************************************************************


const char* blynk_auth_token = "your-auth-code"; 
const char* ssid     = "Wifi-SSID";
const char* password = "Wifi-PASSWORD";

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(".");
  }
  
 digitalWrite(LED_BUILTIN, HIGH);

  Serial.println("WiFi connected");  
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP()); 
  
  
}

//******************************************************************
//       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
//******************************************************************

BLYNK_WRITE(V0)
{
 if(param.asInt()){  
    mySwitch.switchOn(housecode, socketcode1);
    digitalWrite(LED_BUILTIN, LOW);
  } 
  else {
mySwitch.switchOff(housecode, socketcode1);
  digitalWrite(LED_BUILTIN, HIGH);
  }
}

BLYNK_WRITE(V1)
{
 if(param.asInt()){  
    mySwitch.switchOn(housecode, socketcode2);
    digitalWrite(LED_BUILTIN, LOW);
  } 
  else {
mySwitch.switchOff(housecode, socketcode2);
digitalWrite(LED_BUILTIN, HIGH);
  }
}

BLYNK_WRITE(V2)
{
 if(param.asInt()){  
    mySwitch.switchOn(housecode, socketcode3);
    digitalWrite(LED_BUILTIN, LOW);
  } 
  else {
mySwitch.switchOff(housecode, socketcode3);
digitalWrite(LED_BUILTIN, HIGH);
  }
}

BLYNK_WRITE(V3)
{
 if(param.asInt()){  
    mySwitch.switchOn(housecode, socketcode4);
    digitalWrite(LED_BUILTIN, LOW);
  } 
  else {
mySwitch.switchOff(housecode, socketcode4);
digitalWrite(LED_BUILTIN, HIGH);
  }
}

BLYNK_WRITE(V4)
{
 if(param.asInt()){  
    mySwitch.switchOn(housecode, socketcode5);
    digitalWrite(LED_BUILTIN, LOW);
  } 
  else {
mySwitch.switchOff(housecode, socketcode5);
digitalWrite(LED_BUILTIN, HIGH);
  }
}

//******************************************************************
//        Endless Loop (main() function)
//******************************************************************


void loop() {
  if(BlynkConExist){
    Blynk.run();
  }
}

Make sure you edit the following lines:

  • char* housecode = "10000";
  • char* socketcode1 = "10000";
  • char* socketcode2 = "01000";
  • char* socketcode3 = "00100";
  • char* socketcode4 = "00010";
  • char* socketcode5 = "00001";
  • const char* blynk_auth_token = "your-auth-code";
  • const char* ssid = "Wifi-SSID";
  • const char* password = "Wifi-PASSWORD";

The final step is uploading the sketch to your NodeMCU by clicking on the 'upload' button in the Arduino IDE.

Step 6: Setting Up the Blynk App.

If you have done all steps correctly, and the sketch is succesfully uploaded to your NodeMCU you should see your NodeMCU online in the Blynk App.

Add some buttons to your dashboard, and use V0 for socket 1, V1 for socket 2 etc. Make sure the buttons are set on 'switch'.

The final check: connect your sockets to an outlet and tap on one of the buttons. They should turn on!

I hope you learnt a bit from this tutorial, and if you have any questions please ask them and I will help you out!

Share

    Recommendations

    • Sweet Treats Challenge

      Sweet Treats Challenge
    • Remix Contest

      Remix Contest
    • Warm and Fuzzy Contest

      Warm and Fuzzy Contest

    2 Discussions