L298d connection to motor code example

Example: arduino l298n code

//Pin Out
const int IN1 = 7;
const int IN2 = 6;
const int IN3 = 5;
const int IN4 = 4;

const int ENA = 9; //pin for speed control en1
const int ENB = 3; //pin for speed control en2


void setup() {

  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (IN3, OUTPUT);
  pinMode (IN4, OUTPUT);
  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);

}

void loop() {
 //control speed 
          //(pin, speed)  
  analogWrite(ENA, 255);
  analogWrite(ENB, 255); 
  
  //control direction 
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);  

}

Tags:

Misc Example