I have uploaded both code and circuit, please tell me where I have went wrong as I am trying to control the speed of the motor with a potentiometer, however the motor does not turn at all.
[SOLVED]
Included the motor direction control pins in the code and it works.
Just say NO as they can't provide enough current to run a motor, at least not for long enough to be useful
Please post a schematic of your project so that the components and connections can easily be identified. A picture of a pencil and paper drawing is good enough
hopefully its clearer to see here. Just in case, I will write out the connections too.
Enable pin is connected to D10
Pot signal pin is connected to A0
All the grounds are connected to the negative breadboard pins, and as they are all common I have then continued to connect them to the arduino ground pins.
Pot power wire and L293DNE power input wire are connected onto the electrically common positive line, and are then connected to the arduino 5V.
The 9V battery power wire is connected to the L293DNE power output pin.
Motor is connected to both output pins 1 and 2.
I only need the motor to run long enough that I can see it's speed being controlled by the potentiometer, however yes it is not running, so would you say this is a current issue or something to do with my circuit or code that I can fix. I have done this..
int motor = 10;
int pot = A0;
int motorspeed;
void setup() {
//pinMode(motor, OUTPUT);
pinMode(pot, INPUT);
Serial.begin(9600);
}
void loop() {
motorspeed = analogRead(pot)/4;
//analogWrite(motor, motorspeed);
Serial.print(motorspeed);
delay(1000);
}
And the potentiometer values are returned correctly, and I have tried copying the circuit connection from the arduino projects handbook so I am not too sure where I went wrong. Perhaps a misstep.
The values of the potentiometer(mapped) are shown, such as 0, 42, 168, 255 etc. (any between 0-255)
How do you mean? Are you saying I should Serial.print(pot) and then divide it by 4? Would it not just print out the analog values(rather than digital) and not change much? Can you elaborate please, thank you.
pot is pin A0.
I have read the pin into motorspeed(pin digital 10), it is coming with values between 0-255. I am unsure as to why I would need to divide the PWM values by 4, as they have already been mapped prior from 0-1023
I guess you are using a different program from what you posted. Motorspeed is an int. You need to draw a schematic of your project and post a picture of it. Something is drastically wrong.
No it is alright now, I have included the motor direction pins, originally thinking they were not needed for speed, however they are, and the motor spins now and follows the code well.
And the above declaration is correct, but thank you.