I am working on a project. For that I have to regulate the speed of an engine.
I wanted to do this with pwm. But this doesn't work.
Could it be that the capacitor is the problem? That this capacitor gives the motor power when the signal from the arduino is interrupted by PWM?
With all due respect, but we will need a bit more information about the engine and the capacitor before we can give you any descent advise. What Voltage is the engine rated for? What capacity does the capacitor have, it looks like a small cap but a value would be helpful to give you advice.
The capacito has the number 104 on it. That is the only thing I know about it. This is what i found about the engine. It works 3-6 V, 6V ≤200mA 200 ± 10% min, 3V ≤150mA 90 ± 10% min. But I don't know what they mean with it.
But can I just remove the capacitor?
Of course it will not run below a certain value, since your motor is rated for a min Voltage of 3 volt. And it can not turn at it's max rpm since you can't reach it's max voltage of 6 volt. How do you determine at what speed it's turning, visually? The min rpm is 90 and the max, I don't know since it's rated at 200 rpm at 6 volts, you can't reach that. You need a way to measure it, a multimeter is a start.
I do think you missed the point of my previous post. I do believe it's going faster and slower, you just can't see that, because the difference in speed is to slow to visually determine this. That's why I said to put a multimeter on the motor. Does that Voltage change? If yes, then it works like you want.
My program works but when the value of 'potwaarde' is under 128 it just stops running. Above 128 it runs on max speed.
Of course that's the the way it works, you're writing to a pin (4) that does not support PWM output, assuming you're using an Uno or other '328 based board.
From the analogWrite() reference: On most Arduino boards (those with the ATmega168 or ATmega328P), this function works on pins 3, 5, 6, 9, 10, and 11.
robbeserry:
I use a H-bridge (L293D). Everything is connected correct.
The link in post#0 does not work, so how can we be sure.
Do you have a 8-9volt supply for your 6volt motor (the L293D is old technology, and looses about 2.5volt).
That supply shouldn't be a 9volt smoke alarm battery (not enough current available).
I have re-written your sketch (untested).
Leo..
const byte potPin = A0;
const byte enablePin = 4;
const byte controlA = 5; // PWM pin
const byte controlB = 6;
int potWaarde;
void setup() {
pinMode(enablePin, OUTPUT);
pinMode(controlA, OUTPUT);
pinMode(controlB, OUTPUT);
digitalWrite(enablePin, HIGH); // not changed on loop(), so moved to setup()
digitalWrite(controlB, LOW); // same
}
void loop() {
potWaarde = map(analogRead(potPin), 0, 1023, 100, 255); // change '100' for minimum motor run
analogWrite(controlA, potWaarde);
delay(250);
}
robbeserry:
I use a H-bridge (L293D). Everything is connected correct.
Then you won't kind showing us how everything's connected with us so we can check.
BTW change the 100nF cap to 1nF, much more sensible value.
[ 1nF--10nF is plenty for RF suppression of arcing noise, larger values start to risk increasing EMI
generation by causing heavy current spikes as the motor driver switches on, with PWM this becomes
important ]