[vc_row][vc_column][vc_column_text]Motor Shield makes it easy to control two brushed DC motors with your Arduino-compatible board. It is also compatible with pcDuino. With the motor shield, we can use pcDuino to build robot.[/vc_column_text][/vc_column][/vc_row][vc_row][vc_column width=”1/1″][vc_tour][vc_tab title=”Parts List” tab_id=”1395910208-1-86″][vc_column_text]1. 1 x Motor Shield
2. 2 x DC motor with tires
3. 1 x 6V-15V battery
4. If pcDuino1 is used, please add one T-Board for pcDuino1. We don’t need T-board if pcDuino2 is used.
[/vc_column_text][/vc_tab][vc_tab title=”Wiring Instructions” tab_id=”1395910208-2-40″][vc_column_text]Wiring diagram:
1. Power section:
2. Motor connection:
3. pcDuino1 case:
4. pcDuino2 case:
[/vc_column_text][/vc_tab][vc_tab title=”Sample Code” tab_id=”1395913642033-2-2″][vc_column_text]
#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_tab title=”Compile and run in Aduino IDE for pcDuino” tab_id=”1395913643906-3-7″][vc_column_text]Open arduino IDE for pcDuino, compile and run the test code:

Leave a Reply
You must be logged in to post a comment.