Problem with working of fan when door sensor is closed
hi,
working on project in fan must turn on when door sensor closed first time , fan should off when door sensor opened.when door sensor closed second time,bulb must on , when door opened again bulb must off.initially door should open.
here code have written.
i have used state change detection concept.but not seem work.the fan turns on 2 or 3 seconds , automatically turns off without changing door state.
i new arduino , i've tried few things i'm still stuck.
any appreciated,
thanks.
working on project in fan must turn on when door sensor closed first time , fan should off when door sensor opened.when door sensor closed second time,bulb must on , when door opened again bulb must off.initially door should open.
here code have written.
code: [select]
int bulb=9;
int fan=5;
int door=12;
int state;
int dstate; //store state of door
int count = 0; //counter number of times door sensor opened or closed
int previous = 1;
void setup() {
pinmode(bulb,output);
pinmode(door,input);
pinmode(fan,output);
serial.begin(9600);
}
void loop()
{
dstate=digitalread(door);
if(dstate!=previous)
{
count++;
serial.println("count=");
serial.println(count);
if(dstate==low)
{
if(count==3)
{
digitalwrite(fan,low);
}
if(count==5)
{
digitalwrite(bulb,low);
}
}
if(dstate==high)
{
if(count==2)
{
digitalwrite(fan,high);
}
if(count==4)
{
digitalwrite(bulb,high);
}
}
previous=dstate;
}
}
i have used state change detection concept.but not seem work.the fan turns on 2 or 3 seconds , automatically turns off without changing door state.
i new arduino , i've tried few things i'm still stuck.
any appreciated,
thanks.
what debug prints tell you?
Arduino Forum > Using Arduino > Programming Questions > Problem with working of fan when door sensor is closed
arduino
Comments
Post a Comment