สอบถาม 4WD drive smart car (รหัสสินค้า A251) ใช้กับ Motor Drive Module (L298N) (รหัสสินค้า A124) ดังนี้
1.สามารถต่อ DC มอเตอร์ 4WD drive smart car กับ Motor Drive Module (L298N) ได้หรือไม่
2.ถ้าใช้ได้ผมขอวงจรและ code การต่อกับ arduino uno
3.สามารถควบคุมความเร็วมอเตอร์ได้หรือไม่ครับ
ขอตอบเป็นข้อนะครับ
สอบถาม 4WD drive smart car (รหัสสินค้า A251) ใช้กับ Motor Drive Module (L298N) (รหัสสินค้า A124) ดังนี้
1.สามารถต่อ DC มอเตอร์ 4WD drive smart car กับ Motor Drive Module (L298N) ได้หรือไม่
- ตามสเปคมอเตอร์ 4WD Drive Smart Car เป็นมอเตอร์ 5 โวลต์ ใช้กระแสที่ 80-100mA ส่วนโมดูล Mortor Drive Module (L298N) ใช้ขับมอเตอร์ได้ 2 ตัว ใช้ไฟ 5 โวลต์ มีเรกูเลเตอร์ 5 โวลต์สามารถใส่ไฟ 12 โวลต์เข้ามาได้ รองรับโหลดกระแสสูงสุดที่ 2A ดังนั้นขับรถ 4WD Drive Smart Car ได้สบาย ๆ ครับ คลิปนี้ใช้ L298N ขับมอเตอร์ 2 ตัวแบบไม่ต้องติดแผ่นระบายความร้อน
2.ถ้าใช้ได้ผมขอวงจรและ code การต่อกับ arduino uno
- วงจรพร้อม DataSheet มีในหน้าสินค้า หรือคลิกที่ลิงค์นี้ก็ได้ครับ
- คลิปนี้เป็นตัวอย่างสอนการใช้งานครับ
ตัวอย่างโคดมีในเว็บ youtube อันข้างบนให้ดาวน์โหลด หรือดาวน์โหลดจากตรงนี้ครับ
/* L298N_Dual_H_Bridge
This program controls 2 separate DC motors using the L298N
H Bridge Chip.
*THE SUBROUTINES WORK AS FOLLOWS*
motorA(mode, speed)
% replace A with B to control motor B %
mode is a number 0 -> 3 that determines what the motor
will do.
0 = coast/disable the H bridge
1 = turn motor clockwise
2 = turn motor counter clockwise
3 = brake motor
speed is a number 0 -> 100 that represents percentage of
motor speed.
0 = off
50 = 50% of full motor speed
100 = 100% of full motor speed
EXAMPLE
Say you need to have motor A turn clockwise at 33% of its
full speed. The subroutine call would be the following...
motorA(1, 33);
Created by
Iain Portalupi https://www.youtube.com/iainportalupi
1/2/2014
This code is in the public domain.
*/
#define ENA 5 //enable A on pin 5 (needs to be a pwm pin)
#define ENB 3 //enable B on pin 3 (needs to be a pwm pin)
#define IN1 2 //IN1 on pin 2 conrtols one side of bridge A
#define IN2 4 //IN2 on pin 4 controls other side of A
#define IN3 6 //IN3 on pin 6 conrtols one side of bridge B
#define IN4 7 //IN4 on pin 7 controls other side of B
void setup()
{
//set all of the outputs
pinMode(ENA, OUTPUT);
pinMode(ENB, OUTPUT);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop()
{
motorA(1, 15); //have motor A turn clockwise at 15% speed
delay(5000); //let motor A run for 5 seconds
motorA(3, 100); //brake motor A with 100% braking power
motorB(1, 15); //have motor B turn clockwise at 15% speed
delay(5000); //let motor B run for 5 seconds
//have motor A turn counter-clockwise at 15% speed
motorA(2, 15);
delay(5000); //let motor A and motor B run for 5 seconds
motorB(3, 50); //brake motor B with 50% braking power
motorA(0, 100); //let motor A coast
delay(5000); //wait 5 seconds
}
//****************** Motor A control *******************
void motorA(int mode, int percent)
{
//change the percentage range of 0 -> 100 into the PWM
//range of 0 -> 255 using the map function
int duty = map(percent, 0, 100, 0, 255);
switch(mode)
{
case 0: //disable/coast
digitalWrite(ENA, LOW); //set enable low to disable A
break;
case 1: //turn clockwise
//setting IN1 high connects motor lead 1 to +voltage
digitalWrite(IN1, HIGH);
//setting IN2 low connects motor lead 2 to ground
digitalWrite(IN2, LOW);
//use pwm to control motor speed through enable pin
analogWrite(ENA, duty);
break;
case 2: //turn counter-clockwise
//setting IN1 low connects motor lead 1 to ground
digitalWrite(IN1, LOW);
//setting IN2 high connects motor lead 2 to +voltage
digitalWrite(IN2, HIGH);
//use pwm to control motor speed through enable pin
analogWrite(ENA, duty);
break;
case 3: //brake motor
//setting IN1 low connects motor lead 1 to ground
digitalWrite(IN1, LOW);
//setting IN2 high connects motor lead 2 to ground
digitalWrite(IN2, LOW);
//use pwm to control motor braking power
//through enable pin
analogWrite(ENA, duty);
break;
}
}
//**********************************************************
//****************** Motor B control *******************
void motorB(int mode, int percent)
{
//change the percentage range of 0 -> 100 into the PWM
//range of 0 -> 255 using the map function
int duty = map(percent, 0, 100, 0, 255);
switch(mode)
{
case 0: //disable/coast
digitalWrite(ENB, LOW); //set enable low to disable B
break;
case 1: //turn clockwise
//setting IN3 high connects motor lead 1 to +voltage
digitalWrite(IN3, HIGH);
//setting IN4 low connects motor lead 2 to ground
digitalWrite(IN4, LOW);
//use pwm to control motor speed through enable pin
analogWrite(ENB, duty);
break;
case 2: //turn counter-clockwise
//setting IN3 low connects motor lead 1 to ground
digitalWrite(IN3, LOW);
//setting IN4 high connects motor lead 2 to +voltage
digitalWrite(IN4, HIGH);
//use pwm to control motor speed through enable pin
analogWrite(ENB, duty);
break;
case 3: //brake motor
//setting IN3 low connects motor lead 1 to ground
digitalWrite(IN3, LOW);
//setting IN4 high connects motor lead 2 to ground
digitalWrite(IN4, LOW);
//use pwm to control motor braking power
//through enable pin
analogWrite(ENB, duty);
break;
}
}
//**********************************************************
3.สามารถควบคุมความเร็วมอเตอร์ได้หรือไม่ครับ
- รองรับ PWM สามารถควบคุมความเร็วได้ครับ
จากตัวอย่างโคด
สามารถปรับความเร็วได้ 0-100 โดยปรับเป็น % ของความเร็วมอเตอร์
0 = ปิด
50 = 50 % ของความเร็วเต็มที่
100 = 100% ของความเร็วเต็มที่
ตัวอย่างถ้าต้องการปรับที่ความเร็ว 33% ก็เซตค่าตามโคดนี้
motorA(1, 33);
ติดปัญหาตรงไหนสอบถามเพิ่มเติมได้ครับ มีคำแนะนำหรือข้อมูลขาดตกบกพร่อง แนะนำด้วยนะครับ
ใช้ต่อกับปั๊ม3A ตัวเดียวได้ไหมคับ
4WD Drive Smart Car เป็นมอเตอร์ 5 โวลต์ ใช้กระแสที่ 80-100mA 4 ล้อก็ใช้ไฟประมาณ 400mA ตัวไดรเวอร์ 3A ขับได้ครับ
อะไรคือ ปั๊ม3A เหรอครับ
อยากทราบว่าบอร์ดนี้สามารถใช่ร่วมกับบอร์ดคอนโทรลเลอร์ที่ใช้ไอซี mcs 51 ได้ไหมค่ะ และต้องมีโค้ดหรือมีโปรแกรมใช้คู่ไหมค่ะ
ใช้ได้ เพราะส่งสัญญาณเป็นความถี่ PWM ควบคุมความเร็วครับ
ตัวอย่างโคดลองดูตามนี่ครับ http://www.shadowwares.com/forum/index.php?PHPSESSID=oj5t88fvl6f455gp31ns3jc260&topic=869.0
รบกวนถามหน่อยครับ
คือ ผมต่อไฟเลี้ยงบอร์ดนี้ 9.6V อ่ะครับ และผมต้องการให้ output อออก 9.6 V เหมือนกัน แต่มันออกแค่ 3.8V
ถ้าอยากจะเพิ่มผมต้องจ่าย v เพิ่มหรือเปล่าครับ
ลองดูตัวอย่างในลิงค์นี้ครับ
http://www.instructables.com/id/Arduino-Modules-L298N-Dual-H-Bridge-Motor-Controll/?ALLSTEPS