BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

The smallest Wifi smartphone controlled 4WD car using ESP8266, Blynk and Arduino Code


#1

link Projects https://www.youtube.com/watch?v=QwzRC-Ov-Zo

//Need to improve code//

/*
  Wifi/Blynk controlled 4WD car using ESP 8266
  Used Pin ESP07
  D5-14 motorA1 ; D6-12 motorA2
  D1-05 motorB1 ; D2-04 motorB2
  D4-02 Rightflasher
  RX-03 Leftflasher
  D7-13 Headlight ; tx-01 buzzer
*/
#include  < ESP8266WiFi.h >
#include  < BlynkSimpleEsp8266.h >

int X = 512;
int Y = 512;
int maximo = 0;
int Rflasher = 0;
int Lflasher = 0;
int buzzer = 0;
int police = 0;
int flasherLedState = LOW;          //Initial led state

long previousMillis = 0;        // Time control
long flasherLedInterval = 300;     // Interval time to run

#define RED 0
#define BLUE 0

byte whichLED = RED;
byte Red_State = LOW;
byte Red1_State = LOW;
unsigned long switchDelay = 250;
unsigned long strobeDelay = 50;
unsigned long strobeWait = strobeDelay;
unsigned long waitUntilSwitch = switchDelay;  // Initial state

char auth[] = "xxxxxxxxxxxx"; // You should get Auth Token in the Blynk App.

void setup()
{
  Serial.begin(9600);// Set console baud rate
  Blynk.begin(auth, "SSID", "PASS");// You will connect your phone to this Access Point and this is the password

  pinMode(14, OUTPUT); // Pin motor A1
  pinMode(12, OUTPUT); // Pin motor A2
  pinMode(2, OUTPUT); // Pin Rightflasher
  pinMode(3, OUTPUT); // Pin Leftflasher
  pinMode(5, OUTPUT); // Pin motor B1
  pinMode(4, OUTPUT); // Pin motor B2
  pinMode(1, OUTPUT); // PinoBuzzer

}

BLYNK_WRITE(V1)  // 0~1023
{
  int X1 = param[0].asInt();
  X = X1;
  int Y1 = param[1].asInt();
  Y = Y1;
}
BLYNK_WRITE(V2)//      slider PWM from 0 to 1023
{
  maximo = param.asInt();
}

BLYNK_WRITE(V3)     //      button Rightflasher
{
  Rflasher = param.asInt();
}

BLYNK_WRITE(V4)    //      button Leftflasher
{
  Lflasher = param.asInt();
}

BLYNK_WRITE(V5)    //      button buzzer
{
  buzzer = param.asInt();
}


BLYNK_WRITE(V7)     //      button police
{
  police = param.asInt();
}

void loop()
{
  Blynk.run();

  if (X != 512 && Y != 512)
  {

    if ( X > 311 && X < 711  &&  Y > 311 && Y < 711 ) //  Motor Stop
    {
      analogWrite(14, 0); //IN-1A motorA = 0
      analogWrite(12, 0);  //IN-1B


      analogWrite(5, 0); //IN-2A motorB = 0
      analogWrite(4, 0); //IN-2B
    }

    if ( X > 311 && X < 711  &&  Y > 711)  // motor forward
    {
      analogWrite(14, maximo); //motorA = maximo;
      analogWrite(12, 0);

      analogWrite(5, maximo);//motorB = maximo;
      analogWrite(4, 0);
    }

    if ( X > 311 && X < 711  &&  Y < 311)  // Motor backward
    {
      analogWrite(12, maximo);// motorA = maximo;
      analogWrite(14, 0);
      analogWrite(5, maximo);// motorB = maximo;
      analogWrite(4, 0);
    }
    if ( X > 711 &&  Y > 711)  // Right Forward
    {
      analogWrite(14, maximo);//motorA = maximo;
      analogWrite(12, 0);
      analogWrite(5, 0);//motorB = 0;
      analogWrite(4, 0);
    }

    if ( X < 311 &&  Y > 711)  // Left Forward
    {
      analogWrite(14, 0);//motorA = 0;
      analogWrite(12, 0);
      analogWrite(5, maximo);//motorB = maximo;
      analogWrite(4, 0);
    }

    if ( X > 711 &&  Y < 311)  // Right backwards
    {
      analogWrite(12, maximo);//motorA = maximo;
      analogWrite(14, 0);
      analogWrite(5, 0 );//motorB = 0;
      analogWrite(4, 0);
    }

    if ( X < 311 &&  Y < 311)  // Left backwards
    {
      analogWrite(12, 0);//motorA = 0;
      analogWrite(14, 0);
      analogWrite(5, maximo);//motorB = maximo;
      analogWrite(4, 0);
    }
  }

  if (Rflasher != 1 && Lflasher != 1)
  {
    if (police == 1)
    {
      digitalWrite(2, Red_State);
      digitalWrite(3, Red1_State);

      if ((long)(millis() - waitUntilSwitch) >= 0) {
        // time is up!
        Red_State = LOW;
        Red1_State = LOW;
        whichLED = !whichLED;  // toggle LED to strobe
        waitUntilSwitch += switchDelay;
      }

      //  police effect
      if ((long)(millis() - strobeWait) >= 0) {
        if (whichLED == RED)
          Red_State = !Red_State;
        if (whichLED == BLUE)
          Red1_State = !Red1_State;
        strobeWait += strobeDelay;
      }
    } else {
      digitalWrite(2, LOW);
      digitalWrite(3, LOW);
    }
  }

  unsigned long currentMillis = millis();    //Current time
  if (currentMillis - previousMillis > flasherLedInterval) //Logic of time verification
  {
    previousMillis = currentMillis;    // Saves the current time

    if (flasherLedState == LOW)
    {
      flasherLedState = HIGH;
    } else {
      flasherLedState = LOW;
    }
    if (Rflasher == 1 && police == 0)
    {
      digitalWrite(2, flasherLedState);
    } else {
      digitalWrite(2, LOW);
    }
    if (Lflasher == 1 && police == 0)
    {
      digitalWrite(3, flasherLedState);
    } else {
      digitalWrite(3, LOW);
    }
  }
  if (buzzer == 1)
  {
    tone(1, 500, 200); //Horn tone "FA"
  }
}

#2

It is a real cute little car! :+1: But please go back and edit your post with properly formatted code… and then perhaps ask a question as well :wink: (in reference to - //Need to improve code// )… or are you just showing it to us?

Also, MORE DETAILS PLEASE :smiley: what are you using for motors and controller that small??

EDIT - OK, I guess I could have watched until the end of the video before asking :stuck_out_tongue:

Again, real nice work!


#3

Nice little car, world’s smallest iot car. Really awesome.nice work.


#4

WOW what a tiny funny game to play with , can you provide parts list so we all can get own hands on
such little cute game


#5

Wow!!! Such a small car, I love it!!! Thanks for sharing!
Just one question… How many minutes can you drive your car with this little battery??


#6

cool project thanks for sharing :slight_smile:


#7

Is there a build Log for this thing? I’d LOVE to have one of this driving on our 1:87 modelrailroad :smiley:


#8

Thanks Psoro, This car I can’t drive more than 5 minutes. Depends on the quality and capacity of the battery.


#9

I do not have a build log yet , Parts List is inside of youtube video.


#10

I noticed. I’ll go from there.

I think I’ll build a mouse thing around it and use it to play with the cats, lol.