Help with button powering on Servo and DC Motor

I'm working on a fan project for my engineering class, I have to make a button turn on a dc motor and servo motor and have a potentiometer control the speed of my dc motor.

I have it figured out mostly but I keep running into some problems that I've spent hours working on and I still can't seem to figure out:

*The dc motor won't start unless I literally spin it a little with my hand to get it started, I think it's a problem with it getting enough power, but I have it plugged into the 5v power source and it's the only thing besides the potentiometer that's getting powered by it.

*The potentiometer adjusts the speed of the DC Motor but there's a delay between when I move the potentiometer to a different value and when you can observe the difference in speed on the motor.

*The servo motor shakes a little at the end of each rotation and when the button is off, instead of just not moving it continues to just shake until you turn it on again.

*The button turns everything off but the servo motor first finishes it's movement back to the original position, I was wondering if there was anyway to make it just stop where it was, but that's not too important.

I saw someone else had a very similar problems but the way they wrote their code is different from mines, I'm using interrupts and I'm still new to writing code and not sure how to make what worked for them work for me without just completely copying their code.

Any help at all about any of the problems above would be much appreciated.

int button_interrupt = 0; 
int toggle_on = false; 
int motor = 5;
int sensor_pin = A0;
int servo_pin = 10;
#include<Servo.h>
Servo myservo;

void setup() {

 Serial.begin(9600);
 attachInterrupt( button_interrupt, handle_click, RISING); // 
 pinMode(13, OUTPUT);
 pinMode (motor, OUTPUT);
 myservo.attach(servo_pin);
 pinMode (servo_pin, OUTPUT);
}

void loop() {
  
  int pot_val, motor_speed;
 
 pot_val = analogRead( sensor_pin );
 motor_speed = map(pot_val, 0, 1023, 0, 255);

  if ( toggle_on ) {
   digitalWrite(13, HIGH);
   Serial.println("on");
   analogWrite(motor, motor_speed);
  
   int pos = 0;
   int dtwait = 15;
   
   for(pos=0; pos <180; pos +=1){
     myservo.write(pos);
     delay(dtwait);
   }
   for (pos = 180; pos>=1; pos-=1){
     myservo.write(pos);
     delay(dtwait);
   }
 
      
   
 } else {
   
   digitalWrite(13, LOW);
 Serial.println("off");
 analogWrite (motor, 0);
 digitalWrite(servo_pin, LOW);
 }
}

void handle_click()
{
 static unsigned long last_interrupt_time = 0; 
 unsigned long interrupt_time = millis(); 
 if ( interrupt_time - last_interrupt_time > 200 ) { 
 toggle_on = !toggle_on;
 }
 last_interrupt_time = interrupt_time;
}

Hi-

I don't have time to go through your sketch closely, since I'm at work already (630am here....).

But I think you're right about the power thing. When you say "plugged into the 5v power source" do you mean the 5V on the Arduino? If so that may well be the issue since it's not meant to provide hefty current. The stall current of a motor- which is what it needs to get moving- is much higher than that drawn under normal running.

Also I'd be really surprised if interrupts are needed in your project: I did some tests a while back an an empty loop() zooms through at some 150000 times a second. So even with actual code doing stuff, it's likely to be fast enough to see your button presses just by looping with no interrupts.

It's a good idea to post a schematic by the way... especially when there are possible power issues.

Your motor should be hooked up something like in the attached pic, with a transistor and a flyback diode. Let's see yours?

motor and pot.png

By the way, a servo should have its own power too, not from the Arduino; see attached which shows 3 servos...

servo power.png