In the video tutorial above we describe the fundamentals of Robot Motor Control Using the L298N control module. This establishes the core functions that will be used throughout the remainder of these lessons. We show how we can create the core motion components of forward, backward, turn left and turn right. The code developed in the lesson above is presented below for your convenience. If you would like to play along at home, you can get the hardware I am using HERE:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | int ENA=5; int ENB=6; int IN1=7; int IN2=8; int IN3=9; int IN4=11; void setup() { // put your setup code here, to run once: pinMode(ENA,OUTPUT); pinMode(ENB,OUTPUT); pinMode(IN1,OUTPUT); pinMode(IN2,OUTPUT); pinMode(IN3,OUTPUT); pinMode(IN4,OUTPUT); digitalWrite(ENA,HIGH); digitalWrite(ENB,HIGH); } void loop() { // Right Turn digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); delay(1000); //Left Turn digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); delay(1000); //forward digitalWrite(IN1,HIGH); digitalWrite(IN2,LOW); digitalWrite(IN3,LOW); digitalWrite(IN4,HIGH); delay(1000); //backwards digitalWrite(IN1,LOW); digitalWrite(IN2,HIGH); digitalWrite(IN3,HIGH); digitalWrite(IN4,LOW); delay(1000); } |