NodeMCU 1.0 ESP-12E DevKit (ESP8266)

Hi All

This is my very first post on the Arduino forum so apologies in advance if I post this to the wrong category/sub-category (i'm a noob). This might even be something I need to post to the Blynk community forums rather than here but I thought I would start here to get some initial feedback.

I have an (Arduino like) NodeMCU ESP-12E DevKit module connected to a motor shield, mounted to a simple 2WD car chassis. I am trying to connect the module to the Blynk platform so I can control the "car" via the Blynk iOS app. The controls are very basic - FWD, REV, LEFT, RIGHT, HALT.

I was able to initially connect the module to my Blynk dashboard using the "Blynk-Quickstart-Template-Connection.ino" Arduino sketch which was uploaded to the module using the Arduino IDE (2.3.3) without any issues. Now I have created a new sketch to add functionality to control two FM90 DC motors via Blynk.

After several failed attempts to compile the sketch, I was able to adjust the code so it would compile without returning an error. However, now the code has been uploaded to the module, the buttons in my Blynk app do not drive the two FM90 DC motors as intended. I can see that when pressing some of the buttons in the iOS app the blue LED indicator on the NodeMCU illuminates, but the motors do not drive the wheels.

I have a 4xAA ((6V DC (ish)) battery pack attached to the motor shield to power the DC motors. I had initially added a jumper on the motor shield to route the power from the battery pack to the NodeMCU module (VIN+VIM), but when setting the switch on the motor shield to the "on" position the module would not power on. I removed the jumper so the battery pack is only providing power to the motors and then I connected 5V DC directly to the NodeMCU module via a USB connection on my docking station and the results are the same, the DC motors never engage and the only evidence I can see to show the Blynk buttons are having any effect on the module is when the blue LED indicator light on the NodeMCU illuminates.

I first thought the issue was power, as the original battery pack had a cheap on/off toggle switch which I thought was stuck in the closed position as a multimeter shows 1.5/1.6V DC across the terminals on each AA battery (they are brand new Duracell Alkaline batteries), but when measuring the voltage at the VM/GND terminals on the motor shield, no voltage is measured (shows only around 600mV). I switched to a different battery pack but saw the same results.

I'm unsure if the issue is with the DC motors, the motor shield, power, my wiring on the motor shield, or the code I have written.

Including my sketch below:

/**************************************************************
 * This example runs directly on ESP8266 chip
 * using the Blynk platform and mobile application.
 *
 * Change WiFi ssid, password, and Blynk auth token to run :)
 *
 **************************************************************/
/*
Heavily adapted to work with Blynk 2.0 using code from the Blynk Quickstart Template sketch
Written for the NodeMCU DevKit ESP12E (ESP8266)
Written by Jay
October 26, 2024
*/


#define BLYNK_DEBUG               // Comment this out to disable the verbose Blynk protocol log
#define BLYNK_PRINT Serial        // Comment this out to disable prints and save space

// Fill in information from Blynk Device Info here
/* Read more: https://bit.ly/BlynkSimpleAuth */
#define BLYNK_TEMPLATE_ID     "**redacted**"
#define BLYNK_TEMPLATE_NAME   "Quickstart Template"
#define BLYNK_AUTH_TOKEN      "**redacted**"

#include <BlynkMultiClient.h>     // Allows attaching Blynk to the standard Arduino client

// Wi-Fi credentials. Set password to "" for open networks.
const char* ssid = "**redacted**";
const char* pass = "**redacted**";

#ifdef ESP32
#  include <WiFi.h>
#else
#  include <ESP8266WiFi.h>
#endif

static WiFiClient blynkWiFiClient;



// Establish a connection to the Wi-Fi network
void connectWiFi()
{
  Serial.print("Connecting to ");
  Serial.println(ssid);

  if (pass && strlen(pass)) {
    WiFi.begin((char*)ssid, (char*)pass);
  } else {
    WiFi.begin((char*)ssid);
  }

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
}

// Pre processor directives to set the pins on the ESP12E motor shield
#define RightMotorSpeed 5
#define RightMotorDir   0
#define LeftMotorSpeed  4
#define LeftMotorDir    2

void setup()
{
  Serial.begin(115200);
  connectWiFi();
  
  // Setup Blynk
  Blynk.addClient("WiFi", blynkWiFiClient, 80);
  Blynk.config(BLYNK_AUTH_TOKEN);

  // Set all board pins as outputs
  pinMode(RightMotorSpeed, OUTPUT);
  pinMode(RightMotorDir, OUTPUT);
  pinMode(LeftMotorSpeed, OUTPUT);
  pinMode(LeftMotorDir, OUTPUT);
}

void loop()
{
  // Check Wi-Fi connection is still active. If not, try to reconnect
  if (WiFi.status() != WL_CONNECTED) {
    connectWiFi();
    return;
  }

  Blynk.run();
}



// Stop the vehicle
void halt()
{
  digitalWrite(RightMotorSpeed, LOW);
  digitalWrite(LeftMotorSpeed, LOW);
}

// Engage forward motion
void forward()
{
  digitalWrite(RightMotorDir, HIGH);
  digitalWrite(LeftMotorDir, HIGH);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

// Engage reverse
void reverse()
{
  digitalWrite(RightMotorDir, LOW);
  digitalWrite(LeftMotorDir, LOW);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

// Turn right
void right()
{
  digitalWrite(RightMotorDir, LOW);
  digitalWrite(LeftMotorDir, HIGH);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}

// Turn left
void left()
{
  digitalWrite(RightMotorDir, HIGH);
  digitalWrite(LeftMotorDir, LOW);
  digitalWrite(RightMotorSpeed, HIGH);
  digitalWrite(LeftMotorSpeed, HIGH);
}



// If the button attached to virtual pin V0 has been triggered - HALT
BLYNK_WRITE(V0)
{
  if (param[0])
    halt();
  else
    halt();
}

// If the button attached to virtual pin V1 has been triggered - FWD
BLYNK_WRITE(V1)
{
  if (param[0])
    forward();
  else
    halt();
}

// If the button attached to virtual pin V2 has been triggered - REV
BLYNK_WRITE(V2)
{
  if (param[0])
    reverse();
  else
    halt();
}

// If the button attached to virtual pin V3 has been triggered - LEFT
BLYNK_WRITE(V3)
{
  if (param[0])
    left();
  else
    halt();
}

// If the button attached to virtual pin V4 has been triggered - RIGHT
BLYNK_WRITE(V4)
{
  if (param[0])
    right();
  else
    halt();
}



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