Wireless Firework Control Via Blynk and Relays

I currently have ordered a 32-Channel SPDT Relay Shield with IoT Interface, ESP32 IoT WiFi BLE Module with USB and currently I am trying to figure out how exactly I will have them communicate. I planned on using Blynk and ESP32 as a way to control the board Via Smartphone.

Everything to me here is brand new so any help would more than Welcome :grin:

Hi,

I will work on putting together a demo app for you. It will be a starter firmware that will show you everything you need to know to develop this into exactly what you want.

First you’re going to want to download and install Atom.io here:
https://atom.io

Once you have Atom installed and go to install packages. I work on Mac so if you’re on Windows I can’t exactly explain how you would do that. You can google Atom install package and I’m sure they’ll have documentation. You’ll want to install the Platformio package. Once it’s installed go into the Platformio home on Atom. Click on Platforms and install Espressif 32. Once you have that you can play around with creating a test project. This will get your feet wet while you wait for your boards to arrive. Platformio also has documentation you can read up on if you have any issues.

Let us know if you have any questions.

Thank you,
Travis

Hi @marbleaimond

I have created a demo firmware for you here:

Honestly it may be all you would ever really need. It will give you the ability to control all 32 relays on the board by writing 0/1 to virtual pins 1-32.

Here’s what you’ll need to do.

  1. Download and install the Blynk app on your phone.

  2. Create a project in the Blynk app. Make sure to select ESP32 Dev Board(WiFi) as the device.

  3. After the project is created save the Authentication token created(it will be emailed to you). You will need to paste that Auth Token into the firmware.

  4. You can add a couple of buttons to the Project. Make sure they are set for Virtual pin 1-32. virtual pin 1 will control relay 1, virtual pin 2 will control relay 2, etc. A button will write a 0 or a 1 to the virtual pin. If a 0 is written to the virtual pin the relay will turn off, if a 1 is written it will turn on. It’s pretty straight forward.

  5. Download the demo app to your computer from the GitHub link above.

  6. Open Atom, click add project folder, select the folder you downloaded for the project from GitHub.

  7. Open project/src/main.cpp. Change auth, SSID, and pass as required for your setup.

  8. Upload the firmware to the module via a USB connection between your computer and the ESP32 module. For any questions on this or questions 6 or 7 consult Platformio documentation.

  9. When the board powers up its LED should turn blinking green indicating it is connected to the Blynk server. Once you open the Blynk app and it connects to the board the LED should turn solid green. This however is not super responsive. Just know that if the LED is green you are good to go. If it is flashing Yellow then there is a connectivity issue so check your SSID, password, and Auth Token.

  10. Press play in the Blynk app to make sure the project is running, then click the buttons to control relays.

  11. Brag and show off to your friends and family.

Something like this has several possibilities. The firmware can be modified for different use cases, the UI on the Blynk app can be customized to work in a multitude of different ways, the possibilities for use cases go on and on.

Let me know how this works for you and if you have any questions.

Thank you,
Travis

Additional Helpful Resources:

https://docs.blynk.io

https://docs.platformio.org

@TravisE_NCD_Technica
So, Atom wont work on my machine for some odd reason, but i have Visual Studios Code, Is there anything different that i need to do in order for the example written to work?

@TravisE_NCD_Technica
I have it set up with no errors when compiling in Arduino IDE
But for the Board settings would I press get board info of would I have to change each individual item and if so what settings would those be?

Hi,

I never worked with the Arduino IDE much. You should be able to select a port to flash to though. Of course that will be difficult to do until you have the board in hand. It should ship out today so you should receive it soon. Once you have it we can work on getting it flashed.

Arduino: 1.8.13 (Windows 10), Board: "ESP32 Dev Module, Disabled, Default 4MB with spiffs (1.2MB APP/1.5MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 115200, None"

Sketch uses 684312 bytes (52%) of program storage space. Maximum is 1310720 bytes.

Global variables use 38752 bytes (11%) of dynamic memory, leaving 288928 bytes for local variables. Maximum is 327680 bytes.

esptool.py v2.6

Serial port COM4

Connecting........_____....._____....._____....._____....._____....._____.....____An error occurred while uploading the sketch

_



A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header



This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

so after everything is hooked up and ready to go i get an error, do you know what the problem seems to be? @TravisE_NCD_Technica

Hi,

You might need to install this driver to properly mount the ESP32 module to your computer:

Give that a try and let me know what you find. After that driver is installed and you connect the module to your computer via USB you should see a new COM port listed in your device manager, make sure the Arduino IDE is set to flash to that COM port.

23:25:35.799 -> 1 written to pin 1
23:25:35.867 -> Retry Turn On Relay command
23:25:35.867 -> Retry Turn On Relay command
23:25:35.867 -> Retry Turn On Relay command
23:25:35.867 -> Turn On Relay failed
23:25:35.900 -> 0 written to pin 1
23:25:37.407 -> Retry Turn Off Relay command
23:25:37.407 -> Retry Turn Off Relay command
23:25:37.407 -> Retry Turn Off Relay command
23:25:37.407 -> Turn Off Relay command failed

Connected to Network, Blynk, and Wifi, Relay 1 on Blynk app is pressed and thats what is in Serial

so far…

#define BLYNK_PRINT Serial

// Include Librarys
#include <Arduino.h>
#include <WiFi.h> // Wifi
#include <WiFiClient.h> // Wifi
#include <BlynkSimpleEsp32.h> // for Connection to Board
#include <NCD32Relay.h> // to Control Relays
#include <RGBLED.h> // for LED

//Objects
NCD32Relay relayController;
RGBLED rgbLED;
TaskHandle_t backgroundTask;
WidgetTerminal terminal(V33);

//Functions
void backgroundTasks(void* pvParameters);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "FDghszgxvbxzzfb zf zdf f z notreal;;ads; f";

// WiFi credentials. (Variables)
// Set password to "" for open networks.
char ssid[] = "AC6D2B-2.4";
char pass[] = "14314103";
char server[] = "blynk-cloud.com";
unsigned int port = 8442;

void setup()
{
  // Debug console
  //Initialize Serial, Relay Controller, Blynk and RGBLED
  Serial.begin(115200);
  Blynk.connectWiFi(ssid, pass);
  Blynk.config(auth, server, port);  
  relayController.setAddress(0, 0);
  rgbLED.init(2, 15, 13, COMMON_ANODE, false);
  rgbLED.setMode(rgbLED.MODE_BOOT);

  //Create background thread that will handle the status of the RGB LED.  This keeps it     running smooth even if there are communication delays on the main thread
  xTaskCreatePinnedToCore(backgroundTasks, "BackGround Tasks", 20000, NULL, 1,     &backgroundTask, 1);
}


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

//Handle writes to virtual pins which will be used to control relays.
BLYNK_WRITE_DEFAULT() {
  int pin = request.pin;
  int value = param.asInt();

  Serial.printf("%i written to pin %i\n", value, pin);
  terminal.printf("%i written to pin %i\n", value, pin);

  switch (value) {
    case (0): {
        relayController.turnOffRelay(pin);
        break;
      }
    case (1): {
        relayController.turnOnRelay(pin);
        break;
      }
  }
}

BLYNK_CONNECTED() {
  Serial.println("Connected to Server");
  rgbLED.setMode(rgbLED.SERVER_CONNECTED);
}

BLYNK_APP_CONNECTED() {
  Serial.println("App connected");
  rgbLED.setMode(rgbLED.APP_CONNECTED);
}

BLYNK_APP_DISCONNECTED() {
  Serial.println("App disconnected");
  rgbLED.setMode(rgbLED.SERVER_CONNECTED);
}

void backgroundTasks(void* pvParameters) {
  for (;;) {
    rgbLED.loop();
    vTaskDelay(10);
  }
  vTaskDelete( NULL );
}

Hi,

I take it you are able to flash the code into the board and it is running.

Make sure the buttons in the Blynk app are set to control Virtual Pins. Set a button to control Virtual Pin 1 as shown in this screen shot:

Also make sure you are powering the relay board with a 12VDC power supply source(the ESP32 can be powered by USB but that will not supply power to the relays).

Let me know what you find.