Shop OBEX P1 Docs P2 Docs Learn Events
IR sensor application — Parallax Forums

IR sensor application

erict15erict15 Posts: 3
edited 2010-08-03 05:51 in BASIC Stamp
I am wondering if it is possible to use the BASIC Stamp with an IR sensor to send a command to a program (for example, send the play command to media player).
Currently, I am using this code from Parallax:
' =========================================================================
'
'   File...... PIR_Simple.bs2
'   Purpose... Show Output State Of PIR Sensor
'   Author.... Parallax, Inc.
'   E-mail.... support@parallax.com
'   Started... 12-14-2005
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================

' -----[noparse][[/noparse] Program Description ]---------------------------------------------

' This program displays the current state of the PIR Sensor connected to P0
' on the DEBUG screen.


' -----[noparse][[/noparse] Program Code ]----------------------------------------------------

Main:
  DO
    DEBUG HOME, BIN1 IN0                ' Display Status Of P0 At Home Pos.
    PAUSE 100                           ' Small Delay
  LOOP                                  ' Repeat Forever


What I want to do (in pseudocode):
IF P0=1 THEN play_music()

I looked at www.lirc.org/ and that gives an idea of what I want to do, but is much more advanced. Does anyone have any ideas on how to implement this?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-02 13:28
    You can use a PIR sensor to trigger a Stamp program which can control something else. Keep in mind that the PIR sensor's response time is slow.

    Whether you can control your media player depends on what kind of media player you have. There are several MP3 players that can be controlled directly by a microcontroller like a Stamp. The Vinculum VMusic2 is one example (Google "Vinculum VMusic2") that I've used for a sequenced sound player. You can also take other MP3 players, take them apart, solder wires across the play button switch (and possibly other buttons), and use a reed relay to close the switch contacts with the relay controlled by the Stamp.
  • erict15erict15 Posts: 3
    edited 2010-08-02 18:13
    What I was thinking of was to have the BASIC Stamp send some kind of signal to a software program, such as Windows Media Player/Media Center so that the music would start. This would probably be more in programming the Stamp IDE though.
  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-02 18:29
    Most communication like this between a Stamp and Windows is done using serial I/O. On the Stamp side, you just use the SEROUT and SERIN statements, typically with port #16 which uses the built-in programming serial port of the Board of Education. On the Windows side, you'll need to write a program that opens a serial port to the Stamp and accepts commands from the Stamp, then somehow activates the Windows Media Player.
  • erict15erict15 Posts: 3
    edited 2010-08-03 05:51
    Thanks for your help. I got it working now.
Sign In or Register to comment.