Light follower using pic 16f877 and 3 ldr

Discussion in 'Embedded Systems and Microcontrollers' started by roula, Dec 30, 2014.

  1. roula

    Thread Starter New Member

    Dec 30, 2014
    4
    0
    Hello
    I really need help: I am doing my first project: Light follower robot using ldr pic 16f877 and assembly language
    If the right ldr is exposed to light the robot goes right until the middle one is exposed to light so the robot moves forward
    can anyone help me?
    plz it is urgent
    thank u
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,442
    3,361
    If we do your homework or school project will we get the marks?

    Show us what you have do so far and we might be able to assist from there.
     
  3. roula

    Thread Starter New Member

    Dec 30, 2014
    4
    0
    We havent learned about comparator but i was wondering if it can be helpful ?
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    A comparator can be quite useful in conditioning the LDR output for a PIC pin to read.
     
  5. roula

    Thread Starter New Member

    Dec 30, 2014
    4
    0
    So it cannot be used to compare two ldr ???
     
  6. jpanhalt

    AAC Fanatic!

    Jan 18, 2008
    5,694
    904
  7. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    Sure it could, you could probably arrange several comparators to work out the entire drive motor control, but then what would the PIC be doing?

    The LDR is an "analog" device while giving the PIC digital inputs leads to simpler code. The PIC is not hopeless when it comes to analog by using the built in analog to digital (A2D) converters. It's much harder for a beginner to use A2D then a simple digital signal but not impossible. You basically need to read (use a voltmeter) what the LDR output is for "no line" and "line" sensing, then pick a number between these to compare.

    I see this as three sections: the LDRs to read where the line is, the motors & drivers, and the controller between them. My approach would be to work from the edges to the middle: make the LDRs and the motors & drivers, then see what you need to sense the LDR and control the motor drivers.

    Basically you have 3 inputs (the LDRs) and 2 outputs (L & R motor drivers). The code to follow such a table is simple, getting the LDRs read is the tricky part.
     
  8. RRITESH KAKKAR

    Senior Member

    Jun 29, 2010
    2,831
    89
    Hello,

    Don't use this LDR only IR because it is very difficult TO CALIBRATE!
     
  9. roula

    Thread Starter New Member

    Dec 30, 2014
    4
    0
    I ve done the code and simulation and it worked my only problem is if i run the simulation and there is no loght source the motors go forward can anyone? I want it to wait for a light source to move
     
  10. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
    What inputs? How does the PIC see the LDR outputs? Digital or analog?

    Which simulator? The one in MPLAB?

    The MPLAB simulator allows for stimulus inputs to be presented to the code simulating digital inputs on the pins. If they are analog inputs you can still change the value of the variable where the reading is placed.

    Breakpoints allow you to halt the simulation, see what is happening, and change the inputs for another loop thru.
     
  11. MagicMatt

    Member

    Sep 30, 2013
    117
    14
    Why bother with comparitors etc. when most PICs have several ADC channels that could be used directly. Just read the ADC value for each LDR in turn, then let your code do the decision making.
     
Loading...