the sensor works, but the led turns off and on rapidly instead of staying on what could be the problem
the sensor works, but the led turns off and on rapidly instead of staying on what could be the problem
Hmmmmm.... try putting the trig = 0 before the main loop:
Code:trig = 0 ' start output in LOW state main: GOSUB distance SELECT CASE dist CASE 0 ' PULSIN timed out and returns zero, turns LED OFF LOW led CASE IS < 8 ' dist <8 inches but not zero, turns ON LED HIGH led CASE ELSE ' dist >8 inches turns LED OFF LOW led END SELECT GOTO main distance: PULSOUT trig,1 ' each count = 10us PULSIN sens,1,dist ' will time out in 655ms if nothing received dist= dist/15 'convert to inches PAUSE 100 RETURN END
Louie
I put the low trig before the main but it still blinks I wonder if the sensor is sending stray numbers when it starts the distance routine, is there a way I can sim the pic in multisim 11? I may try programming another pic and make sure it is not an internal error
You may right about the stray or false triggering as mentioned in the data sheet.
Now try putting a little delay after the PULSOUT to give the device time to complete the transmit function before listening for an echo.
Code:distance: PULSOUT trig,1 ' each count = 10us PAUSEUS 120 ' Wait for transmit pulse to complete PULSIN sens,1,dist ' will time out in 655ms if nothing received dist= dist/15 'convert to inches PAUSE 100 RETURN END
Louie
Bookmarks