amc2021:code:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
amc2021:code:start [2021/09/03 01:01] โ [For Carbon Dioxide detection in air] kshama001 | 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 24 hours before taking readings. | ||
- | Once the code runs, it prints out the concentration of detected gases in ppm on a serial monitor and the results are displayed on an LCD screen | ||
- | An alarm system (LED light) is also set to glow if the CO< | ||
- | |||
- | |||
- | < | ||
- | | ||
- | #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 = 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 " | ||
- | |||
- | | ||
- | | ||
- | | ||
- | |||
- | int sampleBufferValue = 0; // initiate the sum of digital outputs over the sampling time | ||
- | int led = 8; // LED on pin 4 of Arduino | ||
- | int dB = 0; // | ||
- | |||
- | void setup() { | ||
- | |||
- | Serial.begin(9600); | ||
- | pinMode(led, | ||
- | |||
- | } | ||
- | |||
- | void loop() { | ||
- | |||
- | millisCurrent = millis(); | ||
- | millisElapsed = millisCurrent - millisLast; //the elapsed time is updated | ||
- | | ||
- | if(digitalRead(OUT_PIN) == HIGH){ | ||
- | |||
- | sampleBufferValue++; | ||
- | } | ||
- | 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 | ||
- | Serial.println(dB); | ||
- | Serial.print(" | ||
- | | ||
- | | ||
- | 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.1630623663.txt.gz ยท Last modified: 2023/01/05 14:38 (external edit)