0Pricing
Arduino & IoT Academy · Урок

Скорость и направление с Н-мостом

Управляйте двигателем постоянного тока с помощью модуля L298N.

«Скорость и направление с Н-мостом» — бесплатный урок Arduino & IoT Academy на CoddyKit. Это урок 2 из 4. Ты можешь прочитать весь урок бесплатно ниже — а потом практиковать его прямо в браузере с встроенным редактором кода и ИИ-репетитором 24/7. Это часть пути обучения Arduino & IoT Academy, и твой прогресс синхронизируется между веб-версией и приложением CoddyKit. Курс Arduino & IoT Academy содержит 4 уроков всего.

Части этого урока еще не переведены и отображаются на английском.

Spinning Both Ways

A plain transistor runs a motor in one direction. To make wheels go forward and back, you need a smarter circuit called an H-bridge. 🔁

Why the H Shape

An H-bridge uses four switches arranged like the letter H. The motor sits in the middle, and flipping pairs of switches reverses the current through it.

Meet the L298N

The L298N is a popular H-bridge module. It can drive two DC motors and handles enough current for hobby robots and small carts.

The Direction Pins

Each motor on the L298N has two direction inputs, called IN1 and IN2. Their combination decides which way the motor turns or whether it stops.

int IN1 = 7, IN2 = 8;
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);

Forward and Reverse

Set IN1 HIGH and IN2 LOW to spin one way; swap them to spin the other. The motor simply follows whichever input is higher. ➡️

digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW); // forward

Reversing the Spin

Flip the two inputs and the current through the motor reverses. This is the magic the H-bridge gives you that a lone transistor cannot.

digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH); // reverse

Stopping the Motor

Set both direction inputs the same, like LOW and LOW, and the motor coasts to a halt because no net current flows through it.

The Enable Pin Controls Speed

Each motor also has an enable pin. Feed it a PWM signal and the duty cycle sets how fast the motor spins, just like dimming an LED.

Speed with analogWrite

Send PWM to the enable pin with analogWrite. A value of 255 is full speed and lower numbers slow the motor down smoothly.

int ENA = 9;
analogWrite(ENA, 180); // about 70% speed

Powering the Module

The L298N takes its own motor voltage on a separate terminal. Always tie its ground to the Arduino ground so signals stay in sync.

Two Motors, Full Control

With direction inputs plus PWM enable pins, one H-bridge lets you steer a two-wheel robot at any speed and in any direction. 🤖

Quick Check

On an L298N, what does the enable pin control?

Recap

An H-bridge like the L298N reverses current to change direction, while a PWM enable pin sets the speed. Share ground and you control motors fully. 🚀

Часто задаваемые вопросы

Урок «Скорость и направление с Н-мостом» бесплатный?

Да — полный текст урока «Скорость и направление с Н-мостом» бесплатно доступен здесь в веб-версии. Чтобы практиковать его интерактивно (встроенный редактор кода и ИИ-репетитор 24/7) и разблокировать остальной курс Arduino & IoT Academy, подпишись на CoddyKit PRO. Курс Arduino & IoT Academy содержит 4 уроков всего.

Чему я научусь в уроке «Скорость и направление с Н-мостом»?

Управляйте двигателем постоянного тока с помощью модуля L298N. Ты практикуешь Arduino & IoT Academy с помощью реального кода, который запускаешь прямо в браузере, и ИИ-репетитор 24/7 отвечает на твои вопросы во время урока.

Нужен ли мне опыт, чтобы начать Arduino & IoT Academy?

Предыдущий опыт не требуется. Arduino & IoT Academy на CoddyKit структурирован для всех уровней — от новичков до продвинутых, поэтому ты можешь начать отсюда или с самого начала и учиться в своем темпе. Это урок 2 из 4.

Сколько времени занимает урок «Скорость и направление с Н-мостом»?

Большинство уроков CoddyKit занимают около 5–10 минут. Каждый из них компактный и интерактивный, поэтому ты постоянно делаешь прогресс и продолжаешь с того же места в веб-версии и приложении.

Можно ли писать и запускать код в этом уроке Arduino & IoT Academy?

Да. Каждый урок Arduino & IoT Academy включает встроенный редактор кода, поэтому ты пишешь и запускаешь реальный код прямо в браузере и получаешь моментальную обратную связь от AI — локальная установка не требуется.

Все уроки этого курса

  1. Зачем нужен драйвер
  2. Скорость и направление с Н-мостом
  3. Переключение сетевых устройств реле
  4. Защита от выбросов обратной ЭДС
← Назад к Arduino & IoT Academy