Uncategorized

Robot car controlled by iPhone using Blynk and NodeMCU.

Materials:

I created a simple app on Blynk with 4 buttons connected to virtual Pins.

See how to install and run Blynk here.Then, just connect those buttons to virtual pins, like this:

IMG_4762.PNG

Forward: V0, Backwards: V1, Right: V2 and Left: V3. It look like this:

img_4756

Got a token for the project and used on the following file on your Arduino IDE.

/**************************************************************
 * This example runs directly on NodeMCU chip
 * using the Blynk platform and mobile application.
 * Change WiFi ssid, password, and Blynk auth token to run :)
 **************************************************************/

#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

#define RightMotorSpeed 5
#define RightMotorDir 0
#define LeftMotorSpeed 4
#define LeftMotorDir 2

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
char ssid[] = "MyWifi";
char pass[] = "MyWifiPassword";

void setup()
{
 Serial.begin(9600);
 Blynk.begin(auth, ssid, pass);

 pinMode(RightMotorSpeed, OUTPUT);
 pinMode(RightMotorDir, OUTPUT);
 pinMode(LeftMotorSpeed, OUTPUT);
 pinMode(LeftMotorDir, OUTPUT);
}

void loop()
{
 Blynk.run();
}

void halt()
{
 digitalWrite(RightMotorSpeed, LOW);
 digitalWrite(LeftMotorSpeed, LOW);
}

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

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

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

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

BLYNK_WRITE(V0)
{
 if (param[0])
 forward();
 else
 halt();
}

BLYNK_WRITE(V1)
{
 if (param[0])
 reverse();
 else
 halt();
}

BLYNK_WRITE(V2)
{
 if (param[0])
 right();
 else
 halt();
}

BLYNK_WRITE(V3)
{
 if (param[0])
 left();
 else
 halt();
}

Wiring up the shield to the engines and battery is straightforward. Left wheel is “Motor B”, right wheel is “Motor A”, and power goes to “ESP Power”. If you insert a jumper on the “shortcut” on the VIN and VM pins, it will power the NodeMCU from the same power source.

original-doit-esp8266-nodemcu-motor-shield-with-l293d-extension-board-for-rc-kit-diy-smart-car

IMG_4761.JPG

Assembling everything together, the thing comes out like this (click to zoom):

And it runs well:

Right now, this is a dumb machine. I will install some intelligence on it pretty soon 🙂 Besides, I will play with different wheel options and maybe a servo on the front.

Advertisements
Standard

5 thoughts on “Robot car controlled by iPhone using Blynk and NodeMCU.

  1. Jirbos says:

    Hi. I was try your sketch. But i use DC motor. Know you how i can use only motor Right : from min to max smoothly by joystick by blynk.?
    THanks.

    #define BLYNK_PRINT Serial // Comment this out to disable prints and save space
    #include
    #include
    #include
    #include

    #define RightMotorSpeed 5
    #define RightMotorDir 0

    // You should get Auth Token in the Blynk App.
    // Go to the Project Settings (nut icon).
    char auth[] = “b003999375154c80a70f16c3365b86c5”;
    char ssid[] = “ASUS”;
    char pass[] = “Jersin72”;

    //Servo servo;
    Servo servo1; //D4

    void setup()
    {
    Serial.begin(9600);
    Blynk.begin(auth, ssid, pass);

    pinMode(RightMotorSpeed, OUTPUT);
    pinMode(RightMotorDir, OUTPUT);

    servo1.attach(2);
    }

    void loop()
    {
    Blynk.run();
    }

    void halt()
    {
    digitalWrite(RightMotorSpeed, LOW);

    }

    void forward()
    {
    digitalWrite(RightMotorDir, HIGH);

    digitalWrite(RightMotorSpeed, HIGH);

    }

    void reverse()
    {
    digitalWrite(RightMotorDir, LOW);

    digitalWrite(RightMotorSpeed, HIGH);

    }

    BLYNK_WRITE(V0)
    {
    if (param[0])
    forward();
    else
    halt();
    }

    BLYNK_WRITE(V1)
    {
    if (param[0])
    reverse();
    else
    halt();
    }

    BLYNK_WRITE(V6) //0-180
    {
    servo1.write(param.asInt());
    }

  2. Well, I use two FM90 DC motors as well! That’s a great idea, although I prefer the instantaneous reaction of the buttons. As I move the motors with digitalWrite, the only values are HIGH (1) and LOW (0). You can use a PWM scheme to simulate values smaller than 1, and increase values with an acceleration scheme.

  3. Alberto Bonati says:

    Hi
    I tryed your proyect and work fine but reverse don’t work at all.
    I tryed other sketchs too, and Blynk with joistick too…all work but reverse!.
    If I set GPO 0 and GPO2 as HIGH or 1 value it work fine but with LOW or 0 value motors don’t work at all.
    Did you notice somethingh about this problem?
    Regards
    Alberto

  4. Alberto Bonati says:

    Hi, I agree maybe it’s a wrong GPIO connection problem, I’ll make some tester test. But connections betwin NODEMCU board and motor shield are by default on shield…Ony I can try to test HIGH or LOW state in some other GPIO and hope….GPO4 and GPO5 works fine with speed control, even for gradual speed control.
    I tryed lua enviroment too, but with same result.
    Regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s