Hướng Dẫn Sử Dụng Arduino Đảo Chiều Động Cơ Một Chiều DC

Giới thiệu chung

Trong điều khiển robot thì vấn đề điều khiển động cơ quay thuận, quay ngược là việc rất phổ biến và quan trọng. Để có thể điều khiển được hoạt động của động cơ một chiều ta có thể sử dung một thiết bị tiện dụng gọi là mạch cầu H.

Sơ đồ mạch cầu H
Mạch cầu H có 4 trạng thái hoạt động chính:
- Trạng thái Open: tất cả các công tắc đều mở, động cơ không quay.
- Trạng thái Forward: hai công tắc đối diện chéo nhau đóng lại tạo ra dòng điện 9V chạy qua động cơ, khiến động cơ quay.
- Trạng thái Backward: Các công tắc đối lập được lật ngược lại, dòng điện chạy qua động cơ bị đảo chiều, động cơ quay theo chiều ngược lại.
- Trạng thái Braking: động cơ dừng lại.

SN754410 Quadruple Half-H driver

SN754410
- GND (Pins 4, 5, 12, & 13): The four pins in the middle connect to a shared ground between your 9V and 5V supplies.
- VCC2 (Pin 8): VCC2 supplies the motor current, so you connect it to 9V.
- VCC1 (Pin 16): VCC1 powers the chip’s logic, so you connect it to 5V.
- 1Y and 2Y (Pins 3 and 6): These are the outputs from the left driver. The motor wires connect to these pins.
- 1A and 2A (Pins 2 and 7): The states of the switches on the left are controlled by these pins, so they are connected to I/O pins on the Arduino for toggling.
- 1,2EN (Pin 1): This pin is used to enable or disable the left driver. It is connected to a PWM pin on the Arduino, so that speed can be controlled dynamically.
- 3Y and 4Y (Pins 11 and 14): These are the outputs from the right driver. Because you are using the left driver only, you can leave these disconnected.
- 3A and 4A (Pins 10 and 15): The states of the switches on the right are controlled by these pins, but you are using only the left driver in this example, so you can leave them disconnected.
- 3,4EN (Pin 9): This pin is used to enable or disable the right driver. Because you will not be using the right driver, you can disable it by connecting this pin directly to GND. 

Thiết bị cần chuẩn bị.

- Arduino Uno
- DC motor
- Chiết áp
- Board Test
- SN754410 Quadruple Half-H driver
- Pin 9V

Sơ đồ đấu dây


Sơ đồ đấu dây


Hướng dẫn lập trình

//Hbridge Motor Control
const int EN = 9; //Half Bridge 1 Enable
const int MC1 = 3; //Motor Control 1
const int MC2 = 2; //Motor Control 2
const int POT = 0; //POT on Analog Pin 0
int val = 0; //for storing the reading from the POT
int velocity = 0; //For storing the desired velocity (from 0-255)
void setup()
{ pinMode(EN, OUTPUT);
pinMode(MC1, OUTPUT);
pinMode(MC2, OUTPUT);
brake(); //Initialize with motor stopped}
void loop()
{
val = analogRead(POT);
//go forward
if (val > 562)
{ velocity = map(val, 563, 1023, 0, 255);
forward(velocity);
}
//go backward
else if (val < 462)
{ velocity = map(val, 461, 0, 0, 255);
reverse(velocity);
}
//brake
else
{ brake();
}
}
//Motor goes forward at given rate (from 0-255) void forward(int rate)
{
digitalWrite(EN, LOW);
digitalWrite(MC1, HIGH);
digitalWrite(MC2, LOW);
analogWrite(EN, rate);
}
//Motor goes backward at given rate (from 0-255) void reverse(int rate)
{
digitalWrite(EN, LOW);
digitalWrite(MC1, LOW);
digitalWrite(MC2, HIGH);
analogWrite(EN, rate);
}
//Stops motor void brake()
{
digitalWrite(EN, LOW);
digitalWrite(MC1, LOW);
digitalWrite(MC2, LOW);
digitalWrite(EN, HIGH);
}
Linh kiện điện tử 3M chúc các bạn thành công.

Hướng Dẫn Sử Dụng Arduino Đảo Chiều Động Cơ Một Chiều DC Hướng Dẫn Sử Dụng Arduino Đảo Chiều Động Cơ Một Chiều DC Reviewed by Linh Kiện Điện Tử 3M on tháng 9 04, 2019 Rating: 5

Không có nhận xét nào: