About Arduino Mega 2560 with ESP8266-01 using Blynk.cloud Console

The idea behind the project is – the user is able to turn off and on the relay through a button hardwired to the chassis and through the Blynk app –

I’m currently working on a project that deals with multiple relays and servo motors as actuators. I was working with NodeMCU and Blynk Legacy for a while but later realized that I was going to be short on pins, as I need about at least 12 pins which the board couldn’t provide then I opted to use Mega 2560 with ESP8266-01 as Wi-Fi shield.

While configuring the console, I noticed that there is no option for Mega 2560, as well as the pins while configuring “Datastreams”:

I’m quite stuck here as I really do not know how I will be able to control the state of the relays without using the correct Digital pins. The only available pins in the “Digita Datastream” are pins from Arduino Uno (13 Digital Pins, 5 Analog Pins).

Is there anyway I can use the Arduino Mega pins despite being limited on “pins” in the Blynk.cloud console? Thank you!


These are the pins connected to the Arduino Mega:

const int RELAY_PIN  = 22;
const int RELAY2_PIN  = 23;
const int RELAY3_PIN  = 24;
const int RELAY4_PIN  = 25;

#define trig 32
#define echo 33
#define triggerpin2 34
#define echopin2 35

const int BUTTON_PIN = 42;
const int BUTTON2_PIN = 43;
const int BUTTON3_PIN = 44;
const int BUTTON4_PIN = 45;

I will just suggest you solutions but really not sure of it
first solution is to use esp32 instead of Arduino Mega as it gives you more pins .
second solution is to try to use the given pins (13 and 5 analogue) and check if that will work with the Mega and if also if these all pins can work as digital , give it a try .
Regards

That’s an awful choice, far better to go for an ESP32 or something like this…

or this…

Also, don’t use digital pins, use virtual pins instead…

Pete.

2 Likes

Thanks for replying. As for the suggestions…

a) The 13 pins of the Mega are already occupied with other modules (RTC, Esp8266-01 and Servo motors). To be precise, my pin configurations are:

  1. Esp8266-01 [Pin 2, 3]
  2. RTC [Pin 5, 6, 7]
  3. Servo motors [Pin 8, 9, 10, 11]
  • this leaves me no choice but to use other digital pins on the Arduino Mega

b) I could try using an Esp32, but I might encounter a similar problem with me using a NodeMCU. The problem was that the GPIO on the NodeMCU was very limited and some of the modules I’m using are malfunctioning due to the nature of the board.

Thanks for the suggestions. As to why I’m using digital pins over virtual pins is because the device I’m working on has physical buttons placed on it.

This is the fritzing of the project in question:


this is with the old layout using the nodemcu

This is the code to control the state of the relay using the said buttons.

void loop()
{
 lastButtonState = currentButtonState;
 
 currentButtonState = digitalRead(BUTTON_PIN);

  if (lastButtonState == HIGH && currentButtonState == LOW) {
      relayState = !relayState;
      digitalWrite(RELAY_PIN, relayState);
   }
}

The button basically acts as a switch to turn off and on the relay and allow the servo to move. I guess what I’m trying to say is that, would it be possible to control the relay using the physical button and the virtual button from Blynk.

edit: I was able to use the physical buttons and the virtual buttons on the Blynk Legacy, but I opted to use the 2.0 because of the events feature for the sensor I’m using.

Yes, most of my devices also have physical switches attached to them, but I never use digital pins in Blynk.

You shouldn’t put that stuff in your void loop when working with Blynk.
You should either use a timer to pill your physical switch, or attach an interrupt to it and use debounce code.

Yes, that’s a sketch builder example to do just that…

Very strange!

Pete.