hIOTron
Created January 8, 2020 © GPL3+

Arduino Whistle Detector Switch using Sound Sensor Module

In this project, we will see how to detect Whistle sound and once it is detected we will toggle the AC lamp via a relay.

Arduino Whistle Detector Switch using Sound Sensor Module

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Sound sensor module
×1
Relay Module (Generic)
×1
AC Lamp
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Run a Code

Arduino
#include <FreqMeasure.h>//https://github.com/PaulStoffregen/FreqMeasure

void setup() {
  Serial.begin(9600);
  FreqMeasure.begin(); //Measures on pin 8 by default 
  pinMode(LED_BUILTIN, OUTPUT);
}

double sum=0;
int count=0;
bool state = false; 
float frequency;
int continuity =0;

void loop() {
  if (FreqMeasure.available()) {
    // average several reading together
    sum = sum + FreqMeasure.read();
    count = count + 1;
    if (count > 100) {
      frequency = FreqMeasure.countToFrequency(sum / count);
      Serial.println(frequency); 
      sum = 0;
      count = 0;
    }
  }

    if (frequency>1800 && frequency<2000)
    { continuity++; Serial.print("Continuity -> "); Serial.println(continuity); frequency=0;}

    if (continuity >=3 && state==false)
      {state = true; continuity=0; Serial.println("Light Turned ON"); delay(1000);}

    if (continuity >=3 && state==true)
      {state = false; continuity=0; Serial.println("Light Turned OFF"); delay(1000);}

    digitalWrite(LED_BUILTIN, state);
}

Credits

hIOTron

hIOTron

78 projects • 2 followers
hIOTron is an internet of things based company that offers an IoT Platform, products, IoT Solutions, and IoT Training.

Comments