Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Maker 101
Published © GPL3+

ESP8266 DRV8848 Dual Motor Controller Board

I designed a board that includes the ESP8266 (ESP-12F) WiFi module, allowing you to control some sensors, a servo and dual DC motors.

IntermediateFull instructions provided514
ESP8266 DRV8848 Dual Motor Controller Board

Things used in this project

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Hot Plate, Convection
Hot Plate, Convection

Story

Read more

Custom parts and enclosures

Part List

Schematics

Designator

Code

drv8848-dual-analog-PWM-mode.ino

Arduino
#include <ESP8266WiFi.h>

const int M1forwardPin = 14;
const int M1backwardPin = 12;
const int M2forwardPin = 5;
const int M2backwardPin = 4;
const int sleepPin = 16;

#define M1SPEED 145
#define M2SPEED 150

#define DELAY 500


void setup() {
  pinMode(M1forwardPin, OUTPUT);
  pinMode(M1backwardPin, OUTPUT);
  pinMode(M2forwardPin, OUTPUT);
  pinMode(M2backwardPin, OUTPUT);
  pinMode(sleepPin, OUTPUT);

  digitalWrite(sleepPin, HIGH);
}

void forward() {
  analogWrite(M1forwardPin, M1SPEED);
  analogWrite(M2forwardPin, M2SPEED);
  analogWrite(M1backwardPin, 0);
  analogWrite(M2backwardPin, 0);
}

void backward() {
  analogWrite(M1backwardPin, M1SPEED);
  analogWrite(M2backwardPin, M2SPEED);
  analogWrite(M1forwardPin, 0);
  analogWrite(M2forwardPin, 0);
}

void turnLeft() {
  analogWrite(M1backwardPin, M1SPEED);
  analogWrite(M2forwardPin, M2SPEED);
  analogWrite(M1forwardPin, 0);
  analogWrite(M2backwardPin, 0);
}

void turnRight() {
  analogWrite(M1forwardPin, M1SPEED);
  analogWrite(M2backwardPin, M2SPEED);
  analogWrite(M1backwardPin, 0);
  analogWrite(M2forwardPin, 0);
}

void stopMotors() {
  digitalWrite(sleepPin, LOW);
  analogWrite(M1forwardPin, 0);
  analogWrite(M2forwardPin, 0);
  analogWrite(M1backwardPin, 0);
  analogWrite(M2backwardPin, 0);
}

void loop() {
  stopMotors();
  delay(1000);
  forward();
  delay(DELAY);
  backward();
  delay(DELAY);
  turnLeft();
  delay(DELAY);
  turnRight();
  delay(DELAY);
}

drv8848-dual-analog-PWM-HCSR04-mode.ino

Arduino
#include <ESP8266WiFi.h>

//Pins to which motors are connected (GPIO)
int M1forwardPin = 14;
int M1backwardPin = 12;
int M2forwardPin = 5;
int M2backwardPin = 4;
int sleepPin = 16;

//Pins to which the ultrasonic sensor is connected (GPIO)
const int trigPin = 13;
const int echoPin = 0;

//Define variable for distance calculation
long duration, distance;

void setup() {
  delay(random(500, 2000));
  pinMode(M1forwardPin, OUTPUT);
  pinMode(M1backwardPin, OUTPUT);
  pinMode(M2forwardPin, OUTPUT);
  pinMode(M2backwardPin, OUTPUT);
  pinMode(sleepPin, OUTPUT);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);

  digitalWrite(sleepPin, HIGH);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);

  duration = pulseIn(echoPin, HIGH);
  distance = duration / 58.2;

  delay(10);

  if (distance > 15)
  {
    analogWrite(M1forwardPin, 128);
    analogWrite(M2forwardPin, 128);
    analogWrite(M1backwardPin, LOW);
    analogWrite(M2backwardPin, LOW);
    
  }
  
  if (distance < 14)
  {
    analogWrite(M1forwardPin, LOW);
    analogWrite(M2forwardPin, LOW);
    analogWrite(M1backwardPin, LOW);
    analogWrite(M2backwardPin, LOW);
    delay(200);
    analogWrite(M2backwardPin, 128);
    analogWrite(M1backwardPin, 128);
    analogWrite(M1forwardPin, LOW);
    analogWrite(M2forwardPin, LOW);
    delay(200);
    analogWrite(M1forwardPin, LOW);
    analogWrite(M2forwardPin, LOW);
    analogWrite(M1backwardPin, LOW);
    analogWrite(M2backwardPin, LOW);
    delay(100);
    analogWrite(M1forwardPin, 128);
    analogWrite(M2backwardPin, 128);
    analogWrite(M2forwardPin, LOW);
    analogWrite(M1backwardPin, LOW);
    delay(300);
  }
}

drv8848-dual-analog-PWM-IR-mode.ino

Arduino
#include <ESP8266WiFi.h>
 
#define M1FWD 14
#define M1BWD 12
#define M2FWD 5
#define M2BWD 4
#define SLP 16
#define IR 0

void setup() {
  pinMode(M1FWD, OUTPUT);
  pinMode(M1BWD, OUTPUT);
  pinMode(M2FWD, OUTPUT);
  pinMode(M2BWD, OUTPUT);
  pinMode(SLP, OUTPUT);
  pinMode(IR, INPUT);

  digitalWrite(SLP, HIGH);
}

void loop() {
  int IRval = digitalRead(IR);
  if(IRval == HIGH)
  {
    analogWrite(M1FWD, 128);
    analogWrite(M2FWD, 128);
    analogWrite(M1BWD, 0);
    analogWrite(M2BWD, 0);
  } else
  {
    analogWrite(M1BWD, 128);
    analogWrite(M2FWD, 128);
    analogWrite(M1FWD, 0);
    analogWrite(M2BWD, 0);
  }

}

drv8848-dual-analog-PWM-Servo-mode.ino

Arduino
#include <ESP8266WiFi.h>
#include <Servo.h>
 
#define M1FWD 14
#define M1BWD 12
#define M2FWD 5
#define M2BWD 4
#define SLP 16
#define SERVO 0

Servo myServo;

void setup() {
  pinMode(M1FWD, OUTPUT);
  pinMode(M1BWD, OUTPUT);
  pinMode(M2FWD, OUTPUT);
  pinMode(M2BWD, OUTPUT);
  pinMode(SLP, OUTPUT);
  myServo.attach(SERVO);
  
  digitalWrite(SLP, HIGH);
}

void loop() {
    analogWrite(M1BWD, 0);
    analogWrite(M2FWD, 0);
    analogWrite(M1FWD, 0);
    analogWrite(M2BWD, 0);
    myServo.write(70);
    delay(3000);
    
    myServo.write(120);
    delay(500);
    analogWrite(M1BWD, 128);
    analogWrite(M2FWD, 128);
    analogWrite(M1FWD, 0);
    analogWrite(M2BWD, 0);
    delay(3000);

}

Credits

Maker 101

Maker 101

51 projects • 179 followers
Maker 101; Beginner and intermediate level Maker projects!

Comments