Infrared Sensor Guided Arduino Controlled L293D Robot ( Part 2 )

76,782

28

19

Intro: Infrared Sensor Guided Arduino Controlled L293D Robot ( Part 2 )

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.

Share

    Recommendations

    • Electronics Tips & Tricks Challenge

      Electronics Tips & Tricks Challenge
    • Plastics Contest

      Plastics Contest
    • Optics Contest

      Optics Contest

    19 Discussions

    0
    None
    Hritik0106

    2 years ago

    Is it not necessary to setup the ir mode in void setup() ???

    0
    None
    PrakharB1

    2 years ago

    what are the changes to be done in the given code when we use 2 sensors instead of one?

    0
    None
    shivamt7

    2 years ago

    does it move in all 4 directions including backwards

    0
    None
    anubhavg6

    2 years ago

    Hey man! The IR sensor that i have shows either 0 or 713. Is my sensor digital? How do i get analog outputs?

    Thanks in advance!

    0
    None
    satvik.gupta.129

    3 years ago

    And one thing more the motors are working in part 1 of your tutorial but not in second one...

    0
    None
    satvik.gupta.129

    3 years ago

    And one thing more the motors are working in part 1 of your tutorial but not in second one...

    0
    None
    satvik.gupta.129

    3 years ago

    Hi, my sensors and motors are not working with the code...
    Pls help me, reply as soon as possible.....
    And if possible then pls send me the connections and the code.
    Satvik.agg@gmail.com

    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.

    satvik.agg@gmail.com

    2 replies

    Its the exact same just with the addition of the ultra sensor.
    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.

    0
    None
    hsingh39

    3 years ago on Introduction

    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?

    0
    None
    chaudhary.a.zaman

    3 years ago on Step 5

    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

    1 reply

    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.

    0
    None
    ahmedmahrous

    4 years ago on Introduction

    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

    1 reply
    0
    None
    yeagerxpahmedmahrous

    Reply 4 years ago on Introduction

    you should look at his instructable on "

    Building an Infrared Sensor" it has the schematic diagram. as for the leds you should look look at the part . the pin outs are normally printed on it.

    0
    None
    NIkheel94ProBodger

    Reply 5 years ago on Introduction

    Thanks.
    Once i get some free time from School i will try to update this project and take it to the next Level.