Hello, we are currently using a DC motor to power a winch that lifts a heavy object off of the ground. The object can be lifted when the motor is engaged, but the motor does not seem to be strong enough to hold it in place once it reaches the top since the object’s weight seems to pull the motor beyond what the torque can handle. Is there a way to stop the object from falling down and force the motor to have more powerful braking via a current? I will attach our code below.
We are using the following hardware:
30:1 Metal Gearmotor 37Dx68L mm 12V with 64 CPR Encoder (Helical Pinion)
TB9051FTG Single Brushed DC Motor Driver Carrier
const int pwm1 = 5;
const int pwm2 = 6;
const int en = 3;
const int enb = 9;
const int lightSensor = A7;
int brightness = 0;
bool shouldTurnOtherWay = false;
bool wasAlreadyOn = false;
bool wasAlreadyOff = false;
void setup() {
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(en, OUTPUT);
pinMode(enb, OUTPUT);
pinMode(lightSensor, INPUT);
Serial.begin(115200);
}
void loop() {
brightness = analogRead(lightSensor);
Serial.println(brightness);
if (brightness < 500 && !wasAlreadyOff) {
wasAlreadyOff = true;
wasAlreadyOn = false;
// motor stops
analogWrite(pwm1,0);
analogWrite(pwm2,0);
analogWrite(en,255);
analogWrite(enb,0);
delay(100);
}
if (brightness >= 500 && !wasAlreadyOn) {
wasAlreadyOn = true;
wasAlreadyOff = false;
if (shouldTurnOtherWay) {
//motor spins clockwise
analogWrite(pwm1,255);
analogWrite(pwm2,0);
analogWrite(en,255);
analogWrite(enb,0);
delay(100);
} else {
//motor spins counterclockwise
analogWrite(pwm1,0);
analogWrite(pwm2,255);
analogWrite(en,255);
analogWrite(enb,0);
delay(100);
}
shouldTurnOtherWay = !shouldTurnOtherWay;
}
}