Not the most original question but nonetheless, I am new to C++ but I wanted to try to control the speed of DC motor with a potentiometer(below should be an image of the circuitry). I have also attached the code. The problem I am facing is that, whenever the potentiometer is at one extreme end, the rpm of the motor is 0, then whenever I turn the knob slightly from that end, the rpm goes from 0 gradually to 5555. I am trying to learn how to control dc motors with sensors, such as potentiometers, ultrasonic, pressure etc. so that is the main inspiration here. I do not understand where I have went wrong with the code, so could I have some guidance here please? And also any tips for the future, in case I make any similar mistakes.
int potin;
int pot;
void setup()
{
pinMode(A0, INPUT);
pinMode(11, OUTPUT);
}
void loop()
{
pot = analogRead(A0);
potin = map(pot, 0, 1023, 0 , 255);
digitalWrite(11, potin);
}