amc2021:code:start
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| amc2021:code:start [2021/09/02 22:47] โ [**For noise disturbance detection in the environment**] leen001 | amc2021:code:start [2021/09/03 18:48] (current) โ removed kshama001 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ======Arduino Code====== | ||
| - | ===== For Carbon Dioxide detection in air ===== | ||
| - | |||
| - | |||
| - | < | ||
| - | /* | ||
| - | // This code communicates with the MQ135 air quality sensor. The sensor is supposed to preheat for 2 mins before taking readings | ||
| - | // Once the code runs, it prints out the concentration of detected gases in ppm on a serial monitor and a LCD 20 x 4 screen | ||
| - | //An alarm system (LED light) is also set to print out messages saying if the air is of a good quality relying on a predefined threshold value | ||
| - | */ | ||
| - | // digital output value is converted to ppm value using CO2 gas as parameter | ||
| - | #include " | ||
| - | #include < | ||
| - | #include < | ||
| - | |||
| - | LiquidCrystal_I2C lcd(0x27, | ||
| - | |||
| - | #define led 9 //led on pin 9 | ||
| - | const int gas_pin = A0; //analog feed from MQ135 | ||
| - | MQ135 gasSensor = MQ135(gas_pin); | ||
| - | |||
| - | void setup(){ | ||
| - | |||
| - | lcd.init(); | ||
| - | lcd.begin(16, | ||
| - | lcd.backlight(); | ||
| - | lcd.clear(); | ||
| - | lcd.setCursor(4, | ||
| - | lcd.print(" | ||
| - | |||
| - | pinMode(gas_pin, | ||
| - | pinMode(led, | ||
| - | | ||
| - | Serial.begin(9600); | ||
| - | } | ||
| - | |||
| - | void loop(){ | ||
| - | float ppm = gasSensor.getPPM(); | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | | ||
| - | digitalWrite(led, | ||
| - | lcd.setCursor(2, | ||
| - | lcd.print(" | ||
| - | } | ||
| - | | ||
| - | digitalWrite(led, | ||
| - | lcd.setCursor(1, | ||
| - | lcd.print ("AQ Level Good" | ||
| - | } | ||
| - | |||
| - | } | ||
| - | |||
| - | </ | ||
| - | |||
| - | ===== **For noise disturbance detection in the environment** ===== | ||
| - | |||
| - | |||
| - | < | ||
| - | /* 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 " | ||
| - | //Then the sum called " | ||
| - | // The code allows to communicate | ||
| - | |||
| - | // 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 | ||
| - | const int SAMPLE_TIME = 10; // The sampling time in milliseconds, | ||
| - | const int Threshold = 900; // Threshold on cumulative counts for LED switching ON, the value has been optimized with respect to the used sampling time of 10 ms here. (900 digital outputs โ 90 dB from " | ||
| - | |||
| - | | ||
| - | | ||
| - | | ||
| - | |||
| - | int sampleBufferValue = 0; // initiate the sum of digital outputs over the sampling time | ||
| - | int led = 8; // LED on pin 4 of Arduino | ||
| - | |||
| - | void setup() { | ||
| - | |||
| - | Serial.begin(9600); | ||
| - | pinMode(led, | ||
| - | |||
| - | } | ||
| - | |||
| - | void loop() { | ||
| - | |||
| - | millisCurrent = millis(); // the current time is assigned to the dedicated variable | ||
| - | millisElapsed = millisCurrent - millisLast; // the elapsed time is updated | ||
| - | | ||
| - | if(digitalRead(OUT_PIN) == HIGH){ // HIGH means noise | ||
| - | |||
| - | sampleBufferValue++; | ||
| - | } | ||
| - | if (millisElapsed > SAMPLE_TIME) { // if the elapsed time surpasses the sampling time, print the sampleBufferValue and test the threshold for the alarm | ||
| - | |||
| - | dB = 0.0666 *(sampleBufferValue) + 30.223; //linear regression to calculate the decibel value based of the rough clibration of the sensor response | ||
| - | Serial.println(dB); | ||
| - | | ||
| - | if (sampleBufferValue > Threshold) { // test if the threshold is surpassed | ||
| - | | ||
| - | digitalWrite(led, | ||
| - | delay(2); | ||
| - | digitalWrite(led, | ||
| - | delay(1); | ||
| - | } | ||
| - | | ||
| - | digitalWrite(led, | ||
| - | sampleBufferValue = 0; // re-initialization of the sampleBufferValue variable for the new sampling time | ||
| - | millisLast = millisCurrent; | ||
| - | } | ||
| - | } | ||
| - | |||
| - | </ | ||
amc2021/code/start.1630615629.txt.gz ยท Last modified: 2023/01/05 14:38 (external edit)