Auto Shut-off safety system for stove
Dependencies: mbed Motordriver DHT
main.cpp
- Committer:
- lwettel
- Date:
- 2019-03-08
- Revision:
- 1:b63b3fcf72d1
- Parent:
- 0:c8b31227d874
- Child:
- 2:29fb4e252925
File content as of revision 1:b63b3fcf72d1:
#include "mbed.h" #include "DHT.h" void motor(); DHT sensor(D4, DHT11); Serial pc(USBTX, USBRX); // tx, rx DigitalIn pir(D4); DigitalIn pir2(D2); //Connect it to Timer timer; 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); } } 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; } }