int L1 = A0; // brighter light in the room
int P = A1; //force sensor detects whether person on bed or not
int R = A2; // detects light near window
int L2 = A4; // dim light or night light
int brightness=0;
void setup() {
// the Spark cloud as 'brightness'
Spark.variable("brightness", &brightness, INT);
// Set up pin for output
//declaring types of pins
pinMode (L1, OUTPUT);
pinMode (P, INPUT);
pinMode (R, INPUT);
pinMode (L2, OUTPUT);
}
void loop()
{
//declaring integer values for readings from force sensor as well as photoresistor
int vp= analogRead(P);
brightness=analogRead(R);
//logic for circuit
if (vp<1000 && brightness<100)
// if ambient light is low and no person in the bed switch on bright/main light
{ digitalWrite (L1,HIGH);
}
else if (vp>1000 && brightness<100)
//if ambient light is low and person present in the bed switch on dim/night light and switch off bright light
{ digitalWrite (L1,LOW);
digitalWrite (L2, HIGH);
}
else
//all other conditions both lights are off
{
digitalWrite (L1,LOW);
digitalWrite (L2, LOW);
}
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .