L293D is an IC, which is used to control 2 wheel and 4 wheel robots. It has 16 pins. L293D divides power into two parts, which can be controlled according to the input pins. The following code makes the robot move forward, backward, left, right. Connect the robot as shown in the figure below.

Code:

const int motorPin1  = 1;
const int motorPin2  = 2;  
const int motorPin3  = 3;
const int motorPin4  = 4;
void setup(){
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
}


void loop(){

digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, HIGH);
digitalWrite(motorPin4, LOW);
delay(2000);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
digitalWrite(motorPin1, LOW);
digitalWrite(motorPin2, HIGH);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
digitalWrite(motorPin1, HIGH);
digitalWrite(motorPin2, LOW);
digitalWrite(motorPin3, LOW);
digitalWrite(motorPin4, LOW);
delay(2000);
}

Code explaination:

Here, we take 4 inputs from pin 1,2,3,4; as motorpin1, motorpin2, motorpin3, motorpin4, and declare them as outputs. This all should be written in void setup. Then, we set outputs to HIGH and LOW according to the code above, to make the robot move forward, backward, right and -left. The L293D pins must be connected as shown below.

The Robot will look as follows:

Categories: ArduinoTutorials

0 Comments

Leave a Reply