l298n Introduction
l298n Drive module, can drive 2 DC Motor , can be used to achieve positive turn , reverse function.
BOM List
Arduino Uno * 1
l298n Drive Module * 1
DC Motor * 2
9v Battery * 1
Jumper several
Arduino Uno + l298n driver module wiring
Note: If the voltage is not enough , the motor may not turn oh, so to external 7v-12v power.
Program source code to upload the program to the motherboard, connected to the external power supply, the motor will turn up.
Here the IO port is selected as 5,6,9,10, which are all fourSupportPWM, which can be achieved through the duty-free codeControlTurnSpeedThe speed.
-------------------↓ You can press this button to copy the code-------------------↓
Lingshun Labint input1 = 5; Defines a UNO pin 5 to input1 output int input2 = 6; Defines a UNO pin 6 to input2 output int input3 = 9; Defines a UNO pin 9 to input3 output int input4 = 10; Define UNO pin 10 to input4 output void Setup () {// Serial.begin (9600);//Initialize each IO, mode output mode Pinmode (Input1,output); Pinmode (input2,output);p Inmode (input3,output);p Inmode (input4,output);} void Loop () { //forward forward digitalwrite (Input1,high);//Give High Level digitalwrite (input2,low); Give low Level digitalwrite (Input3,high);//Give High Level digitalwrite (input4,low); Give low -level delay (+) ; Delay 1 seconds//stop stop digitalwrite (Input1,low); Digitalwrite (input2,low); Digitalwrite (Input3,low); Digitalwrite (input4,low); Delay (+); Delay 0.5 seconds //back backward turn digitalwrite (input1,low); Digitalwrite (Input2,high); Digitalwrite (input3,low); Digitalwrite (Input4,high); Delay (+); }
Drive DC motor using Arduino and l298n (red Board)