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.


Continuing the discussion from Blynk + NodeMcu + Alexa device - Smart Home (need conect to Alexa):

!!! SOLVED !!!

I made conection between Alexa and Blynk via Node-Red applcation and it’s wornking perfectly
The commands sent from Alexa to Blynk are being executed by NodeMCU as planned.

I’m posting a print of Node-Red flows, just in case insteresting for anyone.

Thank you for all

If anyone is interested in using Node-Red with Blynk and Alexa then my advice would be not to adopt @cesarskt’s approach of using the HTTP request node to communicate with Blynk, but instead to use the Blynk ws contrib for Node-Red, to give properties two-way interaction between Blynk and Node-Red.

I’d also suggest not running Blynk code on the device(s) that you’re controlling, but to use MQTT for communication between the devices Node-Red, and use Node-Red as the bridge between Blynk and Node-Red.

It’s worth noting that there is currently no Node-Red support for the new Blynk.360 system.


Qué tal Cesar, quiero conectar Blynk a Alexa pero no e podido, ¿tienes alguien tutorial o video cómo puedo realizar?

Hey @Adan would you like to use IFTTT ?

The solution discussed here uses Node-Red.
The first thing to do is set-up a Node-Red server on your network and install the Blynk plug-in (contrib) for whatever version of Blynk you are using.
I’d also recommend setting-up the Mosquitto MQTT broker on the same server, and removing all Blynk code from your devices and using MQTT messages to control those devices.
Once you have that set-up and working then you can add-in the Alexa functionality.

I’ve recently migrated to the node-red-contrib-virtual-smart-home plug-in which is much easier to use and (so far) is much more reliable than the node-red-contrib-alexa-home-skill that I was using before.
This plug-in also allows a much wider range of device types to be used.


Estoy usando IFTTT para poder controlar Blynk con Alexa y así poder hacer uso de los pines GPIO del nodemcu, pero hasta el memento no lo e logrado, por eso necesito de ayuda

Qué tal Peter, tienes el código completo para el Arduino IDE que puedas compartir

O ¿algún video tutorial del que me pueda apoyar ? Sería de mucha ayuda.


@Adan as your question isn’t really related to the topic that you’ve posted in, I would suggest that you start another “need help with my project” topic and provide ALL of the information that is requested when you create that topic. You should also provide information about how you’ve set-up IFTTT and how you’ve configured your Alexa account settings.

If you are using Blynk IoT then you should provide information about the way you’ve configured the datastreams you are using.


Are you asking about code and support for MQTT communication between devices, setting-up a Node-Red server or something else?

One-line random questions don’t help us to help you.

But, as I said earlier, if you are wanting support for Alexa + IFTTT then you should start a new topic.


Olá que tal Adam.

I don’t speak spanish very well. But may we can undestand each other.

Yes guy. I did my SmartHome using Blynk app + Nodemcu, controlled by Alexa device.

It’s working about 1 year without any problem!

In the beginning of this topic, you’ll find how I connected boards to the Energy Frame.

I don’t use Node-red Local server. I’ve using it from a IBM Cloud service. In this way, Is no nedded keep your hipotetical server on, all the time.

After create an instance of Node-red in IBM cloud, you just need install a node for Alexa virtual device and link with your Blynk virtual pin.

I guess it’s better to use the blynk plugin instead of the http request.

Hello @John93
How are you.

May you clarify us Why Blynk Plugin is better?
Last year I ask a help here and didn’t have any any support. This way that I described, was the only one that I got success.

Some people here set focus in the structure of topic or question, but never solve anything

Hello @cesarskt I’m great thanks for asking.
I’m still a beginner in node-red, @PeteKnight can you explain this please ?