Quickdraw Timer

Hello All, I am just starting off with this fun little project and trying to piece together the different aspects of the sketch

the project aims to measure a quickdraw ie you turn on the device, the LCD has a welcome note, you press a button and a tone sounds, you draw your gun and shoot, the noise is detected and the duration between the sound starting and the shot is displayed in milliseconds, you press the button, it resets to the welcome screen until you press the button again and the tone sounds etc

so I am learning on the fly here and got this far with the sketch

//Arduino Sound Detection Sensor Module
// Declare the pins for the Button and the LED

int buttonPin = 12;
int LED = 13;
int soundDetectedPin = 3; // Use Pin 10 as our Input
int soundDetectedVal = HIGH; // This is where we record our Sound Measurement
boolean bAlarm = false;
unsigned long lastSoundDetectTime; // Record the time that we measured a sound
int soundAlarmTime = 500; // Number of milli seconds to keep the sound alarm high

// Buzzer - Version: Latest
#include <Buzzer.h>
//Sample using LiquidCrystal library
#include <LiquidCrystal.h>


// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
Buzzer buzzer(11, 13);



void setup()
{
  lcd.begin(16, 2);              // start the library
  lcd.setCursor(0, 0);
  lcd.print("Merv's Digital "); // print a simple message
  lcd.setCursor(0, 1);
  lcd.print("Quickraw Device"); // print a simple message
  // Define pin #12 as input and activate the internal pull-up resistor
  pinMode(buttonPin, INPUT_PULLUP);
  // Define pin #13 as output, for the LED
  pinMode(LED, OUTPUT);
  Serial.begin(9600);
  pinMode (soundDetectedPin, INPUT) ; // input from the Sound Detection Module

}

void loop() {
  // Read the value of the input. It can either be 1 or 0
  int buttonValue = digitalRead(buttonPin);
  if (buttonValue == LOW) {
    // If button pushed, turn LED on
    digitalWrite(LED, HIGH);
    soundDetectedVal = digitalRead (soundDetectedPin) ; // read the sound alarm time
    
/*    Serial.println(lastSoundDetectTime);
*/
    if (soundDetectedVal == LOW) // If we hear a sound
    {

      lastSoundDetectTime = millis(); // record the time of the sound alarm
      // The following is so you don't scroll on the output screen
      if (!bAlarm) {
        Serial.println("Bang");
        lcd.setCursor(0, 0);
        lcd.print("BANG!           "); // print a simple message
        lcd.setCursor(0, 1);
        lcd.print("                "); // print a simple message
        
        delay(5000);
        
        lcd.setCursor(0, 0);
        lcd.print("Merv's Digital "); // print a simple message
        lcd.setCursor(0, 1);
        lcd.print("Quickraw Device"); // print a simple message

        bAlarm = true;

      }
    }
  }
}

so I get the welcome screen and if I hold the button it listens for a loud sound, when detected it prints "bang" on the serial monitor and the LCD and then returns to the welcome screen but it will not run a second time when pressing the button and I need it to run one one press of the button not holding the button down

I cant see why this doesnt loop, I expect its obvious but any help would be appreciated

I will be adding the buzzer and timer after I have go this part solved

thanks

Dan

bAlarm is set to an initial values of !false.

So when soundDetected happens bAlarm is already !false

if (soundDetectedVal == LOW) // If we hear a sound
    {

      lastSoundDetectTime = millis(); // record the time of the sound alarm
      // The following is so you don't scroll on the output screen
      if (!bAlarm) {

afterwards bAlarm = true; takes away the !false so when soundDetected happens again bAlarm is !false because there is not a code to set bAlarm to !false. That's one of several 'things' that I can see.

Idahowalker:
again bAlarm is !false because there is not a code to set bAlarm to !false. That's on of several 'things' that I can see.

As Idahowalker said you need to set bAlarm back to false at some point.

If you want this process to happen after the button is pressed but not holding it down you need to detect a HIGH to LOW transition on the button.

Also, what device are you using to detect the sound?

thanks Idahowalker I will get my head around this, test changes and report back

ToddL1962 thanks for your reply, I will research the high-low transition, I have seen this before but not used it. I am using a Sound Sensor Detection Module LM393 Chip Electret Microphone from here

it seems fit for purpose at the moment

DanO I was thinking you may need a pull up for the sound sensor input as well.

ToddL1962:
DanO I was thinking you may need a pull up for the sound sensor input as well.

really? it seems to be working OK

Dan0:
really? it seems to be working OK

Things always seem to work OK until they don't. Does the device have an open collector / drain output? If so, then you need an internal or external pull-up resistor.

ToddL1962:
DanO I was thinking you may need a pull up for the sound sensor input as well.

Banggood site does not completely load on my computer so I could not read all of the specs. It did state that "Output valid signal is low" which makes me think it is open collector/drain.

ToddL1962:
Banggood site does not completely load on my computer so I could not read all of the specs. It did state that "Output valid signal is low" which makes me think it is open collector/drain.

yes that is all it says

Sound Detection Sensor Module LM393 Chip Electret Microphone For

Features:

The product boast of output signal instruction.
Single-channel signal output.
Output valid signal is low and the light will be bright.

Specification:

Weight: 4g
Size: 3.1 x 1.6 x 0.8cm
Operating current pressure: 4V - 6V

works fine