Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
2K views

Sumobot Code

The document provides Arduino code to control the movement of a robot. It defines pins for connecting motors to the Arduino board. Functions are used to make the robot go forward, reverse, left, and right by controlling the direction and speed of each motor. The loop calls each function in sequence to demonstrate controlling the robot's movement.

Uploaded by

abubakar_13
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views

Sumobot Code

The document provides Arduino code to control the movement of a robot. It defines pins for connecting motors to the Arduino board. Functions are used to make the robot go forward, reverse, left, and right by controlling the direction and speed of each motor. The loop calls each function in sequence to demonstrate controlling the robot's movement.

Uploaded by

abubakar_13
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Step 8: Basic Code to go Right

int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards.
int LeftMotorReverse = 9; // Pin 9 has Left Motor connected on Arduino boards.

int RightMotorForward = 12; // Pin 12 has Right Motor connected on Arduino
boards.
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino
boards.


void setup()
{
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
}

// The following Loop is to make the Robot go Right
void loop()

{
digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
}

Step 9: Basic Code to go Left
int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards.
int LeftMotorReverse = 9; // Pin 9 has Left Motor connected on Arduino boards.

int RightMotorForward = 12; // Pin 12 has Right Motor connected on Arduino
boards.
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino
boards.


void setup()
{
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
}

// The following Loop is to make the Robot go Left
void loop()

{
digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
}

Step 10: Basic Code to Reverse
int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards.
int LeftMotorReverse = 9; // Pin 9 has Left Motor connected on Arduino boards.

int RightMotorForward = 12; // Pin 12 has Right Motor connected on Arduino
boards.
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino
boards.


void setup()
{
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
}

// The following Loop is to make the Robot Reverse
void loop()

{
digitalWrite(RightMotorReverse, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, HIGH); // turn the Left Motor ON
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
}


Step 11: Code to make Robot go
Forward,Right,Left,Reverse and Stop all in a Loop
int LeftMotorForward = 10; // Pin 10 has Left Motor connected on Arduino boards.
int LeftMotorReverse = 9; // Pin 9 has Left Motor connected on Arduino boards.

int RightMotorForward = 12; // Pin 12 has Right Motor connected on Arduino
boards.
int RightMotorReverse = 13; // Pin 13 has Right Motor connected on Arduino
boards.

//-----------------------------------------------------------------------------
void setup()
{
pinMode(LeftMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorForward, OUTPUT); // initialize the pin as an output.
pinMode(LeftMotorReverse, OUTPUT); // initialize the pin as an output.
pinMode(RightMotorReverse, OUTPUT); // initialize the pin as an output.
}
//-----------------------------------------------------------------------------

// The following Loop is to make the Robot go staright
void loop()
{
void Driveforward();

digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
//-----------------------------------------------------------------------------
void Rightturn();

digitalWrite(RightMotorForward, LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, HIGH); // turn the Left Motor ON
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
//-----------------------------------------------------------------------------
void Leftturn();

digitalWrite(RightMotorForward, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
//-----------------------------------------------------------------------------
void Reverse();

digitalWrite(RightMotorReverse, HIGH); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, HIGH); // turn the Left Motor ON
delay(10000); // wait for a 10 seconds

digitalWrite(RightMotorReverse, LOW); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor ON
delay(10000); // wait for a 10 seconds
//-----------------------------------------------------------------------------

void Allstop();

digitalWrite(RightMotorReverse, LOW); // turn the Right Motor ON
digitalWrite(LeftMotorReverse, LOW); // turn the Left Motor ON
delay(10000); // wait for 10 seconds

digitalWrite(RightMotorForward,LOW); // turn the Right Motor OFF
digitalWrite(LeftMotorForward, LOW); // turn the Left Motor OFF
delay(10000); // wait for 10 seconds
//-----------------------------------------------------------------------------
}

You might also like