• Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors
HomepcDuinoArduino-ish ProgramPWMRun Motor Shield on pcDuino
Previous Next

Run Motor Shield on pcDuino

Posted by: Alvin Jin , March 27, 2014

[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

5

2. 2 x  DC motor with tires

6

3. 1 x 6V-15V battery

blue

4.  If pcDuino1 is used,  please add one T-Board for pcDuino1. We don’t need T-board if pcDuino2 is used.

white[/vc_column_text][/vc_tab][vc_tab title=”Wiring Instructions” tab_id=”1395910208-2-40″][vc_column_text]Wiring diagram:

1. Power section:

11

2. Motor connection:

12

3. pcDuino1 case:

13

4. pcDuino2 case:

14[/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:

test code[/vc_column_text][/vc_tab][/vc_tour][/vc_column][/vc_row]

Tags: PWM

Share!
Tweet

Alvin Jin

About the author

Leave a Reply Cancel reply

You must be logged in to post a comment.

Category

  • Home
  • pcDuino
  • WiKi
  • Store
  • Distributors