I connected my motor and a servo to my L293D motor shield and i used a 3.7 volt battery with 4800 mAh. I also connected a button to on and off the motor for a certain amount of time but only the servo is working properly while my motor doesn't run.
HERE IS THE CODE
int LEDPin=11;
int buttonPin=4;
int buttonNew;
int buttonOld=1;
int dt=100;
#include <Servo.h>
#include <AFMotor.h>
Servo myservo;
int servopin(10);
AF_DCMotor motor1(1);
void setup(){
Serial.begin(9600);
pinMode(LEDPin,OUTPUT);
pinMode(buttonPin,INPUT);
myservo.attach(servopin);
motor1.setSpeed(200);
}
void loop(){
buttonNew=digitalRead(buttonPin);
if(buttonOld==0 && buttonNew==1){
if (LEDState==0){
digitalWrite(LEDPin,HIGH);
myservo.write(0);
Serial.print(buttonOld);
int motorpos='0';
int motorpos2='1';
if (motorpos=='0'){
motor1.run(FORWARD);
delay(2000);
motorpos='1';
}
if(motorpos='1'){
motor1.run(RELEASE);
}
LEDState=1;
}
else{
digitalWrite(LEDPin,LOW);
myservo.write(90);
Serial.print(buttonNew);
int motorpos='0';
int motorpos2='1';
if (motorpos=='0'){
motor1.run(BACKWARD);
delay(2000);
motorpos='1';
}
if (motorpos='1'){
motor1.run(RELEASE);
}
LEDState=0;
}
}
buttonOld=buttonNew;
delay(dt);
}