Bhuvisara DharmasenaChathura Yapa Bandara
Published

DAGAYA Surge Duo Motor Driver

Drive your high power Brushed DC motor with DAGAYA Surge Duo motor driver module.

IntermediateProtip74
DAGAYA Surge Duo Motor Driver

Things used in this project

Hardware components

DAGAYA Surge Duo Motor Driver Module
×1
Arduino Uno/Nano or any other microcontroller
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Connection Diagram

Make connections as shown in below.

Connection for Control two motors according to user given commands.

Connect two motors with DAGAYA Surge Duo Motor Driver and Arduino. Use USB cable to send data to Arduino through GUI application

Code

Code for test the module

Arduino
Upload this code to test break, direction change, PWM of the motor.
const int motorPin = 9; // Pin connected to motor driver input
const int phasePin = 10; //pin connected to PH pin 



void setup() {
  pinMode(motorPin, OUTPUT); // Set motorPin as an output
}

void loop() {

digitalWrite(phasePin, HIGH); // sets the direction to forward
delay(5000);

  digitalWrite(motorPin, HIGH);//motor runs in full speed for 3 sec
  delay(3000);
  digitalWrite(motorPin, LOW);//motor breaks for 1 sec
  delay(1000);
  
  
  // Change the motor speed gradually from 0 to 255 and back to 0
  for (int speed = 0; speed <= 255; speed++) {
    analogWrite(motorPin, speed); // Set motor speed
    delay(300); // Adjust delay for speed change
  }
  for (int speed = 255; speed >= 0; speed--) {
    analogWrite(motorPin, speed); // Set motor speed
    delay(300); // Adjust delay for speed change
  }

digitalWrite(phasePin, LOW);  // Change the direction to backward
delay(1000);

// Change the motor speed gradually from 0 to 255 and back to 0
  for (int speed = 0; speed <= 255; speed++) {
    analogWrite(motorPin, speed); // Set motor speed
    delay(300); // Adjust delay for speed change
  }
  for (int speed = 255; speed >= 0; speed--) {
    analogWrite(motorPin, speed); // Set motor speed
    delay(300); // Adjust delay for speed change
  }




}

Arduino Code for accept user given commands.

Arduino
Upload the code and give commands through serial monitor to control two motors as you want.
// Pin assignments
const int motorAPin = 9;    // PWM pin for Motor A
const int motorBPin = 10;   // PWM pin for Motor B
const int dirAPin = 7;      // Direction pin for Motor A
const int dirBPin = 8;      // Direction pin for Motor B
//const int brakePinA = 6;    // Brake pin for Motor A
//const int brakePinB = 5;    // Brake pin for Motor B
int speed=0;

void setup() {
  pinMode(motorAPin, OUTPUT);
  pinMode(motorBPin, OUTPUT);
  pinMode(dirAPin, OUTPUT);
  pinMode(dirBPin, OUTPUT);
  //pinMode(brakePinA, OUTPUT);
  //pinMode(brakePinB, OUTPUT);
 
  Serial.begin(9600);
  Serial.println("Enter commands to control motors:");
}

void loop() {
  if (Serial.available() > 0) {
    String command = Serial.readStringUntil('\n');
    command.trim();
    command.toUpperCase(); // Ensure command is in uppercase
   
    if (command == "AON") {
      digitalWrite(motorAPin, HIGH); // Max speed
      //digitalWrite(brakePinA, LOW); // Release brake
      Serial.println("Motor A ON");
    }
    else if (command == "AOFF") {
     
      digitalWrite(motorAPin, LOW); // Stop motor
      Serial.println("Motor A OFF");
    }
    else if (command == "ADIRFWD") {
       digitalWrite(motorAPin, HIGH);
      digitalWrite(dirAPin, HIGH); // Set direction to forward
       analogWrite(motorAPin, speed);
      Serial.println("Motor A Forward");
    }
    else if (command == "ADIRREV") {
       digitalWrite(motorAPin, HIGH);
      digitalWrite(dirAPin, LOW); // Set direction to reverse
       analogWrite(motorAPin, speed);
      Serial.println("Motor A Reverse");
    }
    /*else if (command == "ABRAKE") {
      digitalWrite(brakePinA, HIGH); // Engage brake
      Serial.println("Motor A Brake");
    }*/
    else if (command.startsWith("ASPEED")) {
       speed = command.substring(6).toInt();
      speed = constrain(speed, 0, 255); // Ensure speed is within 0-255
      analogWrite(motorAPin, speed);
      Serial.println("Motor A Speed: " + String(speed));
    }
   
    // Similar controls for Motor B
    else if (command == "BON") {
      digitalWrite(motorBPin, HIGH);
      //digitalWrite(brakePinB, LOW);
      Serial.println("Motor B ON");
    }
    else if (command == "BOFF") {
      digitalWrite(motorBPin, LOW);
      Serial.println("Motor B OFF");
    }
    else if (command == "BDIRFWD") {
      digitalWrite(dirBPin, HIGH);
      Serial.println("Motor B Forward");
    }
    else if (command == "BDIRREV") {
      digitalWrite(dirBPin, LOW);
      Serial.println("Motor B Reverse");
    }
    /*else if (command == "BBRAKE") {
      digitalWrite(brakePinB, HIGH);
      Serial.println("Motor B Brake");
    }*/
    else if (command.startsWith("BSPEED")) {
      int speed = command.substring(6).toInt();
      speed = constrain(speed, 0, 255); // Ensure speed is within 0-255
      analogWrite(motorBPin, speed);
      Serial.println("Motor B Speed: " + String(speed));
    }
    else {
      Serial.println("Invalid Command");
    }
  }
}

Python code for build the GUI application on windows to control two Motors.

Python
Give commands to the Arduino board using this GUI application.
import tkinter as tk
from tkinter import messagebox
import serial
import threading
import time

SERIAL_PORT = 'COM3'
BAUD_RATE = 9600
ser = serial.Serial(SERIAL_PORT, BAUD_RATE, timeout=1)
def send_command(command):
    ser.write((command + '\n').encode())

def motor_a_on():
    send_command('AON')

def motor_a_off():
    send_command('AOFF')

def motor_a_dir_fwd():
    send_command('ADIRFWD')

def motor_a_dir_rev():
    send_command('ADIRREV')

#def motor_a_brake():
    #send_command('ABRAKE')

def motor_a_speed(val):
    send_command(f'ASPEED{int(float(val))}')

def motor_b_on():
    send_command('BON')

def motor_b_off():
    send_command('BOFF')

def motor_b_dir_fwd():
    send_command('BDIRFWD')

def motor_b_dir_rev():
    send_command('BDIRREV')

#def motor_b_brake():
    #send_command('BBRAKE')

def motor_b_speed(val):
    send_command(f'BSPEED{int(float(val))}')

def read_serial():
    while True:
        if ser.in_waiting:
            line = ser.readline().decode().strip()
            if line:
                print(f"Arduino: {line}")

# Start a thread to read serial data
threading.Thread(target=read_serial, daemon=True).start()

# Build the GUI
root = tk.Tk()
root.title("Motor Control GUI")

# Motor A Controls
motor_a_frame = tk.LabelFrame(root, text="Motor A Controls", padx=10, pady=10)
motor_a_frame.grid(row=0, column=0, padx=10, pady=10)

tk.Button(motor_a_frame, text="ON", width=10, command=motor_a_on).grid(row=0, column=0, pady=5)
tk.Button(motor_a_frame, text="OFF", width=10, command=motor_a_off).grid(row=0, column=1, pady=5)
tk.Button(motor_a_frame, text="Forward", width=10, command=motor_a_dir_fwd).grid(row=1, column=0, pady=5)
tk.Button(motor_a_frame, text="Reverse", width=10, command=motor_a_dir_rev).grid(row=1, column=1, pady=5)
#tk.Button(motor_a_frame, text="Brake", width=10, command=motor_a_brake).grid(row=2, column=0, columnspan=2, pady=5)
tk.Label(motor_a_frame, text="Speed").grid(row=3, column=0, columnspan=2)
motor_a_speed_slider = tk.Scale(motor_a_frame, from_=0, to=255, orient=tk.HORIZONTAL, command=motor_a_speed)
motor_a_speed_slider.set(255)
motor_a_speed_slider.grid(row=4, column=0, columnspan=2, pady=5)

# Motor B Controls
motor_b_frame = tk.LabelFrame(root, text="Motor B Controls", padx=10, pady=10)
motor_b_frame.grid(row=0, column=1, padx=10, pady=10)

tk.Button(motor_b_frame, text="ON", width=10, command=motor_b_on).grid(row=0, column=0, pady=5)
tk.Button(motor_b_frame, text="OFF", width=10, command=motor_b_off).grid(row=0, column=1, pady=5)
tk.Button(motor_b_frame, text="Forward", width=10, command=motor_b_dir_fwd).grid(row=1, column=0, pady=5)
tk.Button(motor_b_frame, text="Reverse", width=10, command=motor_b_dir_rev).grid(row=1, column=1, pady=5)
#tk.Button(motor_b_frame, text="Brake", width=10, command=motor_b_brake).grid(row=2, column=0, columnspan=2, pady=5)
tk.Label(motor_b_frame, text="Speed").grid(row=3, column=0, columnspan=2)
motor_b_speed_slider = tk.Scale(motor_b_frame, from_=0, to=255, orient=tk.HORIZONTAL, command=motor_b_speed)
motor_b_speed_slider.set(255)
motor_b_speed_slider.grid(row=4, column=0, columnspan=2, pady=5)

root.mainloop()

Credits

Bhuvisara Dharmasena
5 projects • 1 follower
Contact
Chathura Yapa Bandara
19 projects • 5 followers
Contact

Comments

Please log in or sign up to comment.