![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Home Security Device is designed based on FRDM K64f with DHT11, Ultrasonic Ranger, LCD RGB Light, Buzzer, button and Base Shield V2.
Dependencies: mbed Grove_LCD_RGB_Backlight RangeFinder DHT11
Revision 0:89a29cf8b779, committed 2019-03-04
- Comitter:
- qxy
- Date:
- Mon Mar 04 21:22:01 2019 +0000
- Commit message:
- Home Security Device is designed based on FRDM K64f with DHT11, Ultrasonic Ranger, button,buzzer LCD RGB Backlight and Base Shield V2.
Changed in this revision
diff -r 000000000000 -r 89a29cf8b779 DHT11.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DHT11.lib Mon Mar 04 21:22:01 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/fossum_13/code/DHT11/#5da6f6de3e42
diff -r 000000000000 -r 89a29cf8b779 Grove_LCD_RGB_Backlight.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Grove_LCD_RGB_Backlight.lib Mon Mar 04 21:22:01 2019 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/cmatz3/code/Grove_LCD_RGB_Backlight/#253885b1f364
diff -r 000000000000 -r 89a29cf8b779 RangeFinder.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RangeFinder.lib Mon Mar 04 21:22:01 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/NickRyder/code/RangeFinder/#cf496fb70317
diff -r 000000000000 -r 89a29cf8b779 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 04 21:22:01 2019 +0000 @@ -0,0 +1,94 @@ + +#include "mbed.h" +#include "Dht11.h" +#include "RangeFinder.h" +#include "Grove_LCD_RGB_Backlight.h" + +RangeFinder rf(D3, 10, 5800.0, 100000); +DigitalOut led(LED1); +DigitalOut buzzer(D2); +InterruptIn button(D6); +Serial pc(USBTX, USBRX); +Dht11 dhtSensor(D7); + +Grove_LCD_RGB_Backlight rgbLCD(I2C_SDA, I2C_SCL); + + +float temperature = 0.0f; +float humidity = 0.0f; + +int on = 1, off = 0; + +void flip() + { + buzzer = off; + } + +int main() +{ + led = 1; + float d; + + rgbLCD.setRGB(0xff, 0xff, 0xff); + char szBuff[10]; + + button.rise(&flip); // attach the address of the flip function to the rising edge + + + while(1) { + dhtSensor.read(); + temperature = dhtSensor.getCelsius(); + humidity = dhtSensor.getHumidity(); + + printf("Temp: %f, Hum: %f\n", temperature, humidity); + + rgbLCD.locate(0,0); + rgbLCD.print("T:"); + rgbLCD.locate(2,0); + sprintf(szBuff, "%2.1f", temperature); + rgbLCD.print(szBuff); + + rgbLCD.locate(8,0); + rgbLCD.print("H:"); + rgbLCD.locate(10,0); + sprintf(szBuff, "%2.1f", humidity); + rgbLCD.print(szBuff); + + if (temperature >= 25) + { + buzzer = on; + wait(5); + buzzer = off; + rgbLCD.locate(0,0); + rgbLCD.print("T:"); + rgbLCD.locate(2,0); + rgbLCD.print(is over 25); + } + + wait(1); + + + d = rf.read_m(); + if (d == -1.0) { + printf("Timeout Error.\n"); + } else if (d > 5.0) { + // Seeed's sensor has a maximum range of 4m, it returns + // something like 7m if the ultrasound pulse isn't reflected. + printf("No object within detection range.\n"); + rgbLCD.locate(0,1); + rgbLCD.print("No object"); + + } else { + printf("Detecting object within detection range.\n"); + rgbLCD.locate(0,1); + rgbLCD.print("Detected"); + printf("Distance = %f m.\n", d); + buzzer = on; + wait(5); + buzzer = off; + } + wait(0.5); + led = !led; + + } +} \ No newline at end of file
diff -r 000000000000 -r 89a29cf8b779 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 04 21:22:01 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file