Arduino How to control speed of DC motor without potentiometers




Schematic diagram

Wiring

L298n ENA to pin 3 on Arduino
L298n IN1 to pin 4 on Arduino
L298n IN2 to pin 5 on Arduino

Arduino Sketch


int motor1_ena = 3;
int motor1_in1 = 4;
int motor1_in2 = 5;

void setup() {
  // put your setup code here, to run once:
   pinMode( motor1_ena , OUTPUT);
   pinMode( motor1_in1 , OUTPUT);
   pinMode( motor1_in2 , OUTPUT);

   digitalWrite( motor1_in1, HIGH);
   digitalWrite( motor1_in2, LOW );

   analogWrite( motor1_ena , 50); // 0 - 255 DC Motor speed
}

void loop() {
  // put your main code here, to run repeatedly:

}

ความคิดเห็น