EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / Line follower robot

Line follower robot

|

Microcontroller › Arduino › Line follower robot

  • This topic has 1 reply, 2 voices, and was last updated 12 years, 6 months ago by AJISH ALFRED.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • October 19, 2013 at 11:01 am #2691
    Aquib javed khan
    Participant

    line follower robot using ir sensor, my value on white is less than black. what should i do?

    after burning code to arduino it is not working.

    when i am try to open serial port ,this also not showing any value

    my code is below ..

     

     

     

    int leftPins[] = {5,7,4}; //On the for PWM , two pins for motor direction;
    int rightPins[] = {6,3,2};
    const int MIN_PWM = 64; //this can range from 0 to MAX_PWM;
    const int MAX_PWM = 128; //this can range from around 50 to 255;
    const int leftSensorPin = 0;
    const int rightSensorPin = 1;
    int sensorThreshold = 0;

    void setup()
    {
      for(int i=1; i<3; i++)
      {
        pinMode(leftPins, OUTPUT);
        pinMode(rightPins
    , OUTPUT);
      }
    }
    void loop()
    {
        int leftVal = analogRead(leftSensorPin);
        int rightVal = analogRead(rightSensorPin);
        
           if(sensorThreshold == 0){ //have the sensor been calibrated ?
          // if not, calibrate sensor to somethingabpve the ambient average
           sensorThreshold = ((leftVal + rightVal) / 2) + 100 ;  
          }
           if( leftVal > sensorThreshold || rightVal > sensorThreshold)
           {
             // if there is adeqate light to move ahead
             setSpeed(rightPins, map(rightVal,0,1023, MIN_PWM, MAX_PWM));
             setSpeed(leftPins, map(leftVal,0,1023, MIN_PWM, MAX_PWM));
           }
    }

    void setSpeed(int pins[], int speed )
    {  
      if(speed < 0)
      {
        digitalWrite(pins[1],HIGH);
        digitalWrite(pins[2],LOW);
        speed = -speed;
      }
     else
      {
       digitalWrite(pins[1],LOW);
       digitalWrite(pins[2],HIGH);
      }
     analogWrite(pins[0],speed);
    }

     

     

     

     

    October 21, 2013 at 5:11 am #10540
    AJISH ALFRED
    Participant

    Hi Aquib,

     

    “if( leftVal > sensorThreshold || rightVal > sensorThreshold)”

     

    You are checking for a high threshold, right?

    Why dont you set a low threshold value, which is graeter than zero and check for it?

     

    “if( leftVal < sensorThreshold || rightVal < sensorThreshold)”

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • Getting into an LED bulb April 21, 2026
  • understanding of resonance in time domain April 21, 2026
  • Beginner Questions About CNC Machines – G-code, Control Systems & Accuracy April 21, 2026
  • A Must-Watch Video Showing Dangerous Construction of Cheap Lithium-Ion Cells April 21, 2026
  • S1MJ ? April 20, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise