Back to Parent

// variables
int button = D0;
int red = D5;
int photo = A1;
int door = A0;
int green = D7;

int buttonState=0;
int doorState=0;
int photoState=0;
int flag=0; //0 is day, 1 is night
//int photoCellPinState=0;

// setup
void setup()
{
  pinMode(button,INPUT);
  pinMode(red,OUTPUT);
  pinMode(photo,INPUT);
  pinMode(door,INPUT);
  pinMode(green,OUTPUT);
  Spark.variable("doorState", &doorState, INT);
  Spark.variable("buttonState", &buttonState,INT);
  //Spark.variable("", &stateOfDay,INT);
  Spark.variable("photoState", &photoState,INT);
}
//main loop
void loop()
{
  buttonState=digitalRead(button);
  doorState=analogRead(door);
  photoState=analogRead(photo);

  //photo=analogRead(photoCellPin);
  //when bell is rang and door is closed
  if((buttonState==0||flag==1)&&doorState<700)
  //light blinks after doorbell is rung
  {  digitalWrite(red,HIGH);
     delay(2000);
     digitalWrite(red,LOW);
     delay(1000);
     flag=1;
     //At night outside light switches on
  if(photoState<900)
  {
    digitalWrite(green,HIGH);
  }
}
// Door is opened both lights stop blinking
  if(doorState>900)
  {
    digitalWrite(red,LOW);
    digitalWrite(green,LOW);
    flag=0;
  }
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0