အနုပညာ
အလှအပနှင့် ကျန်းမာရေး
လက်မှုအနုပညာ
ယဉ်ကျေးမှုနှင့် သမိုင်း
ဖျော်ဖြေရေး
ပတ်ဝန်းကျင်
အစားအစာနှင့် အချိုရည်
စိမ်းလန်းသောအနာဂတ်
ပြောင်းပြန်အင်ဂျင်နီယာပညာ
သိပ္ပံပညာများ
အားကစား
နည်းပညာ
ဝတ်ဆင်နိုင်သောပစ္စည်းများ
Controlling a DC Motor with an L298N Driver
Ed

ဖန်တီးသူ

Ed

13. ဇူလိုင် 2026FI

Controlling a DC Motor with an L298N Driver

An Arduino pin can't power a motor directly — it can't supply enough current, and it can't reverse the flow. An L298N H-bridge solves both: the Arduino sends low-power control signals, and the driver switches the motor's own battery to run it forwards, backwards and at any speed. This is the core building block of every wheeled robot.

အလယ်အလတ်
1-2 hours

ညွှန်ကြားချက်များ

1

Wire the driver, motor and battery

Push the L298N's control header into the breadboard. From the Arduino, jumper pin 8 to IN1, pin 9 to IN2, and pin 10 to ENA. Connect the DC motor's two wires to the OUT1/OUT2 screw terminals, and a 4×AA battery pack to the +12V and GND motor terminals. IMPORTANT: join all the grounds together — Arduino GND, driver GND and battery GND — or the motor won't run.

Materials for this step:

Arduino Uno R3 SMDArduino Uno R3 SMD1 ခု
Full-Bridge Motor Driver Dual - L298NFull-Bridge Motor Driver Dual - L298N1 ခု
Hobby Motor - GearHobby Motor - Gear1 ခု
Battery Holder - 4xAA Square TerminatedBattery Holder - 4xAA Square Terminated1 ခု
Breadboard - ClassicBreadboard - Classic1 ခု
Jumper Wires Premium M/M 20 AWG - 15.5 cmJumper Wires Premium M/M 20 AWG - 15.5 cm1 ထုပ်
2

Connect and open the IDE

Plug the Arduino into your computer with the USB cable, open the Arduino IDE, and select Arduino Uno and its serial port. Leave the motor battery switched off until the code is uploaded.

Materials for this step:

SparkFun Cerberus USB Cable - 1.8 meterSparkFun Cerberus USB Cable - 1.8 meter1 ခု

Tools needed:

Computer with Arduino IDEComputer with Arduino IDE
3

Upload the motor sketch

Paste this sketch and upload, then switch on the battery. The motor runs forward, stops, reverses, and stops — on a loop.

dc_motor_l298n.inoarduino
// Control a DC motor's speed and direction with an L298N H-bridge.
// L298N IN1 -> pin 8, IN2 -> pin 9, ENA (PWM speed) -> pin 10.
// The motor is powered by the battery pack through the driver; all grounds are joined.

const int IN1 = 8;
const int IN2 = 9;
const int ENA = 10;   // PWM speed pin (0-255)

void setup() {
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(ENA, OUTPUT);
}

void loop() {
  // forward at medium speed
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  analogWrite(ENA, 180);
  delay(2000);

  // stop
  analogWrite(ENA, 0);
  delay(1000);

  // reverse at full speed
  digitalWrite(IN1, LOW);
  digitalWrite(IN2, HIGH);
  analogWrite(ENA, 255);
  delay(2000);

  // stop
  analogWrite(ENA, 0);
  delay(1000);
}
4

Test and control it

Watch the motor go forward, stop, reverse. IN1/IN2 set the direction (swap which is HIGH to flip it); the number in analogWrite(ENA, ...) sets the speed from 0 (off) to 255 (full). If the motor doesn't spin, check that all three grounds are joined and the battery is on.

5

Make it a robot

The L298N drives TWO motors. Wire a second motor to OUT3/OUT4 and control it with IN3, IN4 and ENB on three more Arduino pins. Two motors on a chassis with wheels gives you a robot base you can drive — turn by running the wheels at different speeds or directions.

ပစ္စည်းများ

7

လိုအပ်သော ကိရိယာများ

1
Estimated Total
$60.00

ဆက်စပ် အစီအစဉ်များ

ဤအစီအစဉ်များသည် အသိပညာမျှဝေသည် — နည်းပညာ၊ ပစ္စည်း သို့မဟုတ် မူများ

CC0 အများပိုင်

ဤအစီအစဉ်ကို CC0 အောက်တွင် ထုတ်ဝေထားသည်။ ခွင့်ပြုချက်မလိုဘဲ ကူးယူ၊ ပြင်ဆင်၊ ဖြန့်ဝေ နှင့် အသုံးပြုနိုင်သည်။

အစီအစဉ်မှတစ်ဆင့် ကုန်ပစ္စည်းများဝယ်ယူ၍ ဖန်တီးသူကို ပံ့ပိုးပါ ဖန်တီးသူ ကော်မရှင် ရောင်းချသူက သတ်မှတ်သည်၊ သို့မဟုတ် ဤအစီအစဉ်၏ ဗားရှင်းအသစ်ဖန်တီး၍ ဝင်ငွေခွဲဝေရန် သင့်အစီအစဉ်တွင် ချိတ်ဆက်မှုအဖြစ် ထည့်သွင်းပါ။

ဆွေးနွေးချက်

(0)

ဝင်ရောက် ဆွေးနွေးချက်တွင် ပါဝင်ရန်

Loading comments...