Shop OBEX P1 Docs P2 Docs Learn Events
Sound Implact Sensor Project with basic stamp 2 — Parallax Forums

Sound Implact Sensor Project with basic stamp 2

So I am working on a project using the Sound Impact sensor, and my objective is to be able to turn on a system (light or fan) when you blow into the impact sensor and when you blow into it twice it then turns off the system.
i was able to figure out the commands that will turn on the system was this

' {$STAMP BS2}
' {$PBASIC 2.5}
Main:
DIR1=1
DO
IF IN15 = 1 THEN
HIGH 1
PAUSE 500
ELSEIF IN15 = 0 THEN
LOW 1
ENDIF
LOOP
IF IN15 = 1 THEN

but I just don't know what to do to make the system know that I want to turn off the system when I blow into it twice, any help will be appreciated.

Comments

  • There are two different situations:
    1) You trigger the sensor once and the system turns on. You trigger the sensor a second time (once it's on) and the system turns off.

    2) You trigger the sensor once (in some period of time) and the system turns on (or stays on). You trigger the sensor twice (in some period of time) and the system turns off (or stays off).

    Which do you want?
  • So I am working on a project using the Sound Impact sensor, and my objective is to be able to turn on a system (light or fan) when you blow into the impact sensor and when you blow into it twice it then turns off the system.
    i was able to figure out the commands that will turn on the system was this

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    Main:
    DIR1=1
    DO
    IF IN15 = 1 THEN
    HIGH 1
    PAUSE 500
    ELSEIF IN15 = 0 THEN
    LOW 1
    ENDIF
    LOOP
    IF IN15 = 1 THEN

    but I just don't know what to do to make the system know that I want to turn off the system when I blow into it twice, any help will be appreciated.
  • The second option, I want that when I blow into it once it turns on and stays on and when I blow into it 2 consecutive it turns off and stays off.
  • You need a loop that checks the trigger maybe once every 1/10 second (using a PAUSE 100 in the loop). Each time through the loop, you save the trigger status in a variable. You compare the actual trigger state with the saved state from the previous loop and increment a counter if saved = on and actual = off. This uses the trailing edge of the pulse as the indication that the trigger has occurred. If this is true, you increment a counter. If the counter is 1, you reset another counter to zero. If the counter is 2, you turn the system off and reinitialize. Just before the end of the loop, you increment the 2nd counter and check it. If it reaches 20, turn the system on and reinitialize. What you're doing is keeping a count of the number of times the trigger occurs. If two trigger pulses occur within 2 seconds, the system is turned off. If only one trigger occurs by 2 seconds from the first trigger, the system is turned on.
  • Okay thank you, I will try it out and see how it goes.
  • denzx wrote: »
    The second option...
    But Mike Green's first option makes a lot more sense and is easier to program...

  • Hey, do you mind sharing the final code you came up with for this system, I'm trying to do something similar & really need help
Sign In or Register to comment.