int photoCellPin = A0;
// Variable to store the light reading from the sensor
int photoCellReading = 0;
// Pin where the LED is connected
int ledPin = D10;
void setup()
{
// Set up the LED pin as an output
pinMode(ledPin, OUTPUT);
// Create a cloud variable to track the light sensor reading remotely
Particle.variable("light", photoCellReading);
}
void loop()
{
// Get the light reading from the sensor, range from 0 to 4095
photoCellReading = analogRead(photoCellPin);
// Print the reading to the Serial Monitor to keep track of it
Serial.println(photoCellReading);
// If the reading is more than 500, I want the LED to turn on
if (photoCellReading > 500) {
digitalWrite(ledPin, HIGH); // LED on
} else {
digitalWrite(ledPin, LOW); // LED off
}
// Wait 100ms before reading again, helps avoid unnecessary flicker
delay(100);
}
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. .