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

Basic rc sketch 1 DC MOTOR - 1 Servo - L293D

#1

This was my very first project. Most projects I could easily find involved 2 or 4 dc motors. I looked around and founds codes that fit my purposes and modified it. The biggest headache came with the L293D driver. The left side of the IC seemed to not work in both directions(but I hadn’t connected ALL grounds of the IC on these tries), maybe to a fault of my own or maybe it is specd out like this(something about a quadruple half bridge)~ Also to make the IC work as intended I had to wire up all the grounds(jumping them should help clean things up), most tutorials/instructions call for one; at most two grounds on opposite sides. The original code included a V1 slider to control speed, I did not need this for my project.

#include <Servo.h> //disables PWM on pins 9&10 for Arduino nano
#define BLYNK_PRINT Serial
#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>
#include <SoftwareSerial.h>

SoftwareSerial EspSerial(2, 3); // RX/TX
#define ESP8266_BAUD 9600 //define Esp baud rate 

ESP8266 wifi(&EspSerial);
Servo myServo;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "Your Blynk Auth Token";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Your network name here";
char pass[] = "Your wifi password here";

const int enable1 = 11; // Enable pin 1
const int Forward = 7; //Forward
const int Backward = 8; //Reverse
const int servo = 6; //servo

 int speed = 0; //
/*BLYNK_WRITE(V1)
{
  
 
  speed = param.asInt();
  Serial.println(speed);
  analogWrite(enable1, speed);
}*/

BLYNK_WRITE(V2)
{
  int x = param[0].asInt();
  int y = param[1].asInt();
  
 
 
  Serial.println(" X = ");
  Serial.print(x);
  Serial.print(" ; Y = ");
  Serial.println(y);
   
   if ( y > 200)
   {
    analogWrite(enable1, 255);
    digitalWrite(Forward, HIGH);
    digitalWrite(Backward, LOW);
   }
  
   else if ( y < 50)
   {
      analogWrite(enable1, 255);
      digitalWrite(Backward, HIGH);
      digitalWrite(Forward, LOW);
   }
    

   else
    {
      digitalWrite(enable1, LOW);
      digitalWrite(Backward, HIGH);
      digitalWrite(Forward,HIGH);
    }
    int angle = 0;//
    angle = param[0].asInt();
    if (angle >= 168)
      angle = 180;
    else if (angle <= 16)
      angle = 0; 
      else
      angle = 90;

   myServo.write(angle);
  }

  void setup() {

    pinMode(enable1, OUTPUT);
    pinMode(Forward, OUTPUT);
    pinMode(Backward, OUTPUT);
  //  digitalWrite(enable1,HIGH);

    // Debug console
    Serial.begin(9600); //debug console
    //Set ESP8266 BAUD RATE
    EspSerial.begin(ESP8266_BAUD);
    delay(10);

    Blynk.begin(auth, wifi, ssid, pass);

 myServo.attach(servo);
  }

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

#2

So… what does this do? Is it a unicycle with a servo waving around for ballance :smile:

0 Likes

#3

The servo is for steering! The dc motor on my project will belt drive the rear wheels, and the servo will steer the front like a standard rc car… I wish I knew how to program a unicycle (or a BB-8)to work with some counterbalancing elements that would be a trip.

This project was mostly about having fun and learning. Now on to some home automation.

1 Like

#4

From the 293’s datasheet I can’t really tell if all GND pins are internally connected, but an educated guess (well, actually just a guess :grin:) is that each of the Half-H has its own GND. Omitting to ground any of the Half-H’s that are in use would probably cause the problem you describe. Voltage (in this case the TTL-levels) is reference to ground, and you don’t want to drift away :slight_smile:

Explained “Don’t leave your pins floating”

Another reason to connect all ground pins is that they’ll help with the heat transfer. From the datasheet:

0 Likes