//Define the pin for photo cell and resistor is added
int phoCellPin = A0;
//Variable to store data of light
int phoCellReading = 0;
//Define the pot pin
int potPin = A5;
//Variable for pot reading
int potReading = 0;
//Define LED pin
int ledPin = D2;
//Variable to stor data of LED
int ledBrightness = 0;
void setup() {
//Led outpou setup
pinMode(ledPin, OUTPUT);
//Cloud variable mapped to phoCellReading
Particle.variable("LightData", &phoCellReading, INT);
//Cloud variable mapped to potReading
Particle.variable("PotData", potReading);
}
void loop() {
//Read photo cell reading data
phoCellReading = analogRead(phoCellPin);
//Read pot reading data
potReading = analogRead(potPin);
//Turn light on when interior light is insufficient
//Light intensity adjustable through potentiometer
if(phoCellReading > 500) {
digitalWrite(ledPin, LOW);
} else {
digitalWrite(ledPin, HIGH);
ledBrightness = map(potReading, 0, 4095, 0, 255);
analogWrite(ledPin, ledBrightness);
}
//Wait time between each loop
delay(300);
}
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. .