/* Project: L298N dual h-bridge motor driver module, 1 DC motor with speed control Function: DC motor rotates with minimum, medium,high speed and stops */ //************************************************************ 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 int ENB = 3;//ENB of DC motor attached to PWM digital pin 3 //************************************************************ void setup() { pinMode (ENB, OUTPUT); //sets ENB as OUTPUT pinMode (IN4, OUTPUT);//sets IN4 as OUTPUT pinMode (IN3, OUTPUT);//sets IN3 as OUTPUT } void loop() { //DC motor is ready for turn digitalWrite (IN3, HIGH); digitalWrite (IN4, LOW); //sends to ENB pin PWM signal analogWrite(ENB, 55);//speed of rotation - 55 / min delay(2000);//sets delay for 2 seconds analogWrite(ENB, 105);//speed of rotation - 105 / medium delay(2000);//sets delay for 2 seconds analogWrite(ENB, 255);//speed of rotation - 255 / max delay(2000);//sets delay for 2 seconds analogWrite(ENB, 0);//stops the DC motor. It does not matter the state of inputs (IN) delay(4000);//sets delay for 4 seconds }