Blynk + NodeMcu + Alexa device - Smart Home (need conect to Alexa)

• Hello my friends. Please note I’m handled this project of SMART HOME. I’m looking for control all relays also over alexa’s voice commands and for now, I didn’t find any solution for this.
I ask you kindly to help me with an amend or complement of IDE code to implement this new functions, whit no spoil current OTA, Clock and Blynk functions
• Actually hardware conections and comunicattion/interaction between Blynk <-> hardware are working perfectly.

Details :
• NodeMcu (ESP8266) + Relay 16 Channels + Amazon Echo-Dot with Alexa.
• Wi-Fi communication type over NodeMcu.
• Smartphone OS (iOS or Android)
• Blynk server
• Blynk Library version 0.6.0

#include <ArduinoOTA.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266mDNS.h>
#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <NTPClient.h>
#include <WidgetRTC.h>
#include <WiFiUdp.h>

#define LUZSALA 16                                                                                //DEFINE A NAME FOR PIN D0
#define TOMADASALA 5                                                                              //DEFINE A NAME FOR PIN D1
#define LUZQUARTOS 4                                                                              //DEFINE A NAME FOR PINO D2
#define TOMADASUITE 0                                                                             //DEFINE A NAME FOR PIN D3
#define TOMADAQUARTO 2                                                                            //DEFINE A NAME FOR PINO D4
#define LUZCOZINHA 14                                                                             //DEFINE A NAME FOR PIN D5
#define TOMADACOZINHA 13                                                                          //DEFINE A NAME FOR PIN D7

#define BLYNK_PRINT Serial

NTPClient timeClient(ntpUDP, "");                                                     //DECLARE THE GLOBAL TIME SERVER
BlynkTimer timer;
WidgetRTC rtc;
WidgetTerminal terminal(V0);                                                                      //DEFINE BLYNK VIRTUAL PIN V1 TO TERMINAL DISPLAY USED ON APP

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";                                                 //BLYNK AUTHORIZATION TOKEN 
char ssid[] = "xxxxxxxxxxxxxxxxx";                                                                 //SET LOCAL WI-FI SSID (service set identifier)
char pass[] = "xxxxxxxxxxx";                                                                        //SET LOCAL WI-FI PASSWORD
String displaycurrenttimepluswifi;                                                                //VARIABLE TYPE STRING TO SHOWS IN DISPLAY TERMINAL AT BLYNK APP
int wifisignal, manual, hora, minuto;                                                             //VARIABLES TYPE STRING TO STORE CURRENT TIME, WI-FI SIGNAL, MANUAL/AUTOMATIC MODE, HOUR AND MINUTE

void setup(){
  pinMode(LUZSALA,  OUTPUT);                                                                      //DEFINE PIN AS OUTPUT 
  pinMode(TOMADASALA,  OUTPUT);                                                                   //DEFINE PIN AS OUTPUT 
  pinMode(TOMADAQUARTO, OUTPUT);                                                                  //DEFINE PIN AS OUTPUT 
  pinMode(TOMADASUITE, OUTPUT);                                                                   //DEFINE PIN AS OUTPUT 
  pinMode(LUZQUARTOS,  OUTPUT);                                                                   //DEFINE PIN AS OUTPUT 
  pinMode(LUZCOZINHA, OUTPUT);                                                                    //DEFINE PIN AS OUTPUT  
  pinMode(TOMADACOZINHA,  OUTPUT);                                                                //DEFINE PIN AS OUTPUT  

  Blynk.begin(auth, ssid, pass);                                                                  //CALL/START CONECTION WITH BLYNK SERVER 
  //Blynk.begin(auth, ssid, pass, "", 80);                                         //CALL/START CONECTION WITH BLYNK SERVER 
  Blynk.syncAll();                                                                                //SINCRONIZATION WITH BLYNK SERVER
  ArduinoOTA.onStart([]() {
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_SPIFFS
      type = "filesystem";
    // NOTE: if updating SPIFFS this would be the place to unmount SPIFFS using SPIFFS.end()
    Serial.println("Start updating " + type);
  ArduinoOTA.onEnd([]() {
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) {
      Serial.println("Auth Failed");
    } else if (error == OTA_BEGIN_ERROR) {
      Serial.println("Begin Failed");
    } else if (error == OTA_CONNECT_ERROR) {
      Serial.println("Connect Failed");
    } else if (error == OTA_RECEIVE_ERROR) {
      Serial.println("Receive Failed");
    } else if (error == OTA_END_ERROR) {
      Serial.println("End Failed");
  ArduinoOTA.begin();                                                                                //SINCRONIZATION WITH BLYNK SERVER
  Serial.print("IP address: ");

  ModoAutomatico();                                                                                  //CALL FUNCTION TO SET MANUAL E/OU AUTOMATIC MODE OVER APP (function in a secundary sketch)
int mytimeout = millis() / 1000;
  while (Blynk.connect() == false) {                                                                  //TRY TO CONECT TO SERVER FOR 10 SECONDS
    if((millis() / 1000) > mytimeout + 8){                                                            //TRY LOCAL SERVER IF NOT CONECT WITHIN 9 SECONDS
  timer.setInterval(1000L, clockvalue);                                                               //UPDATE EVERY 1s VALUE FOR TIME (function in a secundary sketch)
  timer.setInterval(5000L, sendWifi);                                                                 //UPDATE EVERY 5s WI-FI SIGNAL
  timer.setInterval(1800000L, ModoAutomatico);                                                        //CHECK EVERY 30m IF IT IS STIL IN AUTOMATIC MODE (function in a secundary sketch)
  rtc.begin();                                                                                        //CALL/START CLOCK PROPETIES
  timeClient.begin();                                                                                 //CALL/START CLOCK PROPETIES
  timeClient.setTimeOffset(-3600*3);                                                                  //SET CLOCK WITH TIME ZONE (Bazil)

  acende_tudo();                                                                                      //CALL FUNCTION TO TURN ON ALL SWITCHES OR RELAYS OR LIGHTS BULB (function in a secundary sketch)
  void sendWifi() {                                                                                  //FUNCTION TO GET WI-FI SIGNAL INFO 
  wifisignal = map(WiFi.RSSI(), -105, -40, 0, 100);
void loop(){
  ArduinoOTA.handle();                                                                               //CALL OTA FUNCTION TO UPLOAD SKETCHES FROM ARDUINO-IDE TO THE BOARD (NodeMcu) OVER WI-FI;                                                                                       //CALL BLYNK APPLICATION;                                                                                       //CALL TIMER FUNCTION

Thanks in advance
Best regards[date=2021-05-01 timezone=“America/Sao_Paulo”]IMG_2942


The NodeMCU doesn’t have enough pins to control a 16 channel relay.

If you want to use Alexa then the first thing you should do is to move from using digital pins in your app to using virtual pins.
You could then use IFTTT or Sinric to give your Alexa integration. However, my preferred approach is to use Node-Red and MQTT.


Hello Pete,
I hope you’re fine.

I apreciatted a lot

for your prompt reply.

Actually I bought this relay with 16ch, because I want to use at least 11digital pins os nodeMcu.
My Sketch has anoter “tabs” with handle of virtual pins. On my Blynk App I handle just virtual pins as you suggested. Thank you for this.

I signed and tried use Sinric Pro and IFTTT to integrate with alexa, but I couldn’t. It didn’t work. Probably still due my lack of expertise.

I’ll learn about Node-Red and MQTT untill now, but if you and/or another friends could help with codes and procedures, I’ll Thank you a lot.

Kind regards my friend

Well, your code doesn’t contain any BLYNK_WRITE(vPin), so I don’t see how it can work at the moment.

The NodeMCU doesn’t have enough suitable pins for that.

You should read this:

You either need to use an ESP32, or a NodeMCU plus a port expander such as the MCP23017…


1 Like

Very nice option you have been using. I’ll study about this

Im my case. the quantity of pin I use right now, sound good for my house.
As per I toold you. It’s working perfectly for now since last week.
I just need to integrate with alexa for voice commands

But according to your photos, you are only using 7 pins now rather than the “at least 11” that you say you need.

So what you are saying about existing functionality doesn’t align with what you’ve said about the number of pins currently being used, and the use of virtual pins in your app/sketch compared to the code you’ve posted.

Also, you appear to be powering your relay board from the 3v pin on your NodeMCU, which isn’t going to work long term.

I’d also be extremely concerned about the gauge of wire that you’ve used to wire the ‘hot’ side of the relays, and the ‘daisy chain’ method that you’ve used for this. Bear in mind that the first piece of wire in this daisy chain carries the combined current of all the circuits that are chained off of this.

I think I’m going to take a step back from this topic, as you don’t seem particularly interested in heeding the advice I’ve offered so far regarding NodeMCU pins, and I have serious doubts about your mains wiring competency and I don’t want to be associated with what may happen as a result.