Sharp ir distance sensor


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2009
    Location
    malaysia
    Posts
    3

    Default Sharp ir distance sensor

    HI.I'M WORKING FOR MY FINAL YEAR PROJECT WHICH IS I MAKE TO MAZE MAPPER ROBOT.FOR THIS PROJECT I USE 3 IR SENSORS (sharp GP2D120XJ00F),2 12VDC MOTOR WITH ENCODER (PD3046) AND 1 PIC18F4550 MICROCONTROLLER.I HAVE MAKE THE SENSORS CODING SEPARATELY BUT I CAN'T COMBINE THE 3 SENSORS CODING INTO 1 CODING.I'VE TRIED TO COMBINE THE SENSORS CODE BUT IT'S DOESN'T WORK AT ALL.HOW CAN I COMBINE THE 3 SENSORS?THERE'S ANYBODY CAN HELP ME TO SOLVE THE PROBLEM.FOR YOUR INFORMATION, I CONNECT THE 3 SENSORS AT THE PORTA0-A2.I ATTACH MY SENSORS CODE BELOW:

    COMBINATION OF 3 SENSOR


    define osc 8

    defenition
    DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
    DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
    DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
    DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
    DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    MRCW1 VAR PORTD.4
    MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
    MRCW2 VAR PORTD.6
    MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
    TRISD.4=0
    TRISD.5=0
    TRISD.6=0
    TRISD.7=0
    TRISA=1
    ADCON1=%00001110
    SENSOR1 VAR BYTE
    SENSOR2 VAR BYTE
    SENSOR3 VAR BYTE

    HPWM 1,150,1000

    main program
    MAIN:

    GOSUB fwd
    pause 1000
    GOSUB IR1
    PAUSE 1000
    GOSUB IR3
    PAUSE 1000
    GOSUB IR2
    PAUSE 1000
    GOTO MAIN

    FWD:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=1
    HPWM 2,150,500
    MRCCW2=1
    MRCW2=0

    RETURN

    IR1:
    ADCIN 0,SENSOR1

    IF SENSOR1>46 THEN
    GOSUB RIGHT
    pause 1000

    ELSE
    if SENSOR1<46 THEN
    GOSUB FWD
    pause 1000
    ENDIF
    ENDIF
    pause 1000

    RETURN

    IR2:
    ADCIN 1,SENSOR2

    IF SENSOR2>46 THEN
    GOSUB BWD
    pause 1000

    ELSE
    if SENSOR2<46 THEN
    GOSUB fwd
    pause 1000
    ENDIF
    ENDIF
    pause 1000

    RETURN

    IR3:
    ADCIN 2,SENSOR3

    IF SENSOR3>46 THEN
    GOSUB LEFT
    pause 1000

    ELSE
    if SENSOR3<46 THEN
    GOSUB FWD
    pause 1000
    ENDIF
    ENDIF
    pause 1000

    RETURN

    RIGHT:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=1
    HPWM 2,150,500
    MRCCW2=0
    MRCW2=0
    RETURN

    LEFT:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=0
    HPWM 2,150,500
    MRCCW2=1
    MRCW2=0
    pause 1000
    RETURN

    BWD:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=1
    HPWM 2,150,500
    MRCCW2=1
    MRCW2=0
    PAUSE 1000
    GOSUB RIGHT

    RETURN

    FOR THE SEPARATE CODE OF SENSOR:

    SENSOR 1

    define osc 8

    'defenition
    DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
    DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
    DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
    DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
    DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    MRCW1 VAR PORTD.4
    MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
    MRCW2 VAR PORTD.6
    MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
    TRISD.4=0
    TRISD.5=0
    TRISD.6=0
    TRISD.7=0
    TRISA.0=1
    ADCON1=%00001110
    SENSOR1 VAR BYTE

    HPWM 1,150,1000

    'main program
    MAIN:

    GOSUB fwd
    pause 1000
    GOSUB IR1

    GOTO MAIN

    FWD:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=1
    RETURN

    IR1:
    ADCIN 0,SENSOR1

    IF SENSOR1>46 THEN
    GOSUB BREAK


    ELSE
    if SENSOR1<46 THEN
    GOTO MAIN

    ENDIF
    ENDIF
    pause 1000

    GOTO IR1

    BREAK:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=0
    RETURN


    AND FOR SENSOR 2

    define osc 8

    'defenition
    DEFINE CCP1_REG PORTC ' Hpwm 1 pin port
    DEFINE CCP1_BIT 2 ' Hpwm 1 pin bit
    DEFINE CCP2_REG PORTC ' Hpwm 2 pin port
    DEFINE CCP2_BIT 1 ' Hpwm 2 pin bit
    DEFINE ADC_BITS 8 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    MRCW1 VAR PORTD.4
    MRCCW1 VAR PORTD.5 'MOTOR RIGHT DRIVE
    MRCW2 VAR PORTD.6
    MRCCW2 VAR PORTD.7 'MOTOR LEFT DRIVE
    TRISD.4=0
    TRISD.5=0
    TRISD.6=0
    TRISD.7=0
    TRISA.1=1
    ADCON1=%00001100
    SENSOR2 VAR BYTE

    HPWM 1,150,1000

    MAIN1:

    GOSUB FWD
    pause 1000
    GOSUB IR2
    GOTO MAIN1

    FWD:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=1
    pause 1000
    RETURN

    IR1:

    ADCIN 1,SENSOR2

    IF SENSOR2>46 THEN
    GOSUB BREAK

    ELSE
    if SENSOR2<46 THEN
    GOTO MAIN1
    ENDIF
    ENDIF
    goto IR2

    BREAK:
    HPWM 1,150,500
    MRCCW1=0
    MRCW1=0
    RETURN


    PLEASE HELP ME,I'M DESPERATELY NEED THE SOLUTION OF MY PROBLEM.THANK YOU.

  2. #2
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,611


    Did you find this post helpful? Yes | No

    Wink

    Hi, hasnan ...

    First, could you write LOWERCASE ??? ... thanks for other's eyes !

    NOW, just Two Questions :

    1) Is there a Comparators module aboard the 4550 ???

    2) Do you think this is enough : " TRISA.1=1 " ???


    Alain
    Last edited by Acetronics2; - 10th October 2009 at 15:27.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  3. #3
    Join Date
    Oct 2009
    Location
    malaysia
    Posts
    3


    Did you find this post helpful? Yes | No

    Default sharp ir distance sensor

    Hi Alain,

    For the answer of your question;

    1.Yes,i have the Comparators module aboard the 4550 which is this 4550 have analog comparators on PORTA and another port.I will attach the picture of PIC18F4550.These 3 sensors were connected through PortA0 to PortA2.

    2. Actually i used TRISA.1=1 just for test one of my sensor either it is function or not.I used the TRISA=1 so that all my 3 sensors active but the problem was from the instruction of ADCON1.there seems like the sensors not funtion when i used only 1 ADCON1 to combine all of 3 sensors.
    Attached Images Attached Images  
    Last edited by hasnannordin; - 11th October 2009 at 05:23. Reason: attach the file

  4. #4
    Join Date
    Oct 2009
    Location
    malaysia
    Posts
    3


    Did you find this post helpful? Yes | No

    Default IR sensor

    oh yes alain i forgot to attach my schematic diagram of my project.i will attached my circuit diagram for your reference.
    Attached Images Attached Images  

Similar Threads

  1. Need a cheap touch sensor idea.. here it is
    By mister_e in forum Code Examples
    Replies: 20
    Last Post: - 16th April 2016, 23:42
  2. Ultrasonic distance sensor with PIC16F84A
    By MrRoboto in forum mel PIC BASIC
    Replies: 3
    Last Post: - 29th June 2009, 10:01
  3. Need Help with GP2Y0A21 IR Sensor
    By azmax100 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 25th January 2009, 12:51
  4. line follower - IR sensor
    By shirleyz in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 29th May 2008, 13:14
  5. distance sensor
    By ngeronikolos in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 27th January 2006, 11:37

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts