I’m playing a standard seatbelt chime of 2kHz into a microphone, then into a LM321 op amp with a gain of 10. Then the op amp output into an Arduino Uno with an LCD display that comes with an Arduino Starter Kit and an LED indicator.
I’m trying to get the Arduino to recognise whether the seatbelt chime is happening and if it is the correct sound. If it is incorrect, I want it to display how many times it fails on the LCD display.
As a beginner, this is how far I’ve gotten:
#include <LiquidCrystal.h>
int greenLED = 8;
int mic = A0;
int micstate = 0;
int counter = 0;
int rs = 12;
int en = 11;
int d4 = 5;
int d5 = 4;
int d6 = 3;
int d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup() {
// put your setup code here, to run once:
pinMode(greenLED, OUTPUT);
pinMode(mic, INPUT);
Serial.begin(115200); //9600
lcd.begin(16, 2);
lcd.print("Hello!");
lcd.setCursor(0, 1);
delay(2000);
lcd.clear();
lcd.print("Number of Fails:");
}
void loop() {
// put your main code here, to run repeatedly:
lcd.setCursor(0, 1);
lcd.print(counter);
micstate = analogRead(mic);
//greenLED turns on when mic reading is between 400 and 500
if (micstate <= 500 && micstate <= 400) {
digitalWrite(greenLED, HIGH);
Serial.println(micstate);
}
else digitalWrite(greenLED, LOW);
Serial.print("FAIL: ");
Serial.println(micstate);
counter = counter + 1;
lcd.print(counter);
}
It works at this stage but I don’t want the time between the “beep” of the chime to show as a fail. I’d like the Arduino to recognise that “beep____beep____beep____beep____beep” is a pass and “beep_beep_beep_beep_beep” is a fail.
If it helps, more seatbelt chime specs:
Initial duty cycle = 50%
ON time = 500ms
Base time = 1000ms
Duration = max of 90 seconds for each event
Number of base times = 90
Any help would be greatly appreciated!