User Tools

Site Tools


amc2021:groupl:code:sound_detection

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
amc2021:groupl:code:sound_detection [2021/09/03 01:44] – created kshama001amc2021:groupl:code:sound_detection [2023/01/05 14:38] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ===== For noise disturbance detection in the environment ===== ===== For noise disturbance detection in the environment =====
  
 +This code monitors the sound intensity using an LM393 sensor connected to an Arduino UNO board.
 +The used sensor has only a digital output. Therefore, the number of times the sensor detects a sound is summed up over a sampling time called "SAMPLE_TIME". Then the sum called "sampleBufferValue" is printed on a Serial Monitor and visualized with the Serial Plotter. 
 +Additionally, the code allows communication with a LED to provide a visual alarm if the "sampleBufferValue" surpasses a preset Threshold.
 +Regarding the digital outputs, 0 means silence and 1 means noise.
  
-<code> +Detailed explanation is given in the [[amc2021:groupl:video:start|video tutorial]]
-/* This code is meant to monitor the sound intensity using LM393 sensor connected to Arduino UNO board. +
-//The used sensor has only a digital output. Therefore, the number of times the sensor detects a sound is summed up over a sampling time called "SAMPLE_TIME".  +
-//Then the sum called "sampleBufferValue" is printed on a Serial Monitor (laptop), and visualized with the Serial Plotter.  +
-// The code allows to communicate  with a LED in order to provide a visual alarm if the "sampleBufferValue" surpasses a preset Threshold  "Threshold" */+
  
-// 0 means silence and 1 means noise 
  
- const int OUT_PIN = 12;          // The OUTPUT of the sound sensor is connected to the digital pin D12 of the Arduino  +<file c++ Sound_Detection.ino> 
- const int SAMPLE_TIME = 10;      // The sampling time in milliseconds,  can be set differently if required + 
- const int Threshold = 90;       // Threshold on decibel value for LED switching ON, the value has been optimized with respect to the used sampling time (900 cumulative digital counts ≈ 90 dB from "Schall")+ const int OUT_PIN = 12;    // The OUTPUT of the sound sensor is connected to the digital pin D12 of the Arduino  
 + const int SAMPLE_TIME = 10;// The sampling time in milliseconds,  can be set differently if required 
 + const int Threshold = 90;  // Threshold on decibel value for LED switching ON, the value has been optimized with respect to  
 +//the used sampling time (900 cumulative digital counts ≈ 90 dB from "Schall")
  
  unsigned long millisCurrent;     // current time  unsigned long millisCurrent;     // current time
Line 38: Line 40:
   sampleBufferValue++;                       //increments the sum variable by 1   sampleBufferValue++;                       //increments the sum variable by 1
   }   }
-   if (millisElapsed > SAMPLE_TIME) {       //if the elapsed time surpasses the sampling time, print the sampleBufferValue and test threshold for alarm+   if (millisElapsed > SAMPLE_TIME) {       //if the elapsed time surpasses the sampling time,  
 +   //print the sampleBufferValue and test threshold for alarm
        
-   dB = 0.0666 *(sampleBufferValue) + 30.223; //linear regression to calculate the decibel value based of the rough calibration of the sensor response +   dB = 0.0666 *(sampleBufferValue) + 30.223; //linear regression to calculate the decibel value based of  
 +   //the rough calibration of the sensor response 
   Serial.println(dB);                        // print decibel values on the Serial Monitor    Serial.println(dB);                        // print decibel values on the Serial Monitor 
   Serial.print("dB");                        // print sound unit decibel   Serial.print("dB");                        // print sound unit decibel
Line 59: Line 63:
 } }
  
-</code>+</file> 
 +[[amc2021:groupl:report:start|Back to report]]
amc2021/groupl/code/sound_detection.1630626263.txt.gz · Last modified: 2023/01/05 14:38 (external edit)