1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Line Following Robot

Discussion in 'Robotics & Mechatronics' started by Omar.M, Jan 26, 2007.

  1. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Hello everyone.
    I want to make a simple, little line following robot for my desk, so I can watch it move around a line. The thing is, I want to keep this as simple as possible, just for a fun little weekend project.

    I am going to be using some very small, two DC motors (that I might get from a previous toy) and a microcontroller (16F628A or 16F684). As for the line detecting I have heard it can be done with a LED IR detector and emitter (both of which I currently have).

    So much question to you is, how do I set up (and program) the line detecting part of the project, using the emitter and detector. Preferably, any information on how I can wire it too, will help. As for the DC motors, I think it'll be quite easy. If I just stick the positive to an output pin and set it to high (and connect other end to ground), that motor will start to spin-- correct?

    Thanks a lot for your help,
    Omar
     
  2. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    If it's a dark line on a light surface, I'm prety sure its just programmed to go straight if neither left and right detectors see light. Then if the left/right detector detects dark, then the robot just starts turning left/right. Some robots have 4 sensors- an inner left/right pair and an outer left/right pair with the second pair farther out to the edges of the robot. This way, if your robot passes outside of the two sensors before the robot has corrected for it, there is still one last chance to track the line as it passes beneath the outter pair of sensors- otherwise you will lose the line.

    You could also have a center sensor in combination with 2 or 4 side sensors. The robot assumes that it is on top of the line whenever the side sensors read light. This means that if the robot loses the line, it will think wherever it is going is correct. If there is a center sensor present and it reads light then it means the line is not directly under the robot and it knows for sure some correction has to be made. This way, if the robot completely loses the line (ie. the center sensors reads light for too long and doesn't read dark again no matter how the robot tries to correct it, while the others.

    Many people just stick 6-10 sensors since photo detectors are so cheap. If a more expensive sensor is being used, then it's about 4 or so if the person wants reliability. The cheap robots just use two cheap sensors.

    You cant drive a motor by connecting it to a pin of a microcontroller- it can't provide enough current. You need a motor driver/H-bridge. You probably also want direction control.
     
    Last edited: Jan 26, 2007
  3. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Thanks for the quick reply. Actually, that makes quite a bit of sense. But rather, how would I set this up? Which pins would I connect the detector to, the emitter? How would it tell it if it is receiving any IR?

    And as for the motor- darn. That's a bummer. I really thought it was possible-- after all I am using a REALLY small motor (I am hoping to make this robot very small, and it'll be very light. And where I am getting it from (an old hand held fan) which runs on 2 AA batteries. Will this one not work, either?

    Omar
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,022
    Likes:
    317
    Location:
    Brisbane Australia

    Have a look at this page. This site has description, circuit and software explanations for building a tiny line follower. It even demonstrates the difference between simple Proportional only control and Proportional + Differential control.

    Here's a pic,
    [​IMG]

    Mike.
     
  6. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Ah, thank you very much. I have seen that page, and the thing is that the author is using an ATMEL chip whereas I am using a PIC microcontroller. A lot of those things that are talked about seem quite complicated -- I just want to use 1 detector and 1 emitter. Though, the diagrams DID help explain how I can set up the line detecting.

    I guess my question now is, if this makes sense:
    I set up a LED emitter on one pin that is HIGH. On another is a detector, that is input. Through BASIC (great cow basic), how will I know that the detector is picking up something? When the detector sees the IR, will it complete the circuit or something?

    And where should I place the emitter and detector underneath the bot (does the detector go in the middle and emitter to the side?)..
    Thanks so much!
     
  7. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,022
    Likes:
    317
    Location:
    Brisbane Australia
    The algorithm is the same no matter which processor you use. Interfacing the detectors/motors is pretty much the same. You have to use at least 2 sets of sensors for this to work, if you only have 1 then you don't know which side of the line you are on.

    Mike.
     
  8. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Oh ok. Is that two different LED Emitters and detectors? Or two detectors and one emitter?

    And as for the motor -- will the ones from a simple toy work? I guess it runs around 5 volts (because it runs on 2 AA batteries), and all I really need to do is turn one on and off depending on line.
     
  9. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    You need multiple detectors for sure. If your emitter is strong enough and wide enough to illuminate the area that both detectors are looking at, you only need one. If there's just one light in the room, you're not blind in one eye right?:D

    Yeah simple motors work.
     
  10. House0Fwax

    House0Fwax Member

    Joined:
    Nov 15, 2006
    Messages:
    583
    Likes:
    17
    Location:
    Hampshire U.K.
    Here's one to look at;
    http://www.geocities.com/tjacodesign/cerberes/cerberes.html
    Tjaco's design graveyard

    Ooops, sorry, I have just realised that it's not a line follower, still, it might be a start.
     
    Last edited: Jan 27, 2007
  11. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Oh I think I understand now. So I put the emitter (a few) directly in the middle. And the detectors will be off to the side.

    I am glad to know that the motors will work out.
    Thank you very much!

    Just a quick question: PIC micro controllers I heard need a pretty smooth 5V fed to them so they can function (since for all of my projects I use a voltage regulator and some caps to smooth out the current). Is this the MAXIMUM voltage they can get? What is the minimum? Like that article that Mike linked (a few posts above), I want to run my robot off small batteries (maybe not watch-cell batteries, but maybe AA).
     
  12. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    You want the emitters to be lighting up the area that the detector is looking at more than you want the emitters to be lighting up the line. so try spreading out the emitters. Maybe one "below" or "above" each detector if the emitters are weak.

    I think the miinimum is 3.3V, but some of the PICs (or maybe even all of them) might be able to go as low as 1.8V or 2.5V. You will need a few AA in series to get the voltage you need. You're going to need that voltage for the motor anyways so you probably don't want to go too low so you can use just one set of batteries for the PIC and motors.
     
  13. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Thank you very much for your help :D. I think I have figured it out, for the most part. But you were saying using a few AA's in a series... will that not burn my microcontroller due to the high voltages? Can it not take 5V as max?

    As well, I read that I cannot just stick the IR detector onto a pin... instead I need to make a voltage divider...? Do you know what this is or if I need to make one?

    Thanks,
    Omar

    Edit: I have tried messing around with motors and microcontrollers... it seems the chip is working (I have tried using LEDs instead of motors, and they blink showing that one pin is high, then low), but when I hook my motor to the pin it doesn't work. The motors are very small, and when I tested with 1.5 volts of current, they work. I checked the output from the pins, it was about 5 volts -- which should be perfect for the motors. It just doesn't work. Any ideas why?
     
    Last edited: Jan 28, 2007
  14. heepofajeep

    heepofajeep New Member

    Joined:
    Jul 9, 2006
    Messages:
    26
    Likes:
    0
    What do you mean by 1.5V of current? How many amps (current) are you supplying? What are you using to power the motors? (not the pic, right?)
     
  15. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    Oh, I got the motor from an old fan toy, so it uses very little power. I tried different voltages (since my wall wart came with an adjustable voltage switch)... I tried 1.5-5Vs, and the motor worked very well with all of the voltages.

    I thought it would work with the PIC, because the voltage that I say from the output using my multimeter (from an output pin) was about 3-5 volts. And since I tested it with 1.5V (and it worked)... there is no reason for it not to with with the microchip.

    Yes, I am trying to supply directly from the chip -- is this a problem? And I am not so sure about the milliamps: is there any way to find out?
     
  16. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    I dont understand what you mean about how a few AA in series would burn out the PIC since it can only take 5V max...the AA are only 1.5V each so you need to put a few in series...

    You cannot connect a motor to the pins of a PIC. you need current AND voltage to drive a motor. Even though a PIC can provide 5V through the pins, it can only do so up to a few mA. If you draw more current than that from the PIC pins, the voltage will quickly drop to zero (and burn out the PIC). It's the same way a 12V, 20A power supply can only provide a maximum of 20A at 12V. If you draw more current than that out of the power supply, the voltage will start to drop.

    Even if a PIC could drive enough current to run a tiny tiny tiny, tiny, tiny, tiny motor, you don't want it to since motors are noisy and make voltage spikes that your PIC is not protected against.

    You need a driver circuit sitting between the PIC and motor to amplify the signal from the PIC into a larger current that can run the motor. This also means the PIC and the motor can be running off of different voltages (or even batteries).
     
    Last edited: Jan 28, 2007
  17. Omar.M

    Omar.M Member

    Joined:
    Dec 13, 2006
    Messages:
    293
    Likes:
    4
    OH. I think I understand now. I guess it would be valid to ask -- these motor drivers: where do you get them? Are they expensive (or am I able to make one)?

    Thanks a lot for clearing things up, all of you!
     
  18. dknguyen

    dknguyen Well-Known Member

    Joined:
    May 6, 2006
    Messages:
    6,668
    Likes:
    64
    You can get one for a few dollars up to millions so you should be able to get one easy. Especially if it's just for a small line follower. They even come in the form of ICs. You can also build one yourself and have your PIC control it.

    The basic type of control for a motor controller is an on/off signal from the PIC (motor controllers can also use serial protocals or whatever else). But physically, the transistors inside a motor controller are controlled by an on/off pulse. Instead of just using on and off pulses to turn the motor full on or full off, you can instead get the PIC to send out a PWM signal for speed control. PWM (Pulse Width Modulation) is a series of pulses at a high frequency where each pulse is HI for a certain % of the period, and LO for the remaning period. This % is called the duty cycle and causes the transistor that is being driven by it to also pass current for only that % of time. The motor will average out the full voltage on and off times and the end result is the motor "sees" less voltage from the battery and slows down giving speed control. For example, if the motor is connected to a 12V battery, and the duty cycle is 50%, the motor acts like it's connected to a 6V battery. If the frequency is too low, then the motor doesn't run so well (it's like you pushing on/off to a motor repeatedly- it starts, stops, starts). But if frequency is high enough the motor runs more smoothly. If the frequency is too high the transistors heat up because they are switching more and have to go through the lossy intermediary stage between on and off more frequently. 20kHz is a good number to go with.

    If you want your motor to reverse itself, then what you need to build is an H-bridge (or buy one). But when you were talking about using the PIC to drive the motor it sounds like you weren't even considering reverse right? it sounded like all you wanted was forward and stop. If that is the case, just use a MOSFET transistor (N-channel type or NMOS is best and most convenient compared to P-type or PMOS). The PIC drives the gate with pulses (you can use simple on/off or PWM for speed control).

    Also, motors are inductive and make voltage spikes when you switch them as a result. You need to put a diode across your motor (in reverse biased so that the diode won't be a short-circuit across the battery), so the spike current from the motor has a place to go. This protects your transistor from blowing up. In an H-bridge where current can flow both ways through a motor, you cannot put diodes across the motor (makes a short-circuit), then you put the diodes in reverse-biased parallel with all the transistors. You should also put a fairly big capacitor across the motor to smooth out the voltage.

    Single-transistor (single direction)
    http://www.dprg.org/tutorials/2005-11a/
    Just pay attention to the motor and transistor on the right in this schematic. You would connect the transistor to the motor like this schematic (don't forget the diode and cpacitor that is not shown). Your PIC would replace the IC with all those resistor and capacitors in the schematic. A pin from the the PIC would go the gate of the transistor in the same way the output pin on the 555 timer IC does in the schematic. You also might want a pull-down resistor (a high resistance around 4.7k to connect the gate to ground). THis makes it so when your PIC pin is floating for whatever reason, the gate is still connected to ground so your motor won't turn on due to noise. It also makes sure your motor can turn completely off.

    H-bridges (bidirectional)
    http://www.modularcircuits.com/h-bridge_secrets1.htm
     
    Last edited: Jan 28, 2007
  19. parinita

    parinita New Member

    Joined:
    Mar 15, 2007
    Messages:
    2
    Likes:
    0
    hello sir, i want to make a line follower robot, for tht i wan to know its hardware details, if u plz help me, i am totally unknown in this field
     
  20. parinita

    parinita New Member

    Joined:
    Mar 15, 2007
    Messages:
    2
    Likes:
    0
    sir, i wan the circuit of line follower robot, as after seeing the ckt it will be clear for me what i have to do.
     
  21. bloody-orc

    bloody-orc New Member

    Joined:
    Aug 23, 2004
    Messages:
    723
    Likes:
    4
    Location:
    Estonia
    sir, google or read threads in this forum.
     

Share This Page