गुरुवार, 13 अप्रैल 2017

Sound Sensor in Arduino

click to enlarge

साउंड सेंसर - ताली बजाकर ऑन ऑफ़ स्वीच 

इस एक्सपेरिमेंट में हम आर्डूइनोसे एक साउंड सेंसर जोड़ कर देखेंगे. साउंड सेंसर के इस्तेमाल से आप अलग अलग तरह के एक्सपेरिमेंट कर सकते हैं. यहाँ पर हम ताली या चुटकी बजाने की आवाज से एक एलईडी को ऑन और ऑफ़ करेंगे.

यहाँ पर इस्तेमाल किया गया सेन्सर मेरे आर्डूइनोके किट के साथ आया है. आपके किट में इस तरह का सेन्सर अगर नहीं आया हो तो  150 रूपए में यह सेन्सर आप अमॅझॉन पर खरीद सकते हैं. इसका लिंक मैंने नीचे Components में दिया है.

इस सेंसर को चार पिन हैं. इसमें आउटपुट के दो पिन हैं.  AO और DO. याने अँनालॉग आउटपुट और डिजिटल आउटपुट. इस  एक्सपेरिमेंट के लिए हम डिजिटल आउटपुट (DO) का इस्तेमाल करेंगे. अँनालॉग आउटपुट का इस्तेमाल हम किसी अन्य एक्सपेरिमेंट में करेंगे.

Components

  • Arduino Uno's board with USB cable
  • one Breadboard small
  • one Sound Sensor - buy it now खरीदें 
  • one LED
  • one Resistor 220 Ohms
  • Jumper wires (Male-Male and Male - Female)
  • 9 V battery with holder
इस एक्सपेरिमेंट में इस्तेमाल होनेवाली चीजें आपको आर्डूइनो उनो के किसी भी स्टार्टर किट में मिल जाएँगी. अगर आपने कोई किट नहीं ख़रीदा हो तो आप उसे इस पन्ने के दाहिने ओर दिए हुए अमॅझॉन के लिंक पर खरीद सकते हैं.

Prerequisite


इस एक्सपेरिमेंट के लिए आर्डूइनो के प्रोग्रामिंग सॉफ्टवेअर की जरूरत पड़ेगी. आपको उसे कॉम्प्युटरपर इंस्टॉल करना होगा. आप उसे इस लिंक से डाउनलोड कर सकते हैं.

जब आप इस लिंक को खोलेंगे तो आपको अपने कम्प्यूटर के हिसाब से डाऊनलोड के लिंक दिखेंगे. डाऊनलोड करने से पहले आपको एक डोनेशन का पेज दिखाई देगा. लेकिन आपको यहाँ पर पैसे देना अनिवार्य नहीं है. क्योंकि यह डोनेशन डॉलर्स में है इसलिए आप चाह कर भी नहीं दे पाएंगे. तो उस पेज के नीचे "Just Download" लिखा होगा उसपर क्लिक करने पर डाऊनलोड शुरू हो जाएगा.


नीचे इस एक्सपेरिमेंट का सर्किट / वायरिंग दिखाया हुआ है.  

click to enlarge

(आप इस चित्र पर क्लिक करके उसे बड़ा कर के देख सकते हैं.)

You can see the wiring for this experiment above. We are using the 5V and Gnd pins on the Arduino to connect to one of the Power lanes and Ground lanes on the breadboard as we need to supply power to two components. The Arduino ports we will be using as Input and Output are 10 and 12. The wire colors used in the above diagram are as follows. Red for Power supply, Black for Ground, Yellow for Signal.

  • The DO - digital output of the sound sensor will go to Arduino pin 10
  • The Arduino pin 12 will be connected to positive/ anode of the LED
  • The 220 ohn resistor is connected to negative/ cathode of the LED
  • Other end of the LED is connected to Ground lane 
  • The + pin of the Sound sensor is connected to the power lane on the breadboard, and Gnd pin is connected to the Gnd lane. There is the fourth pin of this sensor (A0) which is not connected anywhere. In case you are using a three pin sensor, connect the wires as per the markings. Probably the middle pin the signal/ output pin.

Calibrating the Sound Sensor


click to enlarge

इस सेन्सर का इस्तेमाल करने से पहले उसे कॅलीबरेट करना जरूरी है. यानि के आपको उसकी सेन्सिटीविटी अॅडजस्ट करनी पड़ेगी.

इसके लिए इस सेन्सर को पॉवर देने के लिए मेल टू फिमेल जंपर वायर से   आर्डूइनो के  +5V और  Gnd ग्राउंड से जोड़ना पडेगा.

इस सेन्सर पर  LED1 और LED2  ऐसे लिखा हुआ दिखाई देगा. पॉवर सप्लाय देने पर  आपको एक लाल और एक हरे रंग की एलईडी जलती हुई दिखाई देगी.

इस सेन्सर पर नीचे रंग का एक पोटेन्शिओमीटर है. उसपर एक नॉब भी है. इस नॉब को स्क्रू ड्राईवर से घुमाया जा सकता है.  इसके पहले किये गए एक्सपेरिमेंट में हमने एक बड़ा   पोटेन्शिओमीटर इस्तेमाल किया था. उसका नॉब घुमाकर हम  व्होल्टेज को कम या जादा कर सकते थे. वह नॉब एक ही टर्न में अपने मिनिमम और मॅक्सिमम पोजीशन में जाता था. लेकिन यहाँ पर जो नॉब है वह अलग है. आपको यह नॉब एक ही दिशा में कई कई बार घुमाना पडेगा..



click to enlarge

इस नॉब को घुमाते समय मेरे मन में भी यही शंका थी. याने अगर यह नॉब सिंगल टर्न  होता और मैं उसे एक ही दिशा में कई बार घूमता तो वह खराब हो जाता. लेकिन कुछ समय बाद मेरे समझ में आया की यह  सिंगल टर्न नॉब नहीं है

नीले रंग के  पोटेन्शिओमीटर के पास वाली एलईडी  LED2 जलने पर हरे रंग की दिखती है.  यह अगर जल रही है तो स्क्रू ड्राईवर से  नॉब को लेफ्ट में घुमाएं. ( याने अगर आपने यह सेन्सर पिन नीचे की और कर के पकड़ा है तो ) इस नॉब को हरी एलईडी  बंद होने तक लेफ्ट को घुमाते रहिये.

यह आपका  कट ऑफ पॉइंट होगा. अब सेंसर के माइक के पास चुटकी या ताली बजने पर हरी  एलईडी कुछ क्षणों के लिए जलती हुई दिखेगी . हरी एलईडी ना जल उठती हो तो  स्क्रू ड्राईवर से  नॉब को हलकासा राईट को घुमाइए और फिर चुटकी बजाकर देखिये.  उस आवाज से  एलईडी हल्की सी जल उठती हो तो अब सेन्सर आगे के एक्सपेरिमेंट के लिए तैयार है.

अब इस एक्सपेरिमेंट का सर्किट डायग्राम देखकर साउंड सेंसर को ब्रेडबोर्ड पर जोड़कर  ऊपर के सेक्शन में बताये हुए तरीके से सारे कोम्पोनन्ट्स जोड़ लीजिये.

अब आर्डूइनो के बोर्ड को  कॉम्प्युटर से जोड़कर कॉम्प्युटर पर आर्डूइनो का सॉफ्टवेअर खोलिए. नीचे दिखाया गया  प्रोग्राम पहले आप अपने कॉम्प्युटर पर  डाउनलोड कर लीजिये, और फिर उसे  आर्डूइनो के  सॉफ्टवेअर में खोलकर उसे आर्डूइनो के बोर्ड पर अपलोड कीजिये.

Code

click to enlarge

The above image gives you an idea of the code used for this experiment. You can download the code from this link. You can read it as a Google Doc on this link.

It is a Toggle code used in the previous experiment. Where we learnt about bouncing. It is the same Toggle code, without the need for debouncing code. The mechanical switches tend to bounce, but in this case, out input comes from the Sound Sensor, which is activated by the sound you make near the sensor. Hence there is no bouncing issue here.

The code is easy to understand. We are creating two integer variables ledPin and sensorPin and assigning them the port numbers that we will be using on Arduino. You can avoid creating these variables and write the input and out pin numbers directly in the program, that will make the program shorter and more comprehensible. But creating additional variables and assigning them the port numbers will be convenient when you need to change the port numbers. It is easier to change the number once in the variable, instead of having to type it several places in the code.

There are only two functions in the Arduino code. Setup and loop. The code is simple enough to understand. It checks the state of the input and toggles the state of the output.

अब सेंसर के माइक के पास ताली या चुटकी बजाकर देखिये. एक आवाज से एलईडी जल उठेगी और दोबारा आवाज करने पर वह बंद हो जाएगी. इस तरह से हम  साउंड सेंसर का इस्तेमाल किसी भी इलेक्ट्रिक इक्विपमेंट को चालू या बंद करने के लिए कर सकते हैं.




Summary

We saw how to use a Sound Sensor with Arduino's board. you can control the power supply to any electronic component/ equipment with this sound toggle setup. Here we have used low powered components. You can use a relay connected to the output to handle electric appliances needing higher power. We learn that in another article.

We have used only the Digital output from the Sensor. We will also see how to use the Analog output from the Sensor in forthcoming articles.




आगे पढ़िए - साउंड सेंसर के एनालॉग आउटपुट को कैसे नापा जाए

कोई टिप्पणी नहीं:

एक टिप्पणी भेजें

टिप्पणी: केवल इस ब्लॉग का सदस्य टिप्पणी भेज सकता है.