0% found this document useful (0 votes)
13 views1 page

CO Pilot Code

This document is an Arduino sketch for controlling two DC motors using the Adafruit Motor Shield library. It sets up serial communication to receive commands for moving the motors forward, backward, left, right, or stopping them. The motor speed is set to 200, and commands are processed in a loop to control motor movement accordingly.

Uploaded by

Mamtha K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views1 page

CO Pilot Code

This document is an Arduino sketch for controlling two DC motors using the Adafruit Motor Shield library. It sets up serial communication to receive commands for moving the motors forward, backward, left, right, or stopping them. The motor speed is set to 200, and commands are processed in a loop to control motor movement accordingly.

Uploaded by

Mamtha K
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include <AFMotor.

h> // Include Adafruit Motor Shield library

AF_DCMotor motor1(1); // Connect motor 1 to port 1 on the motor shield


AF_DCMotor motor2(2); // Connect motor 2 to port 2 on the motor shield

char command; // Variable to store the received command

void setup() {
Serial.begin(9600); // Set the data rate for the serial communication
motor1.setSpeed(200); // Set motor speed (0-255)
motor2.setSpeed(200);
}

void loop() {
if (Serial.available() > 0) {
command = Serial.read(); // Read the incoming command

// Control motors based on the command received


if (command == 'F') { // Forward
motor1.run(FORWARD);
motor2.run(FORWARD);
}
else if (command == 'B') { // Backward
motor1.run(BACKWARD);
motor2.run(BACKWARD);
}
else if (command == 'L') { // Left
motor1.run(BACKWARD);
motor2.run(FORWARD);
}
else if (command == 'R') { // Right
motor1.run(FORWARD);
motor2.run(BACKWARD);
}
else if (command == 'S') { // Stop
motor1.run(RELEASE);
motor2.run(RELEASE);
}
}
}

You might also like