loading

Here is part 2 of the Arduino controlled L293D Robot.

Part 2 includes Infrared Sensors.This is part of a series of instructables leading to a Line follower Robot.

QRD1114 Infrared Sensor connected to Arduino

Step 1: Wiring the Infrared Sensor to the Arduino

Negative from the IR Sensor connects to Negative on the Breadboard.

Middle Pin ( Positive ) from the IR Sensor connects to Positive on the Breadboard.

Last Pin ( Input ) from the IR Sensor connects to Analog input on Arduino Board.

In this case I had the Input from the IR Sensor connecting to Pin 3 on the Analog Input on the Arduino.

Step 2: Basic Code to Read the IR Sensor

int analogPin = 3;     // Infrared Sensor (Right lead) connected to analog pin 3
                                    // outside leads to ground and +5V
int val = 0;                  // variable to store the value read

void setup()
{
  Serial.begin(9600);          //  setup serial
}

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

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 ground
                               
int 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 <100)

// If the read value is < 100 then run the code below which will turn  both Left and Right Motor on making the Robot go straight.

  {
   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
  }
 
}

Step 4: IR Value Is Greater Than 100

When IR Value is greater than 100 then the Motors are off.

Step 5: IR Value Is Less Than 100

When IR Value is Less than 100 then the Motors are turned on and the Robot drives forward for 10 seconds.
<p>Is it not necessary to setup the ir mode in void setup() ???</p>
<p>what are the changes to be done in the given code when we use 2 sensors instead of one?</p>
<p>does it move in all 4 directions including backwards</p>
<p>Hey man! The IR sensor that i have shows either 0 or 713. Is my sensor digital? How do i get analog outputs?</p><p>Thanks in advance!</p>
And one thing more the motors are working in part 1 of your tutorial but not in second one...
And one thing more the motors are working in part 1 of your tutorial but not in second one...
Hi, my sensors and motors are not working with the code...<br>Pls help me, reply as soon as possible.....<br>And if possible then pls send me the connections and the code.<br>Satvik.agg@gmail.com
<p>hi I am doing project using two dc motors with l293d and two infrared sensors and I also want to use ultra sonic sensor to detect the obstacles can you send me code and wiring diagram for this or it is same as you show in your web page. I shall be thankful to you. Pls send me I have to display it in my school.</p><p>satvik.agg@gmail.com</p>
<p>hello, I am shridar,if yu have the coding for the Line follower pls send it to shridar1719@gmail.com</p>
<p>Its the exact same just with the addition of the ultra sensor. <br>For the ultrasonic sensor you can use the Arduino example and modify the code for at what distance you want it to stop turn etc.</p>
<p>Hiiiiiiiiiii, whenever I try to connect my motor all the pins are high by default,even I have written the code right as LOW for some pin ,then also all the 4 pins to my motor inputs are high...and my motors are unable to move....can anyone help me with this?</p>
<p>hi I have done part one of this project and my motors working perfectly can you please tell me which infra red sensor you use and this is full code for part1 project. I buy infra red sensor fc 51 which are I think distance measure for obstacle detection so please guide me sooner this is my final year project</p>
<p>I am really really sorry i wasnt able to answer your question earlier.<br>I have been really busy with school and life and i hope i am not too late.<br><br>Here is the post where i build the IR Sensor:</p><p><a href="https://www.instructables.com/id/Building-an-Infrared-Sensor/" rel="nofollow">https://www.instructables.com/id/Building-an-Infrar...</a></p><p>You can buy the Sensor i used <a href="https://www.sparkfun.com/products/246" rel="nofollow">https://www.sparkfun.com/products/246</a></p><p>and make your own or you could buy pre made IR Sensor such as this one: <a href="http://www.adafruit.com/product/157" rel="nofollow">http://www.adafruit.com/product/157</a></p>
<p>hi I am doing project using two dc motors with l293d and two infrared sensors and I also want to use ultra sonic sensor to detect the obstacles can you send me code and wiring diagram for this or it is same as you show in your web page. I shall be thankful to you. I am so distress it is my final year project and I am new to understand if you help me I shall be thankful to you.</p>
<p>can u please upload the schematic for the ir line sensor circuit ,, and i need a way to compare between the ir transmitter and reseiver leds because they look similar to each others and they all emits lights when i see them with my camera </p>
<p>you should look at his instructable on &quot;</p><p>Building an Infrared Sensor&quot; it has the schematic diagram. as for the leds you should look look at the part . the pin outs are normally printed on it.</p>
Very well done, must give this a go
Thanks. <br>Once i get some free time from School i will try to update this project and take it to the next Level.

About This Instructable

71,980views

28favorites

License:

More by NIkheel94:Streaming the Xbox 360 to Twitch using an older VGA/DVI PC Monitor with Seperate Sound (Monitor Without Speakers) Easy Basic Arduino Ethernet Controller Most Basic Form of Hydroponics 
Add instructable to: