Back to Parent

// Identify the Servo
Servo david;

// Identify the led
int led = D1;

// Initial position for the servo
int pos = 0;

// Photo Resistor
int photoCellPin = A0;

// Store the sensor reading
int photoCellReading = 0;

// threshold for being covered
int threshold = 2300;

void setup()
{
  // connect the photo cell reading to the cloud
  Particle.variable( "light", &photoCellReading, INT );

  pinMode(led, OUTPUT);

  david.attach(D0);

  Serial.begin( 9600 );
}

void loop()
{
  photoCellReading = analogRead( photoCellPin );

  // see if the room is dark
  if( photoCellReading < threshold )
  {
    david.write(90);
    digitalWrite(led, HIGH);
  }
  else
  {
    david.write(5);
    digitalWrite(led, LOW);
  }

delay(5000);

}
Click to Expand

Content Rating

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

0