What I'm basically are trying to do is to control the direction and the speed of a dc motor with only one potentiometer. The travel from zero to 520 is left turn, from 521 till 523 is motor stop, from 524 till 1023 is right turn. But the more you move towards the zero or 1023 the faster the motor has to be turning.
I know that with an L298N you can control a dc motor, but how can I integrate the pot meter in the schematics?
I've done a lot of googling on the net the last couple of weeks, but nothing I found was exactly what I needed. Therefore I posting my project here. Figuring out how to build the schematic is one thing, but due to my newbie state in writing sketch for Arduino this is just not so easy. I'm seeking help in "sketching" to be able to let this project work. Does anybody have a sketch that can do what I want to do in my project?
I know that with an L298N you can control a dc motor, but how can I integrate the pot meter in the schematics?
You haven't posted any schematics, so that would be a difficult question to answer. "Between here and there" is useless unless we have a common understand of where here and there are.
You need to use PWM outputs so you can control motor speed.
Something like this, mapping the pot readings to 250 to 0 and 0 to 250 to the PWM pins.
void loop(){
speed = analogRead(A0);
if (speed < 521){
analogWrite(rightPWMpin, 0);
analogWrite (leftPWMpin, ((1023-speed)/2)); // 250 to 0 to left side
}
if ((speed >520) && (speed < 524)) {
analogWrite(rightPWMpin, 0);
analogWrite(leftPWMpin, 0);
}
if (speed > 523){
analogWrite(leftPWMpin, 0);
analogWrite (rightPWMpin, ((speed - 523)/2)); // 0 to 250 to right side
}
}
Thx for your sketch, PWM is something I did look at, but didn't think that was useful for my purpose. I will look more in depth on this subject. Thanks for the advice!!
Would you be willing in helping me complete this sketch "void setup", "void loop"?
If not I'll understand of course, but on my own it will cost my weeks.
I've done some testing with the sketch from CrossRoads, but no succes!
I think I've connected all parts correctly.
Also, in this sketch, I didn't find any direction code.
The direction of the motor should also be controlled by the same
potentiometer, which controls the speed.