robot

16

Upload: will

Post on 18-Nov-2015

215 views

Category:

Documents


0 download

DESCRIPTION

disclaimer:do not own anything

TRANSCRIPT

Step 3: Code to Drive Forward when IR Sensor Value is Less than 100// This is the basic code which runs a loop that makes the Robot go straight forward when the Infrared value is below 100.

int analogPin = 3; // Infrared Sensor (Right lead) connected to analog pin 3 // Infrared Sensor(middle Lead) connected to +5V // Infrared Sensor(Left Lead) connected to groundint val = 0; // variable to store the value read

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. Serial.begin(9600); // setup serial}

// The following Loop is to make the Robot go staright when the Infrared value is below 100

void loop()

{ val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value if (val