製作主要材料:
1. L293D motor driver IC x1
2. 74HC00 NAND logic gate IC x1
3. ATmega328 (arduino 相容線路) IC x 1
4. 幾顆電容,電阻及接頭等,
5.電池 1.5V x 4 (提供馬達電源)
6. 電池 9V x 1 (提供 IC 電源)
Arduino Sketch如下: (前進一秒--->停一秒--->後退一秒--->停一秒--->右轉一秒 ---> 停一秒 ----> 左轉一秒 ---> 停一秒)
const int Motor_M1 = 7; // Pin ? of L298N
const int Motor_M2 = 4; // Pin ? of L298N
const int Motor_E1 = 6; // Pin ? of L298N
const int Motor_E2 = 5; // Pin ? of L298N
void setup()
{
Serial.begin(57600);
// set all color leds as output pins
pinMode(Motor_M1, OUTPUT);
pinMode(Motor_M2, OUTPUT);
}
void loop()
{
forward(0,0);
delay(1000);
motorstop(0,0);
delay(1000);
back(0,0);
delay(1000);
motorstop(0,0);
delay(1000);
right(0,0);
delay(1000);
motorstop(0,0);
delay(1000);
left(0,0);
delay(1000);
motorstop(0,0);
delay(1000);
}
void motorstop(byte flag, byte numOfValues)
{
digitalWrite( Motor_E1, 0);
digitalWrite( Motor_E2, 0);
Serial.println("stop : ");
}
void forward(byte flag, byte numOfValues)
{
Serial.println("forward : ");
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, HIGH);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 255);
}
void back(byte flag, byte numOfValues)
{
Serial.println("back : ");
digitalWrite( Motor_M1, LOW);
digitalWrite( Motor_M2, LOW);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 255);
}
void right(byte flag, byte numOfValues)
{
Serial.println("right : ");
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, HIGH);
analogWrite( Motor_E1, 255);
analogWrite( Motor_E2, 0);
}
void left(byte flag, byte numOfValues)
{
Serial.println("left : ");
digitalWrite( Motor_M1, HIGH);
digitalWrite( Motor_M2, HIGH);
analogWrite( Motor_E1, 0);
analogWrite( Motor_E2, 255);
}
圗中最底層放入電池,第二層是馬達驅動IC L293D 板子,最上層是Arduino相容板.
有問題或有興趣的朋友可以mail me : sinocgtchen@gmail.com
我的 Youtube: http://www.youtube.com/user/sinocgtchen
沒有留言:
張貼留言