Shop OBEX P1 Docs P2 Docs Learn Events
help require on generating 38khz — Parallax Forums

help require on generating 38khz

samalsamal Posts: 8
edited 2008-10-02 06:00 in BASIC Stamp
hello gurus,

i hooked up a IR LED to my basic stamp 2 with a 220 ohm series resistor to pin 14 and a 38khz receiver to pin 15. i am pretty new to basic stamps. now i need to generate a 38khz signal on pin 14 and listen to pin 15.

pls help me with the code.

thanks,
Sam

Comments

  • NR1XNR1X Posts: 111
    edited 2008-10-01 09:56
    goto the parallax store and find the ir transmitter/led.. there is an app note thats got everyting you'll need to send and receive ir.. just follow the link.. the zip file contains a pdf and all source code..
  • stephenwagnerstephenwagner Posts: 147
    edited 2008-10-01 12:19
    Samal,

    I have used this with great results.

    http://www.rentron.com/remote_control/TX-IR.htm

    http://www.rentron.com/Files/TX-IR.pdf

    I used it for this customer application.

    http://www.parallax.com/tabid/321/Default.aspx

    I will post the code when I find it.

    SJW
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-01 13:23
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    INPUT 15
    PinState VAR Byte

    MAIN:
    · FREQOUT 14, 1, 38000 ' Send 38,000 hz out the IR-Pin for 1 millisecond.
    · PinState = IN15 ' The IR decoder holds its active low signal long enough to be read here.
    · IF (PinState = 0)· THEN
    ··· SEROUT 16, 16468, [noparse][[/noparse]"I see it!", CR]
    · ELSE
    ··· SEROUT 16, 16468, [noparse][[/noparse]"No IR Echo.", CR]
    · ENDIF
    · PAUSE 500 ' You need this pause, or data flys by too fast.
    · GOTO MAIN


    So, load the above code into your BS2. Open the terminal window on the IDE -- it will get the SEROUT messages above.
    Then move your hand so it reflects the IR light into the IR-Decoder. When you get close enough, "I see it!" messages should
    come out on the terminal window.

    Geez, tough group, all he wanted was some code.

    Post Edited (allanlane5) : 10/1/2008 1:28:59 PM GMT
  • RDL2004RDL2004 Posts: 2,554
    edited 2008-10-01 14:21
    While it is possible to generate the 38kHz in code (and worth doing for the learning experience), this uses Stamp capability that may be better applied elsewhere. It's pretty easy to build an oscillator (a 555 timer is often used) to drive one or more IR LEDs, then all you need the Stamp to do is check whether the receiver has detected the signal or not.

    There is some good info here:

    www.robotroom.com/Infrared555.html

    For more, just Google 38kHz

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Rick
  • samalsamal Posts: 8
    edited 2008-10-01 14:24
    first of all,

    thanks a bunch! for your quick replies

    after i posted this question i tried looking into the help of stamp and found a command FREQOUT and i used it like this:


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}

    DO
    FREQOUT 14, 1, 38000
    DEBUG ? IN15
    LOOP UNTIL IN15 = 0

    END

    but this never came out of the loop even if the debug window was showing IN15 = 0 after i put a book in front of the ir thingy.

    i need to try out Allans code. The idea of delay seems to be logical.

    cheers,
    Sam
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-01 18:37
    The problem is that you MUST read the "IN15" value into a variable. The IR-Detector does not hold that value very long. With your code, you read IN15 once as part of the DEBUG statement, then send that value out port 16, so that by the time you read IN15 AGAIN, the IR-Detector is no longer holding the pin low.

    You can fix this with a simple:

    MyVal VAR BIT

    DO
    FREQOUT 14,1,38000
    MyVal = IN15
    DEBUG ? MyVal
    Loop until MyVal = 0

    END
  • samalsamal Posts: 8
    edited 2008-10-02 06:00
    yeah! that worked pretty neat!

    Here is what I achieved by modifying Allan's code.

    Mod to previous circuit : I mounted the IR tx-rx pair onto a standard servo and the code below makes
    Servo - P0
    IR tx - P15
    IR rx - P14

    Mod to code: I added a lil bit of debouncing for false triggering on IR recevier pin (pls correct me if i screwed up!)


    Operation:
    - the servo point 12 o'clock first
    - if i put my hand in front of the IR, it turns 10 o'clock and scans for objects
    - if i put my hand in front of the IR, it turns right 2 o'clock and scans for objects
    - if i put my hand in front of the IR, it turns back to 12 o'clock and scans for objects

    The present code is attached along with pictures of my $8 robot and BS homework board.

    This is pretty cool for me as a first timer!. Thanks to all you guys out there.

    I need a lil more help with the servo though.... this is what i want:

    Mod to circuit: add one more IR tx-rx pair. Allign both tx-rx pair with 45-50 degrees angle between them.

    i want to scan the IR while moving the servo. to me it seems that i would screw up with the timings so i needa lil help. i already read through teh servo control posting but still not able to figure out

    -Thanks,
    Sam



    yeah.gif
    352 x 288 - 17K
    352 x 288 - 17K
    352 x 288 - 17K
    352 x 288 - 15K
Sign In or Register to comment.