Menu Close

Blynk for NodeMCU – Time Scheduled Switching

This tutorial of Robo India is to make Time Scheduled Electric Switch which switches High/Low at times which we set in Blynk App.

1. Introduction:

When we are not at home for some days, we think of having some device that could switch ON/OFF (or any other important appliance)for some hours during the day. Today, we are going to make such Time Scheduled Electric Switch which switches ON/OFF at times which we set the in our Blynk App

.1.2 Hardware required
Blynk Board and NodeMCU is used in this example. Inset NodeMCU to the Blynk board as shown in the image ahead then connect NodeMCU to PC or Laptop through USB cable.

2. On Blynk App

You need to perform following steps on Blynk App.

2.1 Create a new project and give it name Time Scheduled and then Select device “NodeMCU” and connectivity WiFi.

2.2 Tap on the screen and add the Eventor widget to the screen.

2.3 Tap on the Eventor widget and Click add new event. Select Time button and CHOOSE DAYS OF THE WEEK and START AT time and TIME ZONE. Then tap on OK. Then Turn ON to pin D1 and also add Send Notification and write “Device is ON”

2.4 Same way create a new event and select START time that will Switch OFF the relay. Then Turn OFF to pin D1 and also add Send Notification and write “Device is OFF” 

2.5 Add Notification widget to get Notification.

2.6 Now, select a button widget and add D1 pin as we have connected our relay to PIN D1 of NodeMCU. Tap OK to finalize your Start Event.

3. Code the NodeMCU with the following code.

Before uploading, make sure to paste your authorization token into the auth [] variable. Also make sure to load your Wifi network settings into the Blynk.begin(auth, “ssid”, “pass”) function.

Following code may be downloaded from here.

// Robo India Tutorials
// Hardware: NodeMCU & BlynkBoard (by RoboIndia) 
// simple Code for Time Scheduled Switch
  
#define BLYNK_PRINT Serial


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

char auth[] = "Your auth. key";       // You should get Auth Token in the Blynk App.
const int R = 5;                      // Relay 1 of BlynkBoard Conneted with D1(GPIO 05) pin of NodeMCU
char ssid[] = "Your network name";    // Your WiFi credentials.
char pass[] = "Your Password";        // Set password to "" for open networks.

void setup()
  {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(R,OUTPUT);
  }
  
void loop()
  {
  Blynk.run();
  }


4. Upload and Play

After connecting NodeMCU with BlynkBoard, Upload the Arduino IDE code. Make sure to write proper Auth Key, SSID and Password of the network in the Code. After Uploading the code, tap on the Play Button of Blynk App. And we are done.

5. Output

If you have any query please write us at support@roboindia.com

Thanks and Regards
Content Development Team 
Robo India
https://roboindia.com


Leave a Reply