int enA = 9;
int in1 = 8;
int in2 = 7;
int SpeedControl1 = A0;
int MotorSpeed1 = 0;
void setup()
{
pinMode(enA, OUTPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
}
void loop() {
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
MotorSpeed1 = analogRead(SpeedControl1);
MotorSpeed1 = map(MotorSpeed1, 0, 1023, 0, 255);
if (MotorSpeed1 < 8)MotorSpeed1 = 0;
analogWrite(enA, MotorSpeed1);
}
The problem is this:
Initially I tried to run my mechanics by applying the current directly from my adapter to the motor. This worked fine, and the machine was working properly. Even on with 3 volts it was running fine, and the RPM increased by increasing the voltage on the adapter. So i was confident the motor was up to the job.
Then I tried the same thing, but with the previously mentioned PWM setup. The motor now only kicks in when I fully ‘open-up’ the potentiometer. It only achieves an RPM equivalent to about the 6volts directly from the adapter, not higher-nor lower.
Any suggestions? I was looking into maybe using other motor shields, and upgrading the adapter.
Is this just an inherent limitation to the use of PWM, so maybe there is another more suitable aproach?
Frozenking:
Initially I tried to run my mechanics by applying the current directly from my adapter to the motor. This worked fine, and the machine was working properly. Even on with 3 volts it was running fine, and the RPM increased by increasing the voltage on the adapter. So i was confident the motor was up to the job
Please explain this more clearly - a diagram would be a good idea - so that I can understand how it differs from the other arrangement.
Please explain this more clearly - a diagram would be a good idea - so that I can understand how it differs from the other arrangement.
What I meant is that I simply put the + and - of the powersource (adapter) directly on the motor, compared to the diagram described in the dronebotworkshop website (which entails putting those wires in the L298N)
I suspect it’s less to do with PWM and more that you’re falling over the fact that the ancient L298N cannot supply much current and tends to drop 2-2.5V of any available voltage.
But it might make sense to include a Serial.print() to show you exactly what values you are writing to enA.
There is a MINIMUM PWM that will start the motor, but once started you can turn the PWM down gradually until the motor stalls, I won’t tell you to set the adapter to 12V until I see a wiring diagram.
It should be able to put more power into the engine, but I do not notice a difference between this driver and the L298N. It is still not able to turn the engine, while a direct hook-up to the adapter works at ranges from 3 to 12v.
I assume it is not possible/reliable to measure the voltage that gets to the engine since it is power by PWM?
I will take a picture of the setup and wiring when I get home so you get a better picture of the issue.
If you have a Digital Multi Meter measure the voltage at the motor driver output pins or directly on the motor terminals. Hope you considered the motor’s stall current when selecting a driver and power supply.