i'm using an ultrasonic SRF05 range finder sensor along with pic16f876 and a couple of LDR sensors.

i'm using the sonar module to detect objects above my robot.

if distance >= 4 then

m_detection = 0
'stop

else

m_detection = 1
'move forward

end if


The problem is as follows:

if an object is at a distance of more than 4inches then it stops, if the object is < 4inches away then it moves forward, this is working as it should. The problem happens when there is no object at all - the motors just shudder :S

now also if i comment out the LDR code the sonar appears to work...

Sonar Ping :

Code:
Code:
sonar:

'---------PING----------------------------------------
sonarcontrol = 1 				 'module on
trigger = 0
pulsout trigger, 1  

pulsin echo, 1, range 			 'measure high state

if range <> 0 then	  			 'if pulsin times-out it returns 0
   distance = range /  15 		 'convert: 15=inches at 4MHz
end if

sonarcontrol = 0 	  			 'module off
'-----------------------------------------------------

return
Reading the LDRs

Code:
Code:

check_LDR:

  HIGH portb.4 'Right_LDR               	  'Make right CDS pin high
  PAUSE 3                      	 	  		  ' Let cap charge
  RCTIME portb.4, 1, LDR_Right_RCdata 		  ' Time & record discharge time 


  HIGH portb.5 'Left_LDR                	  'Make left CDS pin high
  PAUSE 3                      				  ' Let cap charge
  RCTIME portb.5, 1, LDR_Left_RCdata   		  ' Time & record discharge time

LDR_Right_Val =  NCD LDR_right_RCdata
LDR_Left_Val =   NCD LDR_left_RCdata
return
i've been struggling with this for some time now and i'm fairly confused.. any pointers would be very helpfull

thanks

jim