arduino motor control code example

Example 1: 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);  

}

Example 2: how to code dc motors

Watch https://www.robolink.com/programming-the-dc-motors/

Tags:

Misc Example