ArduinoMEGA2560, NodeMCU & Blynk to wirelessly control digital outputs

Hi Arduino community,

I’ve read the rules, this is my first forum post and attempt at coding so sorry for any misunderstandings off the bat.

I was hoping that I could have someone with some experience run their eye over the code for this project, because when I press the buttons in the ‘Blynk’ app, nothing happens. When running the serial monitor, there’s also no data visible.

I’m trying to power 5 relays (So far) using the ‘Blynk’ app, an ArduinoMEGA 2560 (For all its I/O) and a NodeMCU (To connect the app with the MEGA).

Circuit diagram attached.

I’ve proved everything from the digital pins on the ArduinoMEGA by setting the pins to output individually in the code, successfully. Just can’t seem to activate the pins using the NodeMCU & ‘Blynk’.

Here’s the code for the MEGA:

[code]
#include <SoftwareSerial.h>

SoftwareSerial nodemcu(2, 3);
long int data;
int ONOFF = 23;
int OPEN = 22;
int CLOSE = 24;
int INOUT = 25;
int AUTO = 26;

void setup() {
  // put your setup code here, to run once:

  Serial.begin(9600);
  nodemcu.begin(9600);
  pinMode(ONOFF, OUTPUT);
  pinMode(OPEN, OUTPUT);
  pinMode(CLOSE, OUTPUT);
  pinMode(INOUT, OUTPUT);
  pinMode(AUTO, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:

  if (nodemcu.available() > 0)
  {
    data = nodemcu.parseInt();
    delay(100);
    Serial.println(data);

    //ONOFF
    if (data = 1)
    {
      digitalWrite(ONOFF, LOW);
    }
    if (data = 2)
    {
      digitalWrite(ONOFF, HIGH);
    }

    //OPEN
    if (data = 3)
    {
      digitalWrite(OPEN, LOW);
    }
    if (data = 4)
    {
      digitalWrite(OPEN, HIGH);
    }

    //CLOSE
    if (data = 5)
    {
      digitalWrite(CLOSE, LOW);
    }
    if (data = 6)
    {
      digitalWrite(CLOSE, HIGH);
    }

    //INOUT
    if (data = 7)
    {
      digitalWrite(INOUT, LOW);
    }
    if (data = 8)
    {
      digitalWrite(INOUT, HIGH);
    }

    //AUTO
    if (data = 9)
    {
      digitalWrite(AUTO, LOW);
    }
    if (data = 10)
    {
      digitalWrite(AUTO, HIGH);
    }
  }
}

[/code]

And Here’s the code for the NodeMCU:

[code]
#define BLYNK_PRINT Serial

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

SoftwareSerial arduinoMega(2, 3); // Connect NodeMCU with pins 2 & 3 of Arduino.

int pinValue1;
int pinValue2;
int pinValue3;
int pinValue4;
int pinValue5;

char auth[] = "My auth token is definitely correct";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "My WiFi";
char pass[] = "My Password";

// Blynk app writes values to Virtual Pin 1.
BLYNK_WRITE(V1)
{
  pinValue1 = param.asInt(); // Assigning incoming value from pin V1 to a variable.
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Device1 (v1): ");
  Serial.println(pinValue1);
  // send value to arduino
  arduinoMega.print(pinValue1);
}

// Blynk app writes values to Virtual Pin 2.
BLYNK_WRITE(V2)
{
  pinValue2 = param.asInt(); // Assigning incoming value from pin V2 to a variable.
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Device2 (v2): ");
  Serial.println(pinValue2);
  // send value to arduino
  arduinoMega.print(pinValue2);
}

// Blynk app writes values to Virtual Pin 3.
BLYNK_WRITE(V3)
{
  pinValue3 = param.asInt(); // Assigning incoming value from pin V3 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Device3 (v3): ");
  Serial.println(pinValue3);
  // send value to arduino
  arduinoMega.print(pinValue3);
}

// Blynk app writes values to Virtual Pin 4.
BLYNK_WRITE(V4)
{
  pinValue4 = param.asInt(); // Assigning incoming value from pin V4 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Device4 (v4): ");
  Serial.println(pinValue4);
  // send value to arduino
  arduinoMega.print(pinValue4);
}

// Blynk app writes values to Virtual Pin 5.
BLYNK_WRITE(V5)
{
  pinValue5 = param.asInt(); // Assigning incoming value from pin V5 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  Serial.print("Device5 (v5): ");
  Serial.println(pinValue5);
  // send value to arduino
  arduinoMega.print(pinValue5);
}
void setup() {
  // put your setup code here, to run once:

  //Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  // Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  // Blynk.begin(auth, ssid, pass, IPAddress(192.168.1.100), 8080);
}

void loop() {
  // put your main code here, to run repeatedly:

  Blynk.run();
}

[/code]

I’m pulling my hair out

Update

The serial monitor is showing the following now that I moved the Tx & Rx function to digital pins 2 & 3 on both the ArduinoMEGA and the NodeMCU. When I press the buttons, still no activation of the digital pins on the MEGA though.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.