[vc_row][vc_column width=”1/1″][vc_column_text]The Motor Shield is a perfect platform for robotics and mechanical applications. It enables the Arduino/pcDuino to drive two brushed DC motors or one 4-wire two-phase stepper motor. So with this motor shield, we can build up our own pcDuino-powered intelligent vehicle or other robots.
Product page of this motor shield please check out here.[/vc_column_text][vc_tour][vc_tab title=”Parts List” tab_id=”1388037519-1-85″][vc_column_text]Motor shield x1
Mini DC motor x 2
6-15V power supply x1 (it can be battery also)
pcDuino V2 x1[/vc_column_text][/vc_tab][vc_tab title=”Wire Diagram” tab_id=”1388037519-2-6″][vc_column_text](1)Power supply:
(2)Output funcations:
(2)All assembled is as following:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1388038235257-2-3″][vc_column_text]Please compile and upload the following code in Arduino IDE:
#include <core.h>
#define pinI1 8 //define IN1 interface
#define pinI2 11 //define IN2 interface
#define speedpinA 9 //enable motor A
#define pinI3 12 //define IN3 interface
#define pinI4 13 //define IN4 interface
#define speedpinB 10 //enable motor B
#define spead 200 //define the spead of motor
void forward()
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,LOW);//turn DC Motor A move anticlockwise
digitalWrite(pinI1,HIGH);
}
void backward()
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void left()
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,HIGH);//turn DC Motor B move clockwise
digitalWrite(pinI3,LOW);
digitalWrite(pinI2,HIGH);//turn DC Motor A move clockwise
digitalWrite(pinI1,LOW);
}
void right()
{
analogWrite(speedpinA,spead);//input a simulation value to set the speed
analogWrite(speedpinB,spead);
digitalWrite(pinI4,LOW);//turn DC Motor B move anticlockwise
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,LOW);//turn DC Motor A move clockwise
digitalWrite(pinI1,HIGH);
}
void stop()
{
digitalWrite(speedpinA,LOW);
//Unenble the pin, to stop the motor. This should be done to avid damaging the motor.
digitalWrite(speedpinB,LOW);
delay(2000);
}
void setup()
{
pinMode(pinI1,OUTPUT);
pinMode(pinI2,OUTPUT);
pinMode(speedpinA,OUTPUT);
pinMode(pinI3,OUTPUT);
pinMode(pinI4,OUTPUT);
pinMode(speedpinB,OUTPUT);
}
void loop()
{
left();
delay(2000);
stop();
right();
delay(2000);
stop();
forward();
delay(2000);
stop();
backward();
delay(2000);
stop();
}
[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]
Leave a Reply
You must be logged in to post a comment.