Smart Home Automation Forum
[arduino code examples for MT4]-04 DC motor control by L298N driver chip - Printable Version

+- Smart Home Automation Forum (https://www.kincony.com/forum)
+-- Forum: Technical Support (https://www.kincony.com/forum/forumdisplay.php?fid=114)
+--- Forum: MT4 (https://www.kincony.com/forum/forumdisplay.php?fid=115)
+--- Thread: [arduino code examples for MT4]-04 DC motor control by L298N driver chip (/showthread.php?tid=9612)



[arduino code examples for MT4]-04 DC motor control by L298N driver chip - admin - 07-11-2026

Code:
/*
* Language: English | Русский: ../RU/DIR_DIR_PWM/ | Қазақ: ../KZ/DIR_DIR_PWM/
*
* This code demonstrates motor control using the AlashMotorControlLite library.
* It sets different rotation speeds for the motor with delays between them.
* Code written for Alash engineering.
*/
#include "AlashMotorControlLite.h"
// Create motor object with DIR_DIR_PWM mode and pins inA = 4, inB = 5, PWM = 6
AlashMotorControlLite motor(DIR_DIR_PWM, 39, 46, 9);
void setup() {
}
void loop() {
  motor.setSpeed(100); // Set forward rotation speed
  delay(3000); // Delay 3 seconds

  motor.setSpeed(0); // Stop motor
  delay(3000); // Delay 3 seconds

  motor.setSpeed(-100); // Set reverse rotation speed
  delay(3000); // Delay 3 seconds

  motor.setSpeed(0); // Stop motor
  delay(3000); // Delay 3 seconds
}
arduino ino file download: 

.zip   motor.zip (Size: 560 bytes / Downloads: 19)
BIN file (you can use esp32 download tool download to ESP32-S3 with address 0x0 then directly to use) download:

.zip   motor.ino.merged.zip (Size: 184.36 KB / Downloads: 9)