CONTROL LED BRIGHTNESS BY LDR

LED brigness LDR

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/Controlling%20Brigtness%20by%20LDR.zip

int level = 0;
int encoder_pin = 5;//use PWM pin
void setup()
{
Serial.begin(9600);
pinMode(encoder_pin, OUTPUT);

}
void loop() {
int sensorValue = analogRead(A0);
level = map(sensorValue, 0, 1023, 255, 0);
analogWrite(encoder_pin, level);
Serial.print(sensorValue);
Serial.print(” “);
Serial.println(level);
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s