Back to Parent

//Instead of fading your light, why not turn it on or off when the light reaches certain levels.

//For example, if the light levels are below 2000 turn the light on (and bright), otherwise turn it off.


int photoCellPin = A3;
int photoCellReading = 0;
int ledPin = D3;
int ledBrightness = 0;


void setup() {
    pinMode(ledPin, OUTPUT);

}

void loop() {
    
    photoCellReading = analogRead(photoCellPin);
    
    if (photoCellReading <= 2000) {
        digitalWrite( ledPin, HIGH);
    }else{
        digitalWrite( ledPin, LOW);
    }
    
    //ledBrightness = map(photoCellReading, 4095, 0, 0, 255);
    //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