Shop OBEX P1 Docs P2 Docs Learn Events
Impact Sensor Issue, SOMEONE PLEASE HELP ASAP! — Parallax Forums

Impact Sensor Issue, SOMEONE PLEASE HELP ASAP!

daveetheewaveedaveetheewavee Posts: 3
edited 2016-04-28 10:48 in General Discussion
Hello, I am making a program where by blowing into an impact sensor, I am able to turn on an off a fan & on and off a light, so fat I have came up with this code:

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


Impact PIN 0

#SELECT $STAMP
#CASE BS2, BS2E
DurAdj CON $100
#ENDSELECT

Capture CON 2000
i VAR Nib

Main:
DO
DEBUG CLS,
"what do you want me to do?", CR
PAUSE 1000
DEBUG "Ready?"
PAUSE 500
DEBUG "BLOW!", CR
COUNT Impact,(Capture */ DurAdj),i
DEBUG CR, "You blowed ", DEC i, " times", CR
IF i=2 THEN fo
IF i=3 THEN foff
PAUSE 3000
DEBUG "Blow to go again"
DO : LOOP UNTIL (Impact = 0)
LOOP
END


fo:
DEBUG "fan on"
RETURN

foff:
DEBUG "fan off"
RETURN

But I'm having an issue with the impact sensor, when I blow into it once, it would give me a value of 4 or 5, or if I blow into it twice, it was give me a value of like 13 or 14, I need help fixing this problem so that if I blow once, it will give me a value of one & if I blow twice, it will give me a value of two and so on & so forth

Comments

  • kwinnkwinn Posts: 8,697
    Hello, I am making a program where by blowing into an impact sensor, I am able to turn on an off a fan & on and off a light, so fat I have came up with this code:

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


    Impact PIN 0

    #SELECT $STAMP
    #CASE BS2, BS2E
    DurAdj CON $100
    #ENDSELECT

    Capture CON 2000
    i VAR Nib

    Main:
    DO
    DEBUG CLS,
    "what do you want me to do?", CR
    PAUSE 1000
    DEBUG "Ready?"
    PAUSE 500
    DEBUG "BLOW!", CR
    COUNT Impact,(Capture */ DurAdj),i
    DEBUG CR, "You blowed ", DEC i, " times", CR
    IF i=2 THEN fo
    IF i=3 THEN foff
    PAUSE 3000
    DEBUG "Blow to go again"
    DO : LOOP UNTIL (Impact = 0)
    LOOP
    END


    fo:
    DEBUG "fan on"
    RETURN

    foff:
    DEBUG "fan off"
    RETURN

    But I'm having an issue with the impact sensor, when I blow into it once, it would give me a value of 4 or 5, or if I blow into it twice, it was give me a value of like 13 or 14, I need help fixing this problem so that if I blow once, it will give me a value of one & if I blow twice, it will give me a value of two and so on & so forth

    Sorry Dave, but in general you have to use whatever output a sensor sends you. In this case you could compare the value to 8 or 9 and pass a 1 if the input is lower and 2 if it is higher.
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    I wouldn't use the COUNT command for this. It counts pulses within a fixed period of time, but it is entirely possible that when you're blowing into the sensor just once, you're triggering it multiple times. I would instead use a state-machine type of detection and then wait a small, but fixed amount of time before testing for a second input.
  • state
    I wouldn't use the COUNT command for this. It counts pulses within a fixed period of time, but it is entirely possible that when you're blowing into the sensor just once, you're triggering it multiple times. I would instead use a state-machine type of detection and then wait a small, but fixed amount of time before testing for a second input.

    So what kind of state-machine type should I use, like what do you recommend I do?
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    You're basically just detecting that the sensor transitioned from the inactive state, to the active state and back before delaying to test for a second occurrence.
  • Which sensor are you using. Way back when I was working on a project for the micromedic competition I used the Pressure sensor that came with the kit to start and stop a servo. The code is in Spin but I can post it if it will help.
Sign In or Register to comment.