Using 5 sensors(luminance, motion, tempurature, humanity, air_quality) to control

Dependencies:   Air_Quality DHT mbed-src

Files at this revision

API Documentation at this revision

Comitter:
ysy00700
Date:
Tue Aug 11 14:43:36 2015 +0000
Parent:
0:d0e594c3fb6c
Commit message:
All of Sensor control

Changed in this revision

Air_Quality.lib Show annotated file Show diff for this revision Revisions of this file
DHT.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-src.lib Show annotated file Show diff for this revision Revisions of this file
diff -r d0e594c3fb6c -r f9339d95123d Air_Quality.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Air_Quality.lib	Tue Aug 11 14:43:36 2015 +0000
@@ -0,0 +1,1 @@
+https://developer.mbed.org/users/ysy00700/code/Air_Quality/#7653022b71cb
diff -r d0e594c3fb6c -r f9339d95123d DHT.lib
--- a/DHT.lib	Tue Jul 21 08:17:32 2015 +0000
+++ b/DHT.lib	Tue Aug 11 14:43:36 2015 +0000
@@ -1,1 +1,1 @@
-DHT#df9b4e185588
+https://developer.mbed.org/users/ysy00700/code/DHT/#df9b4e185588
diff -r d0e594c3fb6c -r f9339d95123d main.cpp
--- a/main.cpp	Tue Jul 21 08:17:32 2015 +0000
+++ b/main.cpp	Tue Aug 11 14:43:36 2015 +0000
@@ -1,7 +1,12 @@
 #include "mbed.h"
 #include "DHT.h"
+#include"Air_Quality.h"
 
-DHT sensor(A0, DHT11);
+AirQuality airqualitysensor;
+int current_quality = -1;
+PinName analogPin = A0;
+
+DHT sensor(D3, DHT11);
 InterruptIn motion(D2);
 AnalogIn luminance(A1);
 
@@ -11,6 +16,15 @@
 
 int motion_detected = 0;
 
+// Interrupt Handler
+void AirQualityInterrupt()
+{
+    AnalogIn sensor(analogPin);
+    airqualitysensor.last_vol = airqualitysensor.first_vol;
+    airqualitysensor.first_vol = sensor.read()*1000;
+    airqualitysensor.timer_index = 1;
+}
+
 void irq_handler(void)
 {
     motion_detected = 1;
@@ -22,19 +36,21 @@
     float hum = 0.0f;
     float cel = 0.0f;
     
+    airqualitysensor.init(analogPin, AirQualityInterrupt);
+    
     int cnt = 0;
     motion.rise(&irq_handler);
     
     while(1)
     {
-        wait(1);
+        wait(0.1);
         error = sensor.readData();
         
         if (0 == error) {
             hum = sensor.ReadHumidity();
             cel = sensor.ReadTemperature(CELCIUS);
-            printf(" Humidity : %4.2f\r\n", hum);
-            printf(" Temperature in Celcius : %2.2f\r\n", cel);
+            printf(" 1. Humidity : %4.2f\r\n\n", hum);
+            printf(" 2. Temperature in Celcius : %2.2f\r\n\n", cel);
             
             {
                 if (hum > 70) {  // if celcius is higher than 28, LED_RED on.
@@ -64,30 +80,55 @@
         if(motion_detected) {
             cnt++;
             motion_detected = 0;
-            led_R = 1;
+            /*led_R = 1;
             led_G = 1;
-            led_B = 1;
+            led_B = 1;*/
             
-            printf("Something move%d\r\n", cnt);
-            wait(1); 
+            printf("3. Something move%d\r\n\n", cnt);
+            wait(0.1); 
         }
         
         if(luminance.read()){
             
             if(0.1<=luminance.read()&&luminance.read()<=0.3){
-                RED=0; GREEN=0; BLUE=1;}   // yellow LED on
+                led_R=0; led_G=0; led_B=1;}   // yellow LED on
                 
             else{
-                RED=1; GREEN=1; BLUE=1;}   // led off
+                led_R=1; led_G=1; led_B=1;}   // led off
              
-            printf("Luminance: %f\r\n", luminance.read());    
-            wait(0.5f);
+            printf("4. Luminance: %f\r\n\n", luminance.read());    
+            wait(0.1);
         }
         else {
-            RED=0; GREEN=0; BLUE=0;    // white LED on 
-            printf("Luminance: %f\r\n", luminance.read());
-            wait(0.5f);         
+            led_R=0; led_G=0; led_B=0;    // white LED on 
+            printf("4. Luminance: %f\r\n\n", luminance.read());
+            wait(0.1);         
         }
+        //air quality sensor
+        current_quality=airqualitysensor.slope();
+        if (current_quality >= 0) { // if a valid data returned.
+            if (current_quality == 0){
+                printf("5. High pollution! Force signal active\n\r\n");
+               // led1 = 0;
+               // led2 = 1;
+            }
+            else if (current_quality == 1){
+                printf("5. High pollution!\n\r\n");
+              //  led1 = 0;
+               // led2 = 1;
+            }
+            else if (current_quality == 2){
+                printf("5. Low pollution!\n\n\r");
+              //  led1 = 0;
+              //  led2 = 1;
+            }
+            else if (current_quality == 3){
+                printf("5. Fresh air\n\r\n");
+              //  led1 = 1;
+              //  led2 = 0;
+            } 
+        }
+        
     }
 }
 /*
@@ -142,4 +183,38 @@
         }
                     
     }
+}*/
+/*
+InterruptIn motion(D2);
+
+DigitalOut RED(LED1, 1);
+DigitalOut GREEN(LED2, 1);
+DigitalOut BLUE(LED3, 1);
+
+int motion_detected = 0;
+
+void irq_handler(void)
+{
+    motion_detected = 1;
+}
+
+int main()
+{
+    int cnt = 0;
+    motion.rise(&irq_handler);
+    
+    while (true) {
+        
+        //grove motion sensor
+        if(motion_detected) {
+            cnt++;
+            motion_detected = 0;
+            RED = 0;
+            GREEN = 1;
+            BLUE = 1;
+            wait(1);
+            printf("Something move%d\r\n", cnt);
+        }
+                    
+    }
 }*/
\ No newline at end of file
diff -r d0e594c3fb6c -r f9339d95123d mbed-src.lib
--- a/mbed-src.lib	Tue Jul 21 08:17:32 2015 +0000
+++ b/mbed-src.lib	Tue Aug 11 14:43:36 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-src/#967d0d8b7aed
+http://mbed.org/users/mbed_official/code/mbed-src/#248b0d2dd755