acook4148
Published © GPL3+

Voice Activated Tripwire

Using the uxcell microphone module and the ultrasonic sensor, we created a voice-activated tripwire.

IntermediateShowcase (no instructions)162
Voice Activated Tripwire

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 221 ohm
Resistor 221 ohm
×1
Slide Switch
Slide Switch
×1
KY-038 uxcell microphone module
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Custom parts and enclosures

Arduino Case frame

Arduino Case walls

Schematics

Actual Circuit

Use both positive and negative buses.
Ultrasonic Trig Pin: 3
Ultrasonic Echo Pin: 2
Piezo Buzzer Pin: 2
Slide Switch Pin: 4
Mic Analog Read Pin: A0
LED Pin: 8

Fritzing Diagram

Code

Code

C/C++
int const trigPin = 3;
int const echoPin = 2;
int const buzzPin = 9;
int const decibelSensorPin = A0; //enter D0 uxcell pin here
int const LEDPin = 8;
int const buttonPin = 4;
int const threshold = 84; //enter threshold here
boolean activated = false; //if the tripwire is activated (actively listening)
boolean deactivate = false;
const char ALARM = 0;
const char STEALTH = 1;
int counter = 0;
char mode = 0;
bool triggered = false;
int decibel = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(buttonPin, INPUT);
  //pinMode(A0, INPUT);
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(buzzPin, OUTPUT);
  pinMode(LEDPin, OUTPUT);
  delay(100);
}
void loop()
{
  decibel = analogRead(decibelSensorPin);

  if (decibel >= threshold) {
      activated = true;
      digitalWrite(LEDPin, HIGH);
  }
  
  if (activated) { //if mic has been activated
    int duration, distance;
    digitalWrite(trigPin, HIGH);
    delay(1);
    digitalWrite(trigPin, LOW);  
    duration = pulseIn(echoPin, HIGH);
    distance = (duration*.0343)/2;
    
    if (triggered || (distance <= 35 && distance >= 0)) {
      triggered = true;
      Serial.println("test");
      
      if (digitalRead(buttonPin) == 0) { //alarm mode
        //Serial.println(decibel);
        tone(buzzPin,261);
        digitalWrite(LEDPin, HIGH);
        delay(500);
        digitalWrite(LEDPin, LOW);
      }
      else { //stealth mode
        //digitalWrite(LEDPin, LOW);
        Serial.println(decibel);
        //Serial.print(" ");
      } 
    } else {
      noTone(buzzPin);
    }

    delay(100);
    counter++;
  }
}

Credits

acook4148
1 project • 0 followers
Contact

Comments

Please log in or sign up to comment.