Auto Shut-off safety system for stove

Dependencies:   mbed Motordriver DHT

Committer:
lwettel
Date:
Fri Mar 08 17:32:33 2019 +0000
Revision:
1:b63b3fcf72d1
Parent:
0:c8b31227d874
Child:
2:29fb4e252925
DHT Temperature sensor and 2 PIR motion sensors for Automatic shut off system for stoves

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lwettel 1:b63b3fcf72d1 1 #include "mbed.h"
lwettel 1:b63b3fcf72d1 2 #include "DHT.h"
lwettel 1:b63b3fcf72d1 3 void motor();
lwettel 1:b63b3fcf72d1 4 DHT sensor(D4, DHT11);
Niranjan_ravi 0:c8b31227d874 5 Serial pc(USBTX, USBRX); // tx, rx
lwettel 1:b63b3fcf72d1 6
lwettel 1:b63b3fcf72d1 7 DigitalIn pir(D4);
lwettel 1:b63b3fcf72d1 8 DigitalIn pir2(D2); //Connect it to
Niranjan_ravi 0:c8b31227d874 9 Timer timer;
lwettel 1:b63b3fcf72d1 10
lwettel 1:b63b3fcf72d1 11 int main() {
lwettel 1:b63b3fcf72d1 12 int error = 0;
lwettel 1:b63b3fcf72d1 13 float f = 0.0f;//, k = 0.0f, dp = 0.0f, dpf = 0.0f, h = 0.0f, c = 0.0f;
lwettel 1:b63b3fcf72d1 14 while(1) {
lwettel 1:b63b3fcf72d1 15 wait(2.0f);
lwettel 1:b63b3fcf72d1 16 error = sensor.readData();
lwettel 1:b63b3fcf72d1 17 if (0 == error)
lwettel 1:b63b3fcf72d1 18 {
lwettel 1:b63b3fcf72d1 19 f = sensor.ReadTemperature(FARENHEIT);
lwettel 1:b63b3fcf72d1 20 printf("\r\nTemperature in Farenheit %4.2f\n", f);
lwettel 1:b63b3fcf72d1 21 }
lwettel 1:b63b3fcf72d1 22 else
lwettel 1:b63b3fcf72d1 23 {
lwettel 1:b63b3fcf72d1 24 printf("\r\Error: %d\n", error);
lwettel 1:b63b3fcf72d1 25 }
lwettel 1:b63b3fcf72d1 26 if(f > 80)
lwettel 1:b63b3fcf72d1 27 {
lwettel 1:b63b3fcf72d1 28
lwettel 1:b63b3fcf72d1 29 if(!pir && !pir2)
lwettel 1:b63b3fcf72d1 30 {
lwettel 1:b63b3fcf72d1 31 pc.printf("\r\nNothing Detected\r\n");
lwettel 1:b63b3fcf72d1 32 pc.printf("\r\nTurn off stove\r\n");
lwettel 1:b63b3fcf72d1 33 motor();
lwettel 1:b63b3fcf72d1 34 wait(1);
lwettel 1:b63b3fcf72d1 35 }
lwettel 1:b63b3fcf72d1 36 else if(pir && !pir2)
lwettel 1:b63b3fcf72d1 37 {
lwettel 1:b63b3fcf72d1 38
lwettel 1:b63b3fcf72d1 39 pc.printf("\r\nKids/Cat Detected\r\n");
lwettel 1:b63b3fcf72d1 40 pc.printf("\r\nTurn off stove\r\n");
lwettel 1:b63b3fcf72d1 41 motor();
lwettel 1:b63b3fcf72d1 42 wait(1);
lwettel 1:b63b3fcf72d1 43 }
lwettel 1:b63b3fcf72d1 44 else
lwettel 1:b63b3fcf72d1 45 {
lwettel 1:b63b3fcf72d1 46
lwettel 1:b63b3fcf72d1 47 pc.printf("\r\nAdult Detected\r\n");
Niranjan_ravi 0:c8b31227d874 48 wait(1);
Niranjan_ravi 0:c8b31227d874 49 }
Niranjan_ravi 0:c8b31227d874 50 }
lwettel 1:b63b3fcf72d1 51 else
lwettel 1:b63b3fcf72d1 52 {
lwettel 1:b63b3fcf72d1 53 pc.printf("\r\nStove not turned on\r\n");
lwettel 1:b63b3fcf72d1 54 }
lwettel 1:b63b3fcf72d1 55 }
lwettel 1:b63b3fcf72d1 56 }
lwettel 1:b63b3fcf72d1 57
lwettel 1:b63b3fcf72d1 58 void motor(){
lwettel 1:b63b3fcf72d1 59 PwmOut PWM1(A5);
lwettel 1:b63b3fcf72d1 60
lwettel 1:b63b3fcf72d1 61 //int main()
lwettel 1:b63b3fcf72d1 62 //{
lwettel 1:b63b3fcf72d1 63 PWM1.period_ms(100);
lwettel 1:b63b3fcf72d1 64 int x;
lwettel 1:b63b3fcf72d1 65 x=20;
lwettel 1:b63b3fcf72d1 66 while(1)
lwettel 1:b63b3fcf72d1 67 {
lwettel 1:b63b3fcf72d1 68 PWM1.pulsewidth_ms(x);
lwettel 1:b63b3fcf72d1 69 //x=x+1;
lwettel 1:b63b3fcf72d1 70
lwettel 1:b63b3fcf72d1 71 wait(0.1);
lwettel 1:b63b3fcf72d1 72 //if(x==10)
lwettel 1:b63b3fcf72d1 73
lwettel 1:b63b3fcf72d1 74 x=0;
lwettel 1:b63b3fcf72d1 75
lwettel 1:b63b3fcf72d1 76 }
lwettel 1:b63b3fcf72d1 77 }
lwettel 1:b63b3fcf72d1 78
lwettel 1:b63b3fcf72d1 79
lwettel 1:b63b3fcf72d1 80
lwettel 1:b63b3fcf72d1 81