Auto Shut-off safety system for stove
Dependencies: mbed Motordriver DHT
Diff: main.cpp
- Revision:
- 1:b63b3fcf72d1
- Parent:
- 0:c8b31227d874
- Child:
- 2:29fb4e252925
diff -r c8b31227d874 -r b63b3fcf72d1 main.cpp --- a/main.cpp Tue Feb 26 18:40:51 2019 +0000 +++ b/main.cpp Fri Mar 08 17:32:33 2019 +0000 @@ -1,21 +1,81 @@ -#include "mbed.h" +#include "mbed.h" +#include "DHT.h" +void motor(); +DHT sensor(D4, DHT11); Serial pc(USBTX, USBRX); // tx, rx -DigitalOut led(LED1); -DigitalIn pir(D2); //Connect it to + +DigitalIn pir(D4); +DigitalIn pir2(D2); //Connect it to Timer timer; - -int main() -{ - while(1) { - if(!pir){ - led = 0; - pc.printf("Nothing Detected\r\n"); - wait(1); - } - else { - led=1; - pc.printf("Motion Detected\r\n"); + +int main() { + int error = 0; + float f = 0.0f;//, k = 0.0f, dp = 0.0f, dpf = 0.0f, h = 0.0f, c = 0.0f; + while(1) { + wait(2.0f); + error = sensor.readData(); + if (0 == error) + { + f = sensor.ReadTemperature(FARENHEIT); + printf("\r\nTemperature in Farenheit %4.2f\n", f); + } + else + { + printf("\r\Error: %d\n", error); + } + if(f > 80) + { + + if(!pir && !pir2) + { + pc.printf("\r\nNothing Detected\r\n"); + pc.printf("\r\nTurn off stove\r\n"); + motor(); + wait(1); + } + else if(pir && !pir2) + { + + pc.printf("\r\nKids/Cat Detected\r\n"); + pc.printf("\r\nTurn off stove\r\n"); + motor(); + wait(1); + } + else + { + + pc.printf("\r\nAdult Detected\r\n"); wait(1); } } -} \ No newline at end of file + else + { + pc.printf("\r\nStove not turned on\r\n"); + } + } +} + +void motor(){ +PwmOut PWM1(A5); + +//int main() +//{ +PWM1.period_ms(100); +int x; +x=20; +while(1) +{ +PWM1.pulsewidth_ms(x); +//x=x+1; + +wait(0.1); +//if(x==10) + +x=0; + +} +} + + + + \ No newline at end of file