element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum I need some help and don't know more where look :/
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 2 replies
  • Subscribers 417 subscribers
  • Views 327 views
  • Users 0 members are here
Related

I need some help and don't know more where look :/

e14 Contributor
e14 Contributor over 13 years ago

Hello Guys,

 

First I isn't be a good writer on English Language but a will try my best for you help me.

 

I'm using a QTR-8A on a Robot but a I need do this with him...

Following a Line and Line Breaks...

 

This is my program for follow line:

 

<code>

#include <DualVNH5019MotorShield.h>

#include <QTRSensors.h>

 

 

DualVNH5019MotorShield md; //declaracao dos pinos dos motores

QTRSensorsAnalog qtr((unsigned char[]) {0, 1, 2, 3, 4, 5, 6, 7}, 8); // declaracao sensores analogicos

 

 

unsigned int sensors[8]; //diz quantos sensores tem utilizados

 

 

const float KP = 0.1; // potencial

const float KD = 5.0; // derivado

 

 

int last_error = 0; // erro

 

 

const int M1 = 200; // velocidade 1

const int M2 = 200; // velocidade 2

 

 

void setup() {

  md.init();

  md.setSpeeds(200, -200);

  for (int i = 0; i < 250; i++) {

    qtr.calibrate();

    delay(20); // rotina de calibracao 1

  }

  md.setSpeeds(-200, 200);

  for (int i = 0; i < 250; i++) {

    qtr.calibrate();

    delay(20); // rotina de calibracao 2

  }

}

 

 

void loop() {

  int position = qtr.readLine(sensors);

  int error = position - 1000;

  int motor_speed = (int)(KP * error + KD * (error - last_error));

 

  last_error = error;

  int m1_speed = M1 + motor_speed;

  int m2_speed = M2 - motor_speed;

  m1_speed = constrain(m1_speed, 0, 400);

  m2_speed = constrain(m2_speed, 0, 400);

  md.setSpeeds(m1_speed, m2_speed);

}

</code>

 

But I don't know how I do for him pass the Break Line !.

Help me guys please !

  • Sign in to reply
  • Cancel
  • gihu
    0 gihu over 13 years ago

    Olá Luis Henrique,

     

    I suppose you mean dashed line when say break, am I rigth?

    If yes, and you have your robot working following a normail line. What you can do is,  when no line is read you go straight (same speed on both motor) for a very short time (ms) and read the sensor again, because of the robot is going straight and the width of the sensor is bigger than the width of the lines, probably you will have no problem, despite of this, just make 3 or 4 tempts in order not make the robot go out of the route.other optionis when the robot cannot sense the lines, go straight until it senses a line again, and you can use a timer for do it just for a while, in order not to take the robot out of the route.

     

    Hope it helps, let me know your progress on it.

     

    Regards,

    Miguel

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • billabott
    0 billabott over 13 years ago

          From
    http://www.pololu.com/docs/0J19/all


    void
    loop()

    {
      unsigned int sensors[3];
      // get calibrated sensor values returned in the sensors array, along with the line position
      // position will range from 0 to 2000, with 1000 corresponding to the line over the middle sensor
      int position = qtr.readLine(sensors);

      // if all three sensors see very low reflectance, take some appropriate action for this situation
      if (sensors[0] > 750 && sensors[1] > 750 && sensors[2] > 750)
      {
        // do something.  Maybe this means we're at the edge of a course or about to fall off a table,
        // in which case, we might want to stop moving, back up, and turn around.
        return;
      }

      // compute our "error" from the line position.  We will make it so that the error is zero when
      // the middle sensor is over the line, because this is our goal.  Error will range from
      // -1000 to +1000.  If we have sensor 0 on the left and sensor 2 on the right,  a reading of -1000
      // means that we see the line on the left and a reading of +1000 means we see the line on
      // the right.
      int error = position - 1000;

      int leftMotorSpeed = 100;
      int rightMotorSpeed = 100

    --
    William Alan Thomas Bottger
    "Meaning, Reduction, Recursion"
    Mathgomery, AL

    Play along with me at the
    Rebel Matrix Math challenge
    http://mathcontest.olemiss.edu/
       .
        .
    On the other hand ===>>

      // if all three sensors see very HIGH reflectance, take some appropriate action for this situation

      if (sensors[0] < 100 && sensors[1]  < 100 && sensors[2]< 100)

      {

        // do something.  Maybe this means the robot has found a break in the line

        // in which case, we might want to move straight ahead for a reasonable distance, before travelling along a curved (know circlular arc of fixed radius) path to the unknown line or the original line and having measured the distance traveled know the difference.

        return;

      }

     

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube