In this article, Poly Notes Hub shares knowledge on how to interfacing dc motor with Arduino UNO. In this article, we will know about the circuit diagram, working principle, and the Code also.
Author Name: Arun Paul.
How to interfacing DC Motor With Arduino UNO ?
Required Components
- Arduino UNO
- Motor Driver IC L293D
- Two Motor
- Power Supply
Circuit Diagram
- Arduino D12, D11, D10, and D9 connected to the L293D’s PIN 2, PIN 7, PIN 10, and PIN 15 respectively.
- +5V and +12V supply provided to the IC’s PIN 16 and PIN 8.
- Motor 1 is connected to the PIN 3 and PIN 6 of the IC.
- Motor 2 is connected to the PIN 11 and PIN 14 of the IC.
- IC’s all ground pin should be connected to the negative terminal of the power supply.
Arduino Code
Upload this code to the Arduino
void setup() {
pinMode(12, OUTPUT); // l293d pin2 connected with D12 of Arduino
pinMode(11, OUTPUT); // l293d pin7 connected with D11 of Arduino
pinMode(10, OUTPUT); // l293d pin10 connected with D10 of Arduino
pinMode(9, OUTPUT); // l293d pin15 connected with D9 of Arduino
}
void loop() {
digitalWrite(12, HIGH); // For Motor 1 and Motor 2 Clockwise Direction
digitalWrite(11, LOW);
digitalWrite(10, HIGH);
digitalWrite(9, LOW);
delay(3000); // Rotating Clockwise for 3 sec
digitalWrite(12, LOW); // For Motor 1 and Motor 2 Break
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(2000); // Stop for 2 Sec
digitalWrite(12, LOW); // For Motor 1 and Motor 2 Anti-Clockwise Direction
digitalWrite(11, HIGH);
digitalWrite(10, LOW);
digitalWrite(9, HIGH);
delay(3000); // Rotating Clockwise for 3 sec
digitalWrite(12, LOW); // For Motor 1 and Motor 2 Break
digitalWrite(11, LOW);
digitalWrite(10, LOW);
digitalWrite(9, LOW);
delay(2000); // Stop for 2 Sec
}