LED BRIGHTNESS CONTROL

MATERIALS
  • ArduinoUNO
  • Breadboard
  • Jumperwires
  • Arduino USB cable
  • 1 LED
  • 1 Resistor (220 Ohms)
  • 1 Variable resistor (10 K)
  • A computer with Arduino IDE
BREADBOARD ASSEMBLY



SCHEME



CODE


/* Control LED brightness*/

int ledPin = 11; // analogical OUTPUT PWM (LED conected to PIN 11)
int potPin = 0; // entrada analógica (POT conected to A0)

void setup()
{
pinMode(ledPin, OUTPUT); //declare PIN 11 as a OUTPUT
}

void loop()
{
analogWrite(ledPin,analogRead(potPin)/4); 
//write in the LED pin
//with the value from the variable resistor
//Important: is divided by 4 because the working range of
//analogRead() is from 0 to 1023, but the analogWrite() one is from
//0 to 255.
delay(100);
}

Comments

Popular Posts