Back to Parent

// Define a pin that we'll place the photo cell on
// Remember to add a 10K Ohm pull-down resistor too.
int photoCellPin = A0;

// Create a variable to hold the light reading
int photoCellReading = 0;

// Define a pin we'll place an LED on
int ledPin = D2;

// Create a variable to store the LED brightness.
int ledBrightness = 0;

void setup()
{
  // Set up the LED for output
  pinMode(ledPin, OUTPUT);

  // Create a cloud variable of type integer
  // called 'light' mapped to photoCellReading
  Particle.variable("light", &photoCellReading, INT);

}

void loop() {
  photoCellReading = analogRead(photoCellPin);
  Serial.println("Photo Cell Reading: " + String(photoCellReading));

  ledBrightness = map(photoCellReading, 0, 4095, 0, 255);
  Serial.println("LED Brightness: " + String(ledBrightness));

  analogWrite(ledPin, ledBrightness);
  delay(100);
}
Click to Expand

Content Rating

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

0