Servo and DC motor working at the same time


hi! need servo , dc motor working @ same time, each 1 controlled potentiometer (and mosfet dc motor), can see in picture attached.

if move servo, works fine, when switch on dc motor, servo goes 0ยบ automatically untill stop dc motor.

i simulated on 123d circuits , works. read on other forum impossible use pin 9 , 10 pwm when you´re using servo library, didn´t use those, tried pin combinations doesn´t work well.

i hope can me. time


code: [select]
#include <servo.h>
servo myservo;

int const potpin = a5; // analog pin used connect potentiometer
int potval;  // variable read value analog pin
int angle;

const int potmotpin = a0;
const int motorpin = 11;
const int servopin = 9;
int potvalor;
int ajustevel;

void setup() {
  pinmode(motorpin, output);
  pinmode (potmotpin, input);

  myservo.attach(servopin);
  serial.begin(9600);


}

void loop() {
  potvalor = analogread(potmotpin);
  serial.println(potvalor);

  ajustevel = potvalor / 4;
  delay(5);
  analogwrite(motorpin, ajustevel);

  potval = analogread(potpin); // read value of potentiometer
  // print out value serial monitor
  serial.print("potval: ");
  serial.print(potval);

  // scale numbers pot
  angle = map(potval, 0, 1023, 0, 179);

  // print out angle servo motor
  serial.print(", angle: ");
  serial.println(angle);

  // set servo position
  myservo.write(angle);

  // wait servo there
  delay(15);

}

the pp3 type of 9v battery unsuitable. can't provide enough current. use 6xaa cells if need 9v.

don't power motor or servo arduino 5v pin. give them own power supply common gnd arduino.

...r


Arduino Forum > Using Arduino > Project Guidance > Servo and DC motor working at the same time


arduino

Comments