Light follower using pic 16f877 and 3 ldr

Thread Starter

roula

Joined Dec 30, 2014
4
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
 

MrChips

Joined Oct 2, 2009
30,824
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.
 

ErnieM

Joined Apr 24, 2011
8,377
So it cannot be used to compare two ldr ???
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.
 

Thread Starter

roula

Joined Dec 30, 2014
4
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
 

ErnieM

Joined Apr 24, 2011
8,377
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.
 

MagicMatt

Joined Sep 30, 2013
117
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.
 
Top