Hブリッジで速度と方向を制御する
L298NモジュールでDCモーターを制御します。
「Hブリッジで速度と方向を制御する」はCoddyKit上の無料Arduino & IoT Academyレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これは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); // forwardReversing 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); // reverseStopping 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% speedPowering 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. 🚀
よくある質問
「Hブリッジで速度と方向を制御する」レッスンは無料ですか?
はい。「Hブリッジで速度と方向を制御する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Arduino & IoT Academyコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Arduino & IoT Academyコースには全4レッスンが含まれています。
「Hブリッジで速度と方向を制御する」で何を学びますか?
L298NモジュールでDCモーターを制御します。 ブラウザで直接実行するハンズオンコードでArduino & IoT Academyを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
Arduino & IoT Academyを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのArduino & IoT Academyは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「Hブリッジで速度と方向を制御する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このArduino & IoT Academyレッスンでコードを書いて実行できますか?
はい。すべてのArduino & IoT Academyレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- ドライバーが必要な理由
- Hブリッジで速度と方向を制御する
- リレーで商用電源機器を切り替える
- 逆起電力のスパイクから保護する