Motor Funcionality

Hola,


this is the code I am using for the engine but it does not work.
Can you tell me what is wrong with it?

Hola Karen, hablas espanol?

You shared two different sketches. Which one is the one you are using?

If you are using the second one, try the following:

int E1 = 6; //M1 Speed Control
int E2 = 5; //M2 Speed Control
int M1 = 8; //M1 Direction Control
int M2 = 7; //M2 Direction Control
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
int i;
for(i=5;i<=8;i++)
pinMode(i, OUTPUT);
Serial.begin(9600);
}
void loop()
{
int leftspeed = 255; //255 is maximum speed
int rightspeed = 255;
analogWrite (E1,leftspeed);
digitalWrite(M1,LOW);
analogWrite (E2,rightspeed);
digitalWrite(M2,LOW);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
analogWrite (E1,leftspeed);
digitalWrite(M1,HIGH);
analogWrite (E2,rightspeed);
digitalWrite(M2,HIGH);
digitalWrite(LED_BUILTIN, HIGH);
delay(2000);
}

Let me know what it does. Also, check if the built-in LED on the Arduino Board is blinking.

1 Like