Introduction: Whistle Detector Light Switches

Hello Friends WELCOME TO Instructable
Here you will get to learn many things like robotics, electronics and much more
Today, we will make light from Whistle here, you can connect with it in many electronics appliances.

Step 1: You Need Some Components

1. Arduino Uno
2. SOUND Sensor
3.Relay Module
4.Light bulb
5. JUMPER Wires (Male to Male)
6. Arduino Cable
7. Power adapter

Step 2: What Is Arduino ¿

Arduino is an open-source electronics platform based on easy-to-use hardware and software. Arduino boards are able to read inputs - light on a sensor, a finger on a button, or a Twitter message - and turn it into an output - activating a motor, turning on an LED, publishing something online.

Step 3: What Is Sound Sensor?

The sound sensor is one type of module used to notice the sound. Generally, this module is used to detect the intensity of sound. ... This sensor employs a microphone to provide input to buffer, peak detector and an amplifier. This sensor notices a sound, & processes an o/p voltage signal to a microcontroller.

sensitivity can be controlled by varying the potentiometer on the module.

Step 4: Relay Module?

Relay Module. A relay is basically a switch which is operated by an electromagnet. The electromagnet requires a small voltage to get activated which we will give from the Arduino and once it is activated, it will pull the contact to make the high voltage circuit.

Step 5: Measuring Audio Frequency

sound sensor module will convert the sound waves in the atmosphere into square waves who’s frequency will be equal to the frequency of the sound waves. So by measuring the frequency of the square wave we can find the frequency of the sound signals in the atmosphere.

Step 6: Measuring Frequency With Arduino

Download the frequency measure library

https://github.com/PaulStoffregen/FreqMeasure/archive/master.zip

link will download a zip file, you can then add this zip file to your Arduino IDE by following the path Sketch -> Include Library -> Add .ZIP Library.

Note: Using the library will disable the analogWrite functionality on pin 9 and 10 on UNO since the timer will be occupied by this library. Also these pins will change if other boards are used....

Step 7: Programming Your Arduino for Detecting Whistle

#include //https://github.com/PaulStoffregen/FreqMeasure

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;
}
}




You can use the Serial.println() function here to check the value of the frequency for your whistle. In my case the value received was from 1800Hz to 2000Hz. The whistle frequency of most people will fall in this particular range. But even other sounds like music or voice might fall under

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

Step 8: Arduino Whistle Detector Working

hardware are ready we can start testing it. Make sure the connections are correct and power up the module. Open the serial monitor and start whistling, you can notice the value of continuity

Step 9: Programming

#include //https://github.com/PaulStoffregen/FreqMeasure

void setup() {
Serial.begin(9600);
FreqMeasure.begin(); // 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>2200 && frequency<2500)
{ 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);
}