Basic Arduino Robot Car Kit + Motor driver L298N H-Bridge module
//Arduino code:\r
\r
int L1 = 6, L2 = 7, L3 = 8, L4 = 9; // Pins connected to Motor driver L298N H-Bridge module\r
\r
void setup()\r
{ // initialize the digital pins we will use as an output.\r
pinMode(L1, OUTPUT); pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT);\r
Serial.begin(9600);\r
}\r
\r
// the loop routine runs over and over again forever:\r
void loop()\r
{\r
forward(500);\r
halt(2000);\r
reverse(500);\r
halt(2000);\r
rightSpin(500);\r
halt(2000);\r
leftSpin(500);\r
halt(2000);\r
}\r
\r
// robMove routine switches the correct inputs to the L298N for the direction selected.\r
void robMove(int l1, int l2, int r1, int r2)\r
{\r
digitalWrite(L1, l1);\r
digitalWrite(L2, l2);\r
digitalWrite(L3, r1);\r
digitalWrite(L4, r2); \r
}\r
\r
void reverse(int wait)\r
{\r
Serial.println(Moving backward);\r
robMove(LOW, HIGH, LOW, HIGH);\r
delay(wait);\r
}\r
\r
void forward(int wait)\r
{\r
Serial.println(Moving forward);\r
robMove(HIGH, LOW, HIGH, LOW);\r
delay(wait);\r
}\r
\r
void leftSpin(int wait)\r
{\r
Serial.println(Spinning left);\r
robMove(HIGH, LOW, LOW, HIGH);\r
delay(wait);\r
}\r
\r
void rightSpin(int wait)\r
{\r
Serial.println(Spinning right);\r
robMove(LOW, HIGH, HIGH, LOW);\r
delay(wait);\r
}\r
\r
void halt(int wait)\r
{\r
Serial.println(Stopping);\r
robMove(LOW, LOW, LOW, LOW);\r
delay(wait);\r
}
\r
int L1 = 6, L2 = 7, L3 = 8, L4 = 9; // Pins connected to Motor driver L298N H-Bridge module\r
\r
void setup()\r
{ // initialize the digital pins we will use as an output.\r
pinMode(L1, OUTPUT); pinMode(L2, OUTPUT); pinMode(L3, OUTPUT); pinMode(L4, OUTPUT);\r
Serial.begin(9600);\r
}\r
\r
// the loop routine runs over and over again forever:\r
void loop()\r
{\r
forward(500);\r
halt(2000);\r
reverse(500);\r
halt(2000);\r
rightSpin(500);\r
halt(2000);\r
leftSpin(500);\r
halt(2000);\r
}\r
\r
// robMove routine switches the correct inputs to the L298N for the direction selected.\r
void robMove(int l1, int l2, int r1, int r2)\r
{\r
digitalWrite(L1, l1);\r
digitalWrite(L2, l2);\r
digitalWrite(L3, r1);\r
digitalWrite(L4, r2); \r
}\r
\r
void reverse(int wait)\r
{\r
Serial.println(Moving backward);\r
robMove(LOW, HIGH, LOW, HIGH);\r
delay(wait);\r
}\r
\r
void forward(int wait)\r
{\r
Serial.println(Moving forward);\r
robMove(HIGH, LOW, HIGH, LOW);\r
delay(wait);\r
}\r
\r
void leftSpin(int wait)\r
{\r
Serial.println(Spinning left);\r
robMove(HIGH, LOW, LOW, HIGH);\r
delay(wait);\r
}\r
\r
void rightSpin(int wait)\r
{\r
Serial.println(Spinning right);\r
robMove(LOW, HIGH, HIGH, LOW);\r
delay(wait);\r
}\r
\r
void halt(int wait)\r
{\r
Serial.println(Stopping);\r
robMove(LOW, LOW, LOW, LOW);\r
delay(wait);\r
}