L298N MOTOR DRIVER HACK WITH ATMEGA328P MICRO CONTROLLER IC || HC-05 BL...


COMPONENTS LIST:- 1. L298N MOTOR DRIVER. 2. ATMEGA328P IC. 3. 16MHZ CRYSTAL OSCILATOR. 4. 22PF CERAMIC CAPACITORS X 2. 5. ZERO PCB BOARD. 6. MALE AND FEMALE BERGE STRIP PINS.

CIRCUIT:-






CODE:-
int ENABLEAB = 3;//ENAB
int LMT1  = 12;//IN1
int LMT2  = 11;//IN2
int RMT1  = 10;//IN3
int RMT2  = 9;//IN4
char command; 

void setup() {
  Serial.begin(9600);
  pinMode(LMT1, OUTPUT);
  pinMode(LMT2, OUTPUT);
  pinMode(RMT1, OUTPUT);
  pinMode(RMT2, OUTPUT);
  pinMode(ENABLEAB, OUTPUT);

}

void loop() {
 if(Serial.available() > 0){ 
    command = Serial.read(); 
    Serial.println(command); 

//FORWARD..............
if(command == 'F' ){
  forward();
}
//BACKWARD..............
else if(command == 'B' ){
  backward();
}
//LEFT..............
else if(command == 'L' ){
  left();
}
//RIGHT..............
else if(command == 'R' ){
  right();
}

//STOP..............
else{
  stp();
}

}
}

void forward(){
  digitalWrite(LMT1, HIGH);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, HIGH);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}



void backward(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH);
  analogWrite(ENABLEAB, 200);
}


void left(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, HIGH);
  digitalWrite(RMT1, HIGH);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 200);
}

void right(){
  digitalWrite(LMT1, HIGH);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, HIGH);
  analogWrite(ENABLEAB, 200);
}

void stp(){
  digitalWrite(LMT1, LOW);
  digitalWrite(LMT2, LOW);
  digitalWrite(RMT1, LOW);
  digitalWrite(RMT2, LOW);
  analogWrite(ENABLEAB, 0);
}

Post a Comment

0 Comments