DC Motor Torque

Need some help here. I'm working on a code to do multiple things. Here are the components:

  1. Arduino Mega board
  2. TS-25GA370H-45, 12volt DC motor
  3. HV711 sensor
  4. 1K stain gauge
  5. LCD 1602 module
  6. (2) LED lights
  7. Active buzzer
  8. Breadboard

My code works like this:
When the code is uploaded, the DC motor starts turning and the LCD displays the stain force of the guage (in this case "0" on startup). I programed the coded with a max strain force of 225 grams. When I apply force to the strain gauge that exceeds 225 grams, the motor stops turning and the LED's and buzzer are actived. This work as supposed to (I have no issue with this).
My issue that I'm having is the torque of the motor. I have the motor connected to a drum that weight about 1.5lbs. The motor can turn the shaft of the drum but doesn't have the required torque to turn the shaft and motor. I can't swap out any of the components I listed above but I can add components like a " L298N Motor Drive Controller Board Module Dual H Bridge DC Stepper For Arduino", but that is all I have and not sure how to use this.

My question:
How can I modify my code to increase the torque of the motor? Or increase the speed on startup? I did try connecting a 9V battery as well to the motor's wiring and this did increase the speed a little bit, along with slight increase torque but when the strain gauge hit the 225 gram limit, the motor only slowed down and not off like it did when it was just on the 5V of the Arduino board. Any help or suggestions will be greatly appreciated.

Code:

#include <HX711.h>                                   // HX711 weight sensor library
#include <LiquidCrystal.h>                           // LCD display library

LiquidCrystal lcd(30, 32, 34, 36, 38, 40);                 // LCD display: (rs, enable, d4, d5, d6, d7)
const int LOADCELL_DOUT_PIN = 44;                     // HX711 wiring
const int LOADCELL_SCK_PIN = 42;                      // HX711 wiring
HX711 scale;                                         // HX711 scale reading
long duration;
int weight;                                          // HX711 weight reading
int led1 = 10;                                        // LED1 light
int led2 = 12;                                       // LED2 light
int buzz = 11;                                       // Active buzzer
int motor = 2;                                      // DC motor

void setup() {
lcd.begin(16,2);                                     // LCD screen initiated
//lcd.clear();                                         // LCD screen cleared
scale.begin(LOADCELL_DOUT_PIN, LOADCELL_SCK_PIN);    // HX711 reading DT & SCK pins
pinMode(led1, OUTPUT);                               // LED1 light
pinMode(led2, OUTPUT);                               // LED2 light
pinMode(buzz, OUTPUT);                               // Active buzzer
pinMode(motor, OUTPUT);                              // DC motor
}

void loop() {
lcd.clear();                                         // LCD screen cleared
if (scale.is_ready()) {                              // HX711 - Zero out scale
long reading = scale.read();                         // HX711 - Reading for weight reading
weight = ((302443.9333-reading)/-1830);              // HX711 calculation for weight
lcd.setCursor(0,0);                                  // HX711 - Sets the cursor to col 0, row 0 on LCD
lcd.print("Weight(gm):");                            // HX711 - Displays "Weight(gm):" on LCD
lcd.print(weight);                                   // HX711 - Displays Weight value on LCD
digitalWrite(led1, LOW);                             // LED1 light turns OFF
digitalWrite(led2, LOW);                             // LED2 light turns OFF
digitalWrite(buzz, LOW);                             // Active buzzer OFF
digitalWrite(motor, HIGH);                           // DC motor ON

if (weight > 225){                                   // HX711 weight limit for alarms
lcd.setCursor(0,0);                                  // HX711 - Sets the cursor to col 0, row 0 on LCD
lcd.print("Bin is full.....");                       // HX711 - Displays "Bin is full....." on LCD
lcd.setCursor(0,1);                                  // HX711 - Sets the cursor to col 0, row 0 on LCD
lcd.print("MaxWeight: 225g");                        // HX711 - Displays "Bin is full....." on LCD
digitalWrite(led1, HIGH);                            // LED1 light turns ON
digitalWrite(led2, LOW);                             // LED2 light turns OFF
digitalWrite(buzz, HIGH);                            // Active buzzer ON
digitalWrite(motor, LOW);                            // DC motor OFF
delay(200);                                          // Delay of 0.2sec reading on LCD             
digitalWrite(led1, LOW);                             // LED1 light turns OFF
digitalWrite(led2, HIGH);                            // LED2 light turns ON
digitalWrite(buzz, LOW);                             // Active buzzer OFF
digitalWrite(motor, LOW);                            // DC motor OFF
delay(200);                                          // Delay of 0.2sec reading on LCD
}
} else {
lcd.print("");                                       // HX711 - Displays "Error!" on LCD
}
delay(100);                                          // HX711 - Delays 0.1sec reading on LCD
}

Wireing diagram (This shows an Uno but using a Mega):

IF your fritzie drawing is correct, you CANNOT power any motor from an Arduino pin, ever!!!
You need to have a transistor of some kind that the Arduino can control and the transistor will, in turn, control the motor power. Fix that before anything else. When that is done, you need a 12 volt power supply with enough current capability to run your motor, controlled by the transistor.
Good luck and make a block diagram showing how you have the new stuff connected.

Here is a MOSFET motor driver.

I don't know what a MOSFET motor driver is and I'm positive I don't have one. With that being said, I came across a old code that I created for an encoder DC motor. I'm wondering if this can be used/modified and placed into my above code? I have on person tell me that I need to send the "pwmVal" with analogWrite, not just the digitalWrite. I didn't understand what he means?
Here is my other code for an encoder DC motor that I used in our other project:

/*
Description:
a. Modify the code to move the motor clockwise and counterclockwise based on the press of two buttons.
b. The motor should turn continuously until the direction is changed again.
*/

#include <util/atomic.h>  // For the ATOMIC_BLOCK macro
#define ENCA 2            // YELLOW
#define ENCB 3            // WHITE
#define PWM 5
#define IN2 7
#define IN1 8
#define clk 9
#define counterclk 10
int dir, pwmVal, pwm, pwr;
volatile int posi = 0;  // specify posi as volatile

void setup() {
  Serial.begin(9600);
  pinMode(ENCA, INPUT);
  pinMode(ENCB, INPUT);
  attachInterrupt(digitalPinToInterrupt(ENCA), readEncoder, RISING);
  pinMode(PWM, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  Serial.println("Task2 L298N control DC motor");
}

void loop() {
  int pos = 0;
  ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
    pos = posi;
  }
  pwmVal = 120;                    // sample pwm value to move the motor
  if (digitalRead(clk) == HIGH) {  // verify the motor turns clockwise
    dir = 1;
    pwr = fabs(pwmVal);  // signal the motor
    setMotor(dir, pwr, PWM, IN1, IN2);
  } else if (digitalRead(counterclk) == HIGH) {  // verify the motor turns counterclockwise
    dir = -1;
    pwr = fabs(pwmVal);  // signal the motor
    setMotor(dir, pwr, PWM, IN1, IN2);
  }
  Serial.print("PWM value: ");  // display the PWM value on the serial monitor
  Serial.print(pwr);
  Serial.print(" | Directon: ");  // display the motor direction on the serial monitor
  Serial.print(dir);
  Serial.println();
}

void setMotor(int dir, int pwmVal, int pwm, int in1, int in2) {
  analogWrite(pwm, pwmVal);
  if (dir == 1) {             // determine if the motor direction is clockwise
    digitalWrite(in1, HIGH);  // pin8 as OUTPUT (On) and toggles between pin7
    digitalWrite(in2, LOW);   // pin7 as OUTPUT (Off) and toggles between pin8
  } else if (dir == -1) {     // determine if the motor direction is counterclockwise
    digitalWrite(in1, LOW);   // pin8 as OUTPUT (Off) and toggles between pin7
    digitalWrite(in2, HIGH);  // pin7 as OUTPUT (On) and toggles between pin8
  } else {
    digitalWrite(in1, LOW);  // pin8 as OUTPUT (Off) and toggles between pin7
    digitalWrite(in2, LOW);  // pin7 as OUTPUT (Off) and toggles between pin8
  }
}

void readEncoder() {
  int b = digitalRead(ENCB);
  if (b > 0) {
    posi++;
  } else {
    posi--;
  }
}

I hoping with this code and my original code above can be somehow used together to get the motor to supply more torque (the speed of the motor can remain low).
Thanks

... set 'pwmVal' to a higher value.

Use a higher voltage motor power supply and appropriate motor driver.

How would I set the "pwmVal" to a higher value when I don't have it defined with a value?

Change this line where you set the value:

Of couse...I was looking right at it but didn't see it. I'll try that. Thanks.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.