amc2021:code:start
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
amc2021:code:start [2021/09/02 12:12] – created kshama001 | amc2021:code:start [2021/09/03 18:48] (current) – removed kshama001 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Arduino Code====== | ||
- | **For CO < | ||
- | |||
- | < | ||
- | #include " | ||
- | #include < | ||
- | #include < | ||
- | |||
- | LiquidCrystal_I2C lcd(0x27, | ||
- | |||
- | #define led 9 //led on pin 9 | ||
- | |||
- | const int gas_pin = A0; | ||
- | 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 allows to follow the sound intensity using LM393 sensor: The number of times the sensor has detected a sound is summed up over a sampling time | ||
- | SAMPLE_TIME. Then the sum (sampleBufferValue) is printed on serial monitor | ||
- | A let is used to give a visual alarm if the sampleBufferValue | ||
- | surpasses a given 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 | ||
- | const int SAMPLE_TIME = 10; // The sampling time | ||
- | const int Threshold = 100; // Threshold on cumulative counts for LED switching ON | ||
- | unsigned long millisCurrent; | ||
- | unsigned long millisLast = 0; | ||
- | unsigned long millisElapsed = 0; | ||
- | int sampleBufferValue = 0; | ||
- | |||
- | int led = 8; // LED is connected to the digital pin number 4 of the Arduino | ||
- | |||
- | void setup() { | ||
- | // put your setup code here, to run once: | ||
- | Serial.begin(9600); | ||
- | pinMode(led, | ||
- | |||
- | } | ||
- | |||
- | void loop() { // put your main code here, to run repeatedly: | ||
- | |||
- | millisCurrent = millis(); | ||
- | millisElapsed = millisCurrent - millisLast; | ||
- | if(digitalRead(OUT_PIN) == HIGH){ // HIGH means noise | ||
- | |||
- | sampleBufferValue++; | ||
- | } | ||
- | if (millisElapsed > SAMPLE_TIME) { //here we will print the counts and test the threshold | ||
- | Serial.println(sampleBufferValue); | ||
- | if (sampleBufferValue > Threshold) { | ||
- | digitalWrite(led, | ||
- | delay(2); | ||
- | digitalWrite(led, | ||
- | delay(1); | ||
- | } | ||
- | digitalWrite(led, | ||
- | sampleBufferValue = 0; | ||
- | millisLast = millisCurrent; | ||
- | } | ||
- | } | ||
- | |||
- | </ |
amc2021/code/start.1630577536.txt.gz · Last modified: 2023/01/05 14:38 (external edit)