0Pricing
Arduino & IoT Academy · Lekcja

Prędkość i kierunek za pomocą mostka H

Sterować silnikiem prądu stałego za pomocą modułu L298N.

Prędkość i kierunek za pomocą mostka H to bezpłatna lekcja Arduino & IoT Academy na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Arduino & IoT Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

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. 🚀

Często zadawane pytania

Czy lekcja „Prędkość i kierunek za pomocą mostka H” jest bezpłatna?

Tak — pełny tekst „Prędkość i kierunek za pomocą mostka H” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Arduino & IoT Academy, przejdź na CoddyKit PRO. Kurs Arduino & IoT Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Prędkość i kierunek za pomocą mostka H”?

Sterować silnikiem prądu stałego za pomocą modułu L298N. Ćwiczysz Arduino & IoT Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Arduino & IoT Academy?

Nie wymagamy żadnego doświadczenia. Arduino & IoT Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Prędkość i kierunek za pomocą mostka H”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Arduino & IoT Academy?

Tak. Każda lekcja Arduino & IoT Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Dlaczego potrzebny jest sterownik
  2. Prędkość i kierunek za pomocą mostka H
  3. Przełączanie urządzeń sieciowych przekaźnikiem
  4. Ochrona przed przepięciami indukcyjnymi
← Powrót do Arduino & IoT Academy