/* Project: L298N dual h-bridge motor driver module, 2 DC motors without speed control (constant maximum speed) Function: Both DC motors rotate to one direction then stop, rotate to another direction then stop. */ //************************************************************ int IN1 = 7;//input 1 of DC motor 1 attached to digital pin 7 int IN2 = 6;//input 2 of DC motor 1 attached to digital pin 6 int IN3 = 5;//input 3 of DC motor 2 attached to digital pin 5 int IN4 = 4;//input 4 of DC motor 2 attached to digital pin 4 //************************************************************ void setup() { pinMode (IN1, OUTPUT);//sets IN1 as OUTPUT pinMode (IN2, OUTPUT);//sets IN2 as OUTPUT pinMode (IN3, OUTPUT);//sets IN3 as OUTPUT pinMode (IN4, OUTPUT);//sets IN4 as OUTPUT } void loop() { //Both DC motors rotate one direction: digitalWrite (IN2, HIGH); digitalWrite (IN1, LOW); digitalWrite (IN4, HIGH); digitalWrite (IN3, LOW); delay(2000);//sets delay for 2 seconds //Both DC motors stops digitalWrite (IN2, LOW); digitalWrite (IN4, LOW); delay(4000);//sets delay for 4 seconds //Both DC motors rotate another direction: digitalWrite (IN1, HIGH); digitalWrite (IN2, LOW); digitalWrite (IN3, HIGH); digitalWrite (IN4, LOW); delay(2000);//sets delay for 2 seconds //Both DC motors stops digitalWrite (IN1, LOW); digitalWrite (IN3, LOW); delay(4000);//sets delay for 4 seconds }